]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Some parsing
authorDale Weiler <killfieldengine@gmail.com>
Mon, 9 Apr 2012 14:14:26 +0000 (10:14 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Mon, 9 Apr 2012 14:14:26 +0000 (10:14 -0400)
cpp.c
gmqcc
lex.c
main.c
parse.c

diff --git a/cpp.c b/cpp.c
index e2f8021a1c5699d2546e158b3cf40b2a65f0657f..62a9819920c6f41cf7e2f8073dc78ddf91044adb 100644 (file)
--- a/cpp.c
+++ b/cpp.c
@@ -6,5 +6,5 @@
  * which is what we parse for the preprocessor here.
  */
 int cpp(struct lex_file *file) {
-       /* TODO ... */
+       /* no return */
 }
diff --git a/gmqcc b/gmqcc
index 257c415afc2dd5fd5fef3f972261d33851f2d63c..9bc7f27d9ed45849c15d18a76d331f73c6eaa88e 100755 (executable)
Binary files a/gmqcc and b/gmqcc differ
diff --git a/lex.c b/lex.c
index 9d15301d8d0070da7aec062df4af6e2b5864f83b..5333171ef2e28a63d57cf6bc1ccdd8720bda1d9c 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -349,6 +349,7 @@ int lex_debug(struct lex_file *file) {
        while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0)
                if (token == LEX_IDENT)
                        printf("%s ", file->lastok);
+       fputc('\n', stdout);
        lex_reset(file);
        return 1;
 }
diff --git a/main.c b/main.c
index 248f94f3af32074fd38a757d968dc2a297cd5b63..5134e9849f5312b7bf239ee1f8def258c1c10388 100644 (file)
--- a/main.c
+++ b/main.c
@@ -61,12 +61,11 @@ int main(int argc, char **argv) {
        if  (!fp) {
                fclose(fp);
                return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
+       } else {
+               struct lex_file *lex = lex_open(fp);
+               lex_debug(lex);
+               parse    (lex);
+               lex_close(lex);
        }
-       
-       struct lex_file *lex = lex_open(fp);
-       lex_debug(lex);
-       parse    (lex);
-       lex_close(lex);
-       
        return 0;
 }
diff --git a/parse.c b/parse.c
index 129bcb197b1da7441d62bdf62ffb2606e7daf3bb..939831949df4b6c98107f140ce7c2e747c0050e0 100644 (file)
--- a/parse.c
+++ b/parse.c
 #include <limits.h>
 #include "gmqcc.h"
 
+
+static const char *const parse_punct[] = {
+       "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
+       "/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
+       "." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL
+       /* 
+        * $,@,: are extensions:
+        * $ is a shorter `self`, so instead of self.frags, $.frags
+        * @ is a constructor
+        * : is compiler builtin functions
+        */
+};
+
 int parse(struct lex_file *file) {
        int     token = 0;
        while ((token = lex_token(file)) != ERROR_LEX      && \
@@ -42,10 +55,89 @@ int parse(struct lex_file *file) {
                        
                        /* TODO: Preprocessor */
                        case '#':
-                               token = cpp(file);
+                               token = lex_token(file);
+                               token = lex_token(file);
+                               token = lex_token(file);
+                               token = lex_token(file);
+                               token = lex_token(file);
+                               token = lex_token(file);
+                               break;
+                               
+                       /* PUNCTUATION PARSING BEGINS */
+                       case '&':               /* &  */
+                               token = lex_token(file);
+                               if (token == '&') { /* && */
+                                       token = lex_token(file);
+                                       printf("--> LOGICAL AND\n");
+                                       goto end;
+                               }
+                               printf("--> BITWISE AND\n");
+                               break;
+                       case '|':               /* |  */
+                               token = lex_token(file);
+                               if (token == '|') { /* || */
+                                       token = lex_token(file);
+                                       printf("--> LOGICAL OR\n");
+                                       goto end;
+                               }
+                               printf("--> BITWISE OR\n");
+                               break;
+                       case '!':
+                               token = lex_token(file);
+                               if (token == '=') { /* != */
+                                       token = lex_token(file);
+                                       printf("--> LOGICAL NOT EQUAL\n");
+                                       goto end;
+                               }
+                               printf("--> LOGICAL NOT\n");
+                               break;
+                       case '<':               /* <  */
+                               token = lex_token(file);
+                               if (token == '=') { /* <= */
+                                       token = lex_token(file);
+                                       printf("--> LESS THAN OR EQUALL\n");
+                                       goto end;
+                               }
+                               printf("--> LESS THAN\n");
+                               break;
+                       case '>':               /* >  */
+                               token = lex_token(file);
+                               if (token == '=') { /* >= */
+                                       token = lex_token(file);
+                                       printf("--> GREATER THAN OR EQUAL\n");
+                                       goto end;
+                               }
+                               printf("--> GREATER THAN\n");
+                               break;
+                       case '=':
+                               token = lex_token(file);
+                               if (token == '=') { /* == */
+                                       token = lex_token(file);
+                                       printf("--> COMPARISION \n");
+                                       goto end;
+                               }
+                               printf("--> ASSIGNMENT\n");
+                               break;
+                       case ';':
+                               token = lex_token(file);
+                               printf("--> FINISHED STATMENT\n");
+                               break;
+                       case '-':
+                               token = lex_token(file);
+                               printf("--> SUBTRACTION EXPRESSION\n");
+                               break;
+                       case '+':
+                               token = lex_token(file);
+                               printf("--> ASSIGNMENT EXPRRESSION\n");
+                               break;
                }
+               end:;
        }
        lex_reset(file);
        
+       //      "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
+       //"/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
+       //"." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL
+       
        return 1;
 }