Parsing fixes

This commit is contained in:
Dale Weiler 2012-04-11 22:13:34 -04:00
parent e4bc0a2d6a
commit 32d7728b2f
3 changed files with 18 additions and 15 deletions

2
lex.c
View file

@ -277,7 +277,7 @@ int lex_token(struct lex_file *file) {
/* valid identifier */ /* valid identifier */
if (ch > 0 && (ch == '_' || isalpha(ch))) { if (ch > 0 && (ch == '_' || isalpha(ch))) {
lex_clear(file); lex_clear(file);
while (ch > 0 && ch != ' ' && ch != '(' && ch != '\n') { while (ch > 0 && ch != ' ' && ch != '(' && ch != '\n' && ch != ';') {
lex_addch(ch, file); lex_addch(ch, file);
ch = lex_getsource(file); ch = lex_getsource(file);
} }

29
parse.c
View file

@ -262,11 +262,18 @@ int parse_tree(struct lex_file *file) {
typedef_add(f, t); typedef_add(f, t);
printf("TYPEDEF %s as %s\n", f, t);
mem_d(f); mem_d(f);
mem_d(t); mem_d(t);
while (token != '\n') //while (token != '\n')
token = lex_token(file); 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; break;
} }
@ -288,16 +295,17 @@ int parse_tree(struct lex_file *file) {
case TOKEN_GOTO: PARSE_PERFORM(PARSE_TYPE_GOTO, {}); case TOKEN_GOTO: PARSE_PERFORM(PARSE_TYPE_GOTO, {});
case TOKEN_VOID: PARSE_PERFORM(PARSE_TYPE_VOID, {}); case TOKEN_VOID: PARSE_PERFORM(PARSE_TYPE_VOID, {});
case TOKEN_STRING: PARSE_TREE_ADD(PARSE_TYPE_STRING); case TOKEN_STRING: PARSE_TREE_ADD(PARSE_TYPE_STRING); goto fall;
case TOKEN_VECTOR: PARSE_TREE_ADD(PARSE_TYPE_VECTOR); case TOKEN_VECTOR: PARSE_TREE_ADD(PARSE_TYPE_VECTOR); goto fall;
case TOKEN_ENTITY: PARSE_TREE_ADD(PARSE_TYPE_ENTITY); case TOKEN_ENTITY: PARSE_TREE_ADD(PARSE_TYPE_ENTITY); goto fall;
case TOKEN_FLOAT: PARSE_TREE_ADD(PARSE_TYPE_FLOAT); case TOKEN_FLOAT: PARSE_TREE_ADD(PARSE_TYPE_FLOAT); goto fall;
/* fall into this for all types */ /* fall into this for all types */
{ {
fall:;
char *name = NULL; char *name = NULL;
TOKEN_SKIPWHITE(); TOKEN_SKIPWHITE();
name = util_strdup(file->lastok); name = util_strdup(file->lastok);
//token = lex_token (file); token = lex_token (file);
/* is it NOT a definition? */ /* is it NOT a definition? */
if (token != ';') { if (token != ';') {
@ -343,7 +351,7 @@ int parse_tree(struct lex_file *file) {
} else if (token == '=') { } else if (token == '=') {
PARSE_TREE_ADD(PARSE_TYPE_EQUAL); PARSE_TREE_ADD(PARSE_TYPE_EQUAL);
} else { } 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 { } else {
/* definition */ /* definition */
@ -361,11 +369,6 @@ int parse_tree(struct lex_file *file) {
*/ */
case '#': case '#':
token = lex_token(file); /* skip '#' */ 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 * If we make it here we found a directive, the supported
* directives so far are #include. * directives so far are #include.

View file

@ -4,7 +4,7 @@ typedef string my_string;
typedef entity my_entity; typedef entity my_entity;
typedef void my_void; typedef void my_void;
my_float type_float; my_float type_float
my_vector type_vector; my_vector type_vector;
my_string type_string; my_string type_string;
my_entity type_entity; my_entity type_entity;