From 32d7728b2f9be72cfa364bb84ec7c570975af7ac Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Wed, 11 Apr 2012 22:13:34 -0400 Subject: [PATCH] Parsing fixes --- lex.c | 2 +- parse.c | 29 ++++++++++++++++------------- test/typedef.qc | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lex.c b/lex.c index 7c8044b..669d13d 100644 --- a/lex.c +++ b/lex.c @@ -277,7 +277,7 @@ int lex_token(struct lex_file *file) { /* valid identifier */ if (ch > 0 && (ch == '_' || isalpha(ch))) { lex_clear(file); - while (ch > 0 && ch != ' ' && ch != '(' && ch != '\n') { + while (ch > 0 && ch != ' ' && ch != '(' && ch != '\n' && ch != ';') { lex_addch(ch, file); ch = lex_getsource(file); } diff --git a/parse.c b/parse.c index 54dd2f0..f6de1c6 100644 --- a/parse.c +++ b/parse.c @@ -262,11 +262,18 @@ int parse_tree(struct lex_file *file) { typedef_add(f, t); + printf("TYPEDEF %s as %s\n", f, t); + mem_d(f); mem_d(t); - while (token != '\n') - token = lex_token(file); + //while (token != '\n') + token = lex_token(file); + if (token != ';') + error(ERROR_PARSE, "%s:%d Expected `;` on typedef\n", file->name, file->line); + + token = lex_token(file); + printf("TOK: %c\n", token); break; } @@ -288,16 +295,17 @@ int parse_tree(struct lex_file *file) { case TOKEN_GOTO: PARSE_PERFORM(PARSE_TYPE_GOTO, {}); case TOKEN_VOID: PARSE_PERFORM(PARSE_TYPE_VOID, {}); - case TOKEN_STRING: PARSE_TREE_ADD(PARSE_TYPE_STRING); - case TOKEN_VECTOR: PARSE_TREE_ADD(PARSE_TYPE_VECTOR); - case TOKEN_ENTITY: PARSE_TREE_ADD(PARSE_TYPE_ENTITY); - case TOKEN_FLOAT: PARSE_TREE_ADD(PARSE_TYPE_FLOAT); + case TOKEN_STRING: PARSE_TREE_ADD(PARSE_TYPE_STRING); goto fall; + case TOKEN_VECTOR: PARSE_TREE_ADD(PARSE_TYPE_VECTOR); goto fall; + case TOKEN_ENTITY: PARSE_TREE_ADD(PARSE_TYPE_ENTITY); goto fall; + case TOKEN_FLOAT: PARSE_TREE_ADD(PARSE_TYPE_FLOAT); goto fall; /* fall into this for all types */ { + fall:; char *name = NULL; TOKEN_SKIPWHITE(); name = util_strdup(file->lastok); - //token = lex_token (file); + token = lex_token (file); /* is it NOT a definition? */ if (token != ';') { @@ -343,7 +351,7 @@ int parse_tree(struct lex_file *file) { } else if (token == '=') { PARSE_TREE_ADD(PARSE_TYPE_EQUAL); } else { - error(ERROR_COMPILER, "%s:%d Invalid decltype: expected `(` [function], or `=` [constant] for %s\n", file->name, file->line, name); + error(ERROR_COMPILER, "%s:%d Invalid decltype: expected `(` [function], or `=` [constant], or `;` [definition] for %s\n", file->name, file->line, name); } } else { /* definition */ @@ -361,11 +369,6 @@ int parse_tree(struct lex_file *file) { */ case '#': token = lex_token(file); /* skip '#' */ - //while (isspace(token)) { - // if (token == '\n') - // return error(ERROR_PARSE, "Expected valid preprocessor directive after `#` %s\n"); - // token = lex_token(file); /* try again */ - //} /* * If we make it here we found a directive, the supported * directives so far are #include. diff --git a/test/typedef.qc b/test/typedef.qc index f60bf77..7971ba8 100644 --- a/test/typedef.qc +++ b/test/typedef.qc @@ -4,7 +4,7 @@ typedef string my_string; typedef entity my_entity; typedef void my_void; -my_float type_float; +my_float type_float my_vector type_vector; my_string type_string; my_entity type_entity; -- 2.39.2