]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Parsing fixes
authorDale Weiler <killfieldengine@gmail.com>
Thu, 12 Apr 2012 02:13:34 +0000 (22:13 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Thu, 12 Apr 2012 02:13:34 +0000 (22:13 -0400)
lex.c
parse.c
test/typedef.qc

diff --git a/lex.c b/lex.c
index 7c8044b8ecd8e8819dfda4c77960d6a2ba1f31d5..669d13d7afd89201c20d7dd47ae6e666d6d6a5cd 100644 (file)
--- 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 54dd2f0658180db8568b7717c3893c378c00cf88..f6de1c6ab1ed09e8aa8a7c812fc928341ea7ab86 100644 (file)
--- 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.
index f60bf7785f43c94dc01d21bacccd20481f856b50..7971ba8e52fe6a4c1b8f158e3741fe591579d041 100644 (file)
@@ -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;