]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
More parse tree stuff
authorDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 02:44:06 +0000 (22:44 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 02:44:06 +0000 (22:44 -0400)
lex.c
main.c
parse.c

diff --git a/lex.c b/lex.c
index 6c381c9f3cfef5aa27a7829b31f6a0ab8078a74f..01b2ec73b0369398bf4fb625bbba16fdf89df5a1 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -295,7 +295,8 @@ int lex_token(struct lex_file *file) {
                        for (it = 0; it < sizeof(lex_keywords)/sizeof(*lex_keywords); it++)
                                if (!strncmp(typedef_find(file->lastok)->name, lex_keywords[it], sizeof(lex_keywords[it])))
                                        return it;
-                               
+               
+                       
                return LEX_IDENT;
        }
        return ch;
diff --git a/main.c b/main.c
index 3e8b8b6b45c73c51f9aaf3c64d9c53b49c37bd1a..c796d7c6525898885dba1e340d105eb10fce2b1e 100644 (file)
--- a/main.c
+++ b/main.c
 #include <limits.h>
 #include "gmqcc.h"
 
-//typedef int foo;
-
 int usage(const char *name) {
        printf("Usage: %s -f infile -o outfile\n", name);
        return 0;
 }
-
 int main(int argc, char **argv) {
        const char *ofile = NULL;
        const char *ifile = NULL;
@@ -60,10 +57,9 @@ int main(int argc, char **argv) {
        printf("ifile: %s\n", ifile);
        printf("ofile: %s\n", ofile);
        
+       
        /* Open file */
        FILE *fp = fopen(ifile, "r");
-       
-       /* run the preprocessor */
        if  (!fp) {
                fclose(fp);
                return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
diff --git a/parse.c b/parse.c
index 68aa2c9ba18be74c6ec1c418add89fa3f5124987..b46df134b044004114d91d66deaf92cf85ab4d16 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -68,6 +68,7 @@
 #define PARSE_TYPE_BAND     35
 #define PARSE_TYPE_BOR      36
 #define PARSE_TYPE_DONE     37
+#define PARSE_TYPE_IDENT    38
 
 /*
  * Adds a parse type to the parse tree, this is where all the hard
@@ -119,10 +120,12 @@ void parse_debug(struct parsenode *tree) {
                        case PARSE_TYPE_RETURN:    STORE("STATEMENT: RETURN\n");
                        case PARSE_TYPE_DONE:      STORE("STATEMENT: DONE\n");
 
-
+                       case PARSE_TYPE_VOID:      STORE("DECLTYPE:  VOID\n");
+                       case PARSE_TYPE_STRING:    STORE("DECLTYPE:  STRING\n");
                        case PARSE_TYPE_ELIP:      STORE("DECLTYPE:  VALIST\n");
                        case PARSE_TYPE_ENTITY:    STORE("DECLTYPE:  ENTITY\n");
                        case PARSE_TYPE_FLOAT:     STORE("DECLTYPE:  FLOAT\n");
+                       case PARSE_TYPE_VECTOR:    STORE("DECLTYPE:  VECTOR\n");
                        
                        case PARSE_TYPE_GT:        STORE("TEST:      GREATER THAN\n");
                        case PARSE_TYPE_LT:        STORE("TEST:      LESS THAN\n");
@@ -147,7 +150,7 @@ void parse_debug(struct parsenode *tree) {
                        case PARSE_TYPE_FOR:       STORE("LOOP:      FOR\n");
                        case PARSE_TYPE_DO:        STORE("LOOP:      DO\n");
                        
-
+                       case PARSE_TYPE_IDENT:     STORE("IDENT:     ???\n");
                }
                tree = tree->next;
        }
@@ -190,32 +193,28 @@ 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", "");
+                               //if (token != '(')
+                               //      error(ERROR_PARSE, "Expected `(` after if\n", "");
                                        
                                PARSE_TREE_ADD(PARSE_TYPE_IF);
                                break;
                        case TOKEN_ELSE:
                                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);
                                        
                                PARSE_TREE_ADD(PARSE_TYPE_ELSE);
                                break;
                        case TOKEN_FOR:
                                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);
                                        
                                PARSE_TREE_ADD(PARSE_TYPE_FOR);
                                break;
-                               
-                       case LEX_IDENT:
-                               token = lex_token(file);
-                               break;
                        
                        /*
                         * This is a quick and easy way to do typedefs at parse time
@@ -272,6 +271,15 @@ int parse(struct lex_file *file) {
                                        token = lex_token(file);
                                break;
                                
+                       case '(':
+                               token = lex_token(file);
+                               PARSE_TREE_ADD(PARSE_TYPE_LPARTH);
+                               break;
+                       case ')':
+                               token = lex_token(file);
+                               PARSE_TREE_ADD(PARSE_TYPE_RPARTH);
+                               break;
+                               
                        case '&':               /* &  */
                                token = lex_token(file);
                                if (token == '&') { /* && */
@@ -338,14 +346,6 @@ int parse(struct lex_file *file) {
                                token = lex_token(file);
                                PARSE_TREE_ADD(PARSE_TYPE_ADD);
                                break;
-                       case '(':
-                               token = lex_token(file);
-                               PARSE_TREE_ADD(PARSE_TYPE_LPARTH);
-                               break;
-                       case ')':
-                               token = lex_token(file);
-                               PARSE_TREE_ADD(PARSE_TYPE_RPARTH);
-                               break;
                        case '{':
                                token = lex_token(file);
                                PARSE_TREE_ADD(PARSE_TYPE_LBS);
@@ -354,6 +354,17 @@ int parse(struct lex_file *file) {
                                token = lex_token(file);
                                PARSE_TREE_ADD(PARSE_TYPE_RBS);
                                break;
+                               
+                       /*
+                        * TODO: Fix lexer to spit out ( ) as tokens, it seems the
+                        * using '(' or ')' in parser doesn't work properly unless
+                        * there are spaces before them to allow the lexer to properly
+                        * seperate identifiers. -- otherwise it eats all of it.
+                        */
+                       case LEX_IDENT:
+                               token = lex_token(file);
+                               PARSE_TREE_ADD(PARSE_TYPE_IDENT);
+                               break;
                }
        }
        parse_debug(parseroot);