forked from NeoFlock/noom
i don't remember what i changed
This commit is contained in:
13
src/lexer.c
13
src/lexer.c
@@ -15,7 +15,7 @@ int noomL_isalphanum(char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int noomL_iswhitespace(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
|
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 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;
|
||||||
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;
|
||||||
|
if (noom_startswith(s, "~")) return 1;
|
||||||
|
|
||||||
return 0; // no symbol
|
return 0; // no symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void print_node(noomP_Node* node, noom_uint_t depth) {
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
// uhh uhhh uhhhhh
|
// 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;
|
noom_uint_t pos = 0;
|
||||||
|
|
||||||
printf("LEX OUTPUT:\n");
|
printf("LEX OUTPUT:\n");
|
||||||
|
|||||||
32
src/parser.c
32
src/parser.c
@@ -79,6 +79,38 @@ noomP_Node* noomP_parseRawExpression(noomP_Parser* parser) {
|
|||||||
varNode->source_offset = token.offset;
|
varNode->source_offset = token.offset;
|
||||||
|
|
||||||
return varNode;
|
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;
|
return 0;
|
||||||
|
|||||||
@@ -3,12 +3,17 @@
|
|||||||
|
|
||||||
typedef enum noomP_NodeType {
|
typedef enum noomP_NodeType {
|
||||||
NOOMP_NODE_PROGRAM,
|
NOOMP_NODE_PROGRAM,
|
||||||
|
|
||||||
NOOMP_NODE_VARNAME,
|
NOOMP_NODE_VARNAME,
|
||||||
NOOMP_NODE_VARIABLE,
|
|
||||||
NOOMP_NODE_NUMBERLITERAL,
|
|
||||||
NOOMP_NODE_LOCALDECLARATION,
|
NOOMP_NODE_LOCALDECLARATION,
|
||||||
NOOMP_NODE_IFSTATEMENT,
|
NOOMP_NODE_IFSTATEMENT,
|
||||||
NOOMP_NODE_BLOCK,
|
NOOMP_NODE_BLOCK,
|
||||||
|
|
||||||
|
NOOMP_NODE_VARIABLE,
|
||||||
|
NOOMP_NODE_NUMBERLITERAL,
|
||||||
|
NOOMP_NODE_BOOLEANLITERAL,
|
||||||
|
NOOMP_NODE_NILLITERAL,
|
||||||
|
|
||||||
NOOMP_NODE_UNARYOPERATOR,
|
NOOMP_NODE_UNARYOPERATOR,
|
||||||
NOOMP_NODE_BINARYOPERATOR
|
NOOMP_NODE_BINARYOPERATOR
|
||||||
|
|||||||
Reference in New Issue
Block a user