Commit Graph

21 Commits

Author SHA1 Message Date
Aryadev Chavali
05136fdd25 Fixed examples for changes in lexer
Name assigned to %CONST is the next symbol in stream, not the symbol
attached to it.
2024-04-16 15:38:24 +06:30
Aryadev Chavali
1e7f1bdee9 Changed %const format in preprocesser now
Instead of %const(<name>) ... %end it will now be %const <name>
... %end i.e. the first symbol after %const will be considered the
name of the constant similar to %use.
2024-04-15 18:39:37 +06:30
Aryadev Chavali
c748ed8386 Changed output schema for printing tokens 2024-04-15 16:31:07 +06:30
Aryadev Chavali
83faf86312 Fix error where lexer would loop infinitely if unknown character found 2024-04-15 16:30:44 +06:30
Aryadev Chavali
0f430e399c Changed hex format from x<digits> -> 0x<digits> 2024-04-15 16:30:30 +06:30
Aryadev Chavali
175138f570 Lexical error on char literal being too big or too small
This is actually an improvement on the older lexer.
2024-04-15 16:29:42 +06:30
Aryadev Chavali
a2d98142d5 lerr_t is now a struct with constructors
Similar principle to pp_err_t in that a structure provides the
opportunity for more information about the error such as location.
2024-04-15 16:29:37 +06:30
Aryadev Chavali
ae3794c33e constexpr -> const in lexer.cpp
Not much of an actual performance change, more semantic meaning for me.
2024-04-15 16:27:05 +06:30
Aryadev Chavali
a70dcf2e3f ~extern "C"~ when including lib/inst.h 2024-04-15 16:26:44 +06:30
Aryadev Chavali
0385d4bb8d Fix some off by one errors in lexer 2024-04-15 04:43:58 +06:30
Aryadev Chavali
f01d64b5f4 lexer now produces a vector of heap allocated tokens
This removes the problem of possibly expensive copies occurring due to
working with tokens produced from the lexer (that C++ just... does):
now we hold pointers where the copy operator is a lot easier to use.

I want expensive stuff to be done by me and for a reason: I want to
be holding the shotgun.
2024-04-15 04:42:24 +06:30
Aryadev Chavali
86e9d51ab0 enum -> enum class in lexer
This makes enum elements scoped which is actually quite useful as I
prefer the namespacing that enum's give in C++.
2024-04-14 17:17:51 +06:30
Aryadev Chavali
86aca9a596 Added static assert to lexer in case of opcode changes 2024-04-14 17:12:24 +06:30
Aryadev Chavali
44305138b0 Implemented cstr functions. 2024-04-14 17:05:56 +06:30
Aryadev Chavali
e55871195a Implemented overload for ostream and token as well as constructors for token 2024-04-14 17:05:52 +06:30
Aryadev Chavali
a8f605c89b Implemented tokenise_buffer
Note that this is basically the same as the previous version,
excluding the fact that it uses C++ idioms more and does a bit better
in error checking.
2024-04-14 17:04:15 +06:30
Aryadev Chavali
7a9e646d39 Implemented tokenise_literal_string
One thing I've realised is that even methods such as this require
error tracking.  I won't implement it in the tokenise method as it's
not related to consuming the string per se but instead in the main method.
2024-04-14 17:02:45 +06:30
Aryadev Chavali
50e9a4eef5 Implemented tokenise_literal_char (tokenise_char_literal)
I made the escape sequence parsing occur here instead of leaving it to
the main tokenise_buffer function as I think it's better suited here.
2024-04-14 17:01:35 +06:30
Aryadev Chavali
3c46fde66a Implemented tokenise_literal_hex
Note the overall size of this function in comparison to the C version,
as well as its clarity.

Of course, it is doing allocations in the background through
std::string which requires more profiling if I want to make this super
efficient™ but honestly the assembler just needs to work, whereas the
runtime needs to be fast.
2024-04-14 16:57:46 +06:30
Aryadev Chavali
4f8f511168 Implemented tokenise_literal_number (tokenise_number) 2024-04-14 16:56:58 +06:30
Aryadev Chavali
585aff1cbb Started implementing lexer in lexer.cpp
The implementation for tokenise_symbol is already a lot nicer to look
at and add to due to string/string_view operator overloading of ==.
Furthermore, error handling through pair<> instead of making some
custom structure which essentially does the same thing is already
making me happy for this rewrite.
2024-04-14 16:56:43 +06:30