diff --git a/src/lexer.c b/src/lexer.c index ecda06a..979e70f 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -15,7 +15,7 @@ int noomL_isalphanum(char c) { } int noomL_iswhitespace(char c) { - return c == ' ' || c == '\r' || c == '\n' || c == '\t'; + return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == '\v' || c == '\f'; } noom_uint_t noomL_getsymbol(const char* s) { // TODO: maybe find some less shit crap holy crap @@ -26,6 +26,13 @@ noom_uint_t noomL_getsymbol(const char* s) { // TODO: maybe find some less shit if (noom_startswith(s, "<=")) return 2; if (noom_startswith(s, ">=")) return 2; if (noom_startswith(s, "..")) return 2; + + if (noom_startswith(s, "::")) return 2; + + if (noom_startswith(s, "//")) return 2; + + if (noom_startswith(s, ">>")) return 2; + if (noom_startswith(s, "<<")) return 2; if (noom_startswith(s, "+")) return 1; if (noom_startswith(s, "-")) return 1; @@ -52,6 +59,10 @@ noom_uint_t noomL_getsymbol(const char* s) { // TODO: maybe find some less shit if (noom_startswith(s, ";")) return 1; + if (noom_startswith(s, "&")) return 1; + if (noom_startswith(s, "|")) return 1; + if (noom_startswith(s, "~")) return 1; + return 0; // no symbol } diff --git a/src/main.c b/src/main.c index ae0c3f1..a3e2126 100644 --- a/src/main.c +++ b/src/main.c @@ -33,7 +33,7 @@ void print_node(noomP_Node* node, noom_uint_t depth) { int main(int argc, char** argv) { // uhh uhhh uhhhhh - const char* code = "if 6 then local a = 2 + 2; end"; + const char* code = "if false or true then local a = 5 end"; noom_uint_t pos = 0; printf("LEX OUTPUT:\n"); diff --git a/src/parser.c b/src/parser.c index cc256bd..d8a8cc8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -79,6 +79,38 @@ noomP_Node* noomP_parseRawExpression(noomP_Parser* parser) { varNode->source_offset = token.offset; return varNode; + } else if (token.type == NOOML_TOKEN_KEYWORD) { + if (noom_streql(parser->code + token.offset, token.length, "true", 4)) { + noomP_skip(parser, &token); + + noomP_Node* litNode = noomP_allocNode(parser); + if (litNode == 0) return 0; + + litNode->type = NOOMP_NODE_BOOLEANLITERAL; + litNode->source_offset = token.offset; + + return litNode; + } else if (noom_streql(parser->code + token.offset, token.length, "false", 5)) { + noomP_skip(parser, &token); + + noomP_Node* litNode = noomP_allocNode(parser); + if (litNode == 0) return 0; + + litNode->type = NOOMP_NODE_BOOLEANLITERAL; + litNode->source_offset = token.offset; + + return litNode; + } else if (noom_streql(parser->code + token.offset, token.length, "nil", 3)) { + noomP_skip(parser, &token); + + noomP_Node* litNode = noomP_allocNode(parser); + if (litNode == 0) return 0; + + litNode->type = NOOMP_NODE_NILLITERAL; + litNode->source_offset = token.offset; + + return litNode; + } } return 0; diff --git a/src/parser.h b/src/parser.h index 79adb1e..16cb4eb 100644 --- a/src/parser.h +++ b/src/parser.h @@ -3,12 +3,17 @@ typedef enum noomP_NodeType { NOOMP_NODE_PROGRAM, + NOOMP_NODE_VARNAME, - NOOMP_NODE_VARIABLE, - NOOMP_NODE_NUMBERLITERAL, + NOOMP_NODE_LOCALDECLARATION, NOOMP_NODE_IFSTATEMENT, NOOMP_NODE_BLOCK, + + NOOMP_NODE_VARIABLE, + NOOMP_NODE_NUMBERLITERAL, + NOOMP_NODE_BOOLEANLITERAL, + NOOMP_NODE_NILLITERAL, NOOMP_NODE_UNARYOPERATOR, NOOMP_NODE_BINARYOPERATOR