]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Fixes for '#' tokens
authorDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 01:32:24 +0000 (21:32 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 01:32:24 +0000 (21:32 -0400)
Makefile
main.c
parse.c

index 500245268f5133760fa04355c258ab4a089c68cf..7a016b322b9ecaa2dabb9b43da7fdb009d9f1e32 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,13 @@
 CC     = gcc
 CFLAGS = -O3 -Wall
-OBJ    = main.o lex.o error.o parse.o typedef.o
+OBJ    = main.o    \
+         lex.o     \
+         error.o   \
+         parse.o   \
+         typedef.o
 
 %.o: %.c
-       $(CC) -c -o $@ $< $(CFLAGS)
+       $(CC) -c $< -o $@ $(CFLAGS)
 
 gmqcc: $(OBJ)
        $(CC) -o $@ $^ $(CFLAGS)
diff --git a/main.c b/main.c
index 0699c1897b96cd6cf0849dd1a7865d0b36f9bcdd..3e8b8b6b45c73c51f9aaf3c64d9c53b49c37bd1a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -62,6 +62,8 @@ int main(int argc, char **argv) {
        
        /* 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 9c38111a53467d4b995ce2ebda38d7c462b356d7..68aa2c9ba18be74c6ec1c418add89fa3f5124987 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -38,7 +38,7 @@
 #define PARSE_TYPE_CONTINUE 5
 #define PARSE_TYPE_RETURN   6
 #define PARSE_TYPE_GOTO     7
-#define PARSE_TYPE_FOR      8   // extension
+#define PARSE_TYPE_FOR      8
 #define PARSE_TYPE_VOID     9
 #define PARSE_TYPE_STRING   10
 #define PARSE_TYPE_FLOAT    11
 #define PARSE_TYPE_MINUS    26
 #define PARSE_TYPE_ADD      27
 #define PARSE_TYPE_EQUAL    28
-#define PARSE_TYPE_LBS      29 // left  bracket scope
-#define PARSE_TYPE_RBS      30 // right bracket scope
-#define PARSE_TYPE_ELIP     31 // ...
+#define PARSE_TYPE_LBS      29
+#define PARSE_TYPE_RBS      30
+#define PARSE_TYPE_ELIP     31
 #define PARSE_TYPE_DOT      32
 #define PARSE_TYPE_LT       33
 #define PARSE_TYPE_GT       34
 #define PARSE_TYPE_BAND     35
 #define PARSE_TYPE_BOR      36
-#define PARSE_TYPE_DONE     37 // finished statement
+#define PARSE_TYPE_DONE     37
 
 /*
  * Adds a parse type to the parse tree, this is where all the hard
                parsetree             = parsetree->next;                 \
        } while (0)
 
-static const char *const parse_punct[] = {
+/*
+ * These are all the punctuation handled in the parser, these don't
+ * need tokens, they're already tokens.
+ */
+#if 0
        "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
        "/" , "(" , ")" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
-       "." , "<" , ">" , "&" , "|" , NULL
-};
+       "." , "<" , ">" , "&" , "|" , 
+#endif
 
 #define STORE(X) {     \
        printf(X);         \
@@ -175,7 +179,6 @@ int parse(struct lex_file *file) {
                if (!parseroot)
                        return error(ERROR_INTERNAL, "Ran out of memory", " ");
                parsetree = parseroot;
-               parsetree = parseroot;
        }
        
        int     token = 0;
@@ -255,6 +258,20 @@ int parse(struct lex_file *file) {
                         * of the ascii table which doesn't conflict with our other tokens
                         * which are higer than the ascii table.)
                         */
+                       case '#':
+                               /*
+                                * Skip the preprocessor for now:  We'll implement our own
+                                * eventually.  For now we need to make sure directives are
+                                * not accidently tokenized.
+                                */
+                               token = lex_token(file);
+                               token = lex_token(file);
+                               
+                               /* skip all tokens to end of directive */
+                               while (token != '\n')
+                                       token = lex_token(file);
+                               break;
+                               
                        case '&':               /* &  */
                                token = lex_token(file);
                                if (token == '&') { /* && */