From 248cd7af945adc9c5de019ec74c866626cd560ab Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Mon, 9 Apr 2012 23:46:59 -0400 Subject: [PATCH] Fix parser bug --- README | 4 ++++ gmqcc.h | 11 +++++------ lex.c | 1 - parse.c | 38 +++++++++++++++++++++----------------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/README b/README index 4ecb4db..b072829 100644 --- a/README +++ b/README @@ -30,6 +30,10 @@ typedef.c complicated than it sounds. This handles all typedefs, and even recrusive typedefs. +alloc.c + This is just an allocator for the compiler, it's used for debugging reasons + only. + README This is the file you're currently reading diff --git a/gmqcc.h b/gmqcc.h index 43d90df..681e539 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -155,12 +155,11 @@ struct lex_file { #define TOKEN_GOTO 7 #define TOKEN_FOR 8 // extension #define TOKEN_TYPEDEF 9 // extension -#define TOKEN_INT 10 // extension -#define TOKEN_VOID 11 -#define TOKEN_STRING 12 -#define TOKEN_FLOAT 13 -#define TOKEN_VECTOR 14 -#define TOKEN_ENTITY 15 +#define TOKEN_VOID 10 +#define TOKEN_STRING 11 +#define TOKEN_FLOAT 12 +#define TOKEN_VECTOR 13 +#define TOKEN_ENTITY 14 /* * Lexer state constants, these are numbers for where exactly in diff --git a/lex.c b/lex.c index 01b2ec7..76cfbf0 100644 --- a/lex.c +++ b/lex.c @@ -37,7 +37,6 @@ static const char *const lex_keywords[] = { "for", "typedef", /* types */ - "int", "void", "string", "float", diff --git a/parse.c b/parse.c index 4e820c7..a312dcc 100644 --- a/parse.c +++ b/parse.c @@ -98,13 +98,7 @@ } void parse_debug(struct parsenode *tree) { - while (tree && tree->next != NULL) { - /* skip blanks */ - if (tree->type == 0) { - tree = tree->next; - continue; - } - + while (tree) { switch (tree->type) { case PARSE_TYPE_ADD: STORE("OPERATOR: ADD \n"); case PARSE_TYPE_BAND: STORE("OPERATOR: BITAND \n"); @@ -162,10 +156,13 @@ void parse_debug(struct parsenode *tree) { * like syntax check for legal use -- like it should as it's a TODO item * which is not implemented */ -#define PARSE_TODO(X) { \ - token = lex_token(file); \ - PARSE_TREE_ADD(X); \ - break; \ +#define PARSE_TODO(X) { \ + token = lex_token(file); \ + while (token != '\n') { \ + token = lex_token(file); \ + } \ + PARSE_TREE_ADD(X); \ + break; \ } void parse_clear(struct parsenode *tree) { @@ -191,7 +188,8 @@ int parse(struct lex_file *file) { parseroot = mem_a(sizeof(struct parsenode)); if (!parseroot) return error(ERROR_INTERNAL, "Ran out of memory", " "); - parsetree = parseroot; + parsetree = parseroot; + parsetree->type = -1; /* not a valid type -- root element */ } int token = 0; @@ -203,8 +201,8 @@ int parse(struct lex_file *file) { switch (token) { case TOKEN_IF: token = lex_token(file); - //while ((token == ' ' || token == '\n') && file->length >= 0) - // token = lex_token(file); + while ((token == ' ' || token == '\n') && file->length >= 0) + token = lex_token(file); //if (token != '(') // error(ERROR_PARSE, "Expected `(` after if\n", ""); @@ -212,18 +210,19 @@ int parse(struct lex_file *file) { PARSE_TREE_ADD(PARSE_TYPE_IF); break; case TOKEN_ELSE: - token = lex_token(file); + //token = lex_token(file); //while ((token == ' ' || token == '\n') && file->length >= 0) // token = lex_token(file); PARSE_TREE_ADD(PARSE_TYPE_ELSE); break; case TOKEN_FOR: - token = lex_token(file); + //token = lex_token(file); //while ((token == ' ' || token == '\n') && file->length >= 0) // token = lex_token(file); - PARSE_TREE_ADD(PARSE_TYPE_FOR); + //PARSE_TREE_ADD(PARSE_TYPE_FOR); + PARSE_TODO(PARSE_TYPE_FOR); break; /* @@ -281,6 +280,11 @@ int parse(struct lex_file *file) { token = lex_token(file); break; + case '.': + token = lex_token(file); + PARSE_TREE_ADD(PARSE_TYPE_DOT); + break; + case '(': token = lex_token(file); PARSE_TREE_ADD(PARSE_TYPE_LPARTH); -- 2.39.2