]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Starting some parsing
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Mon, 16 Jul 2012 12:14:37 +0000 (14:14 +0200)
committerWolfgang Bumiller <wolfgang.linux@bumiller.com>
Mon, 16 Jul 2012 12:14:37 +0000 (14:14 +0200)
lexer.c
parser.c

diff --git a/lexer.c b/lexer.c
index 867fb9430fe796ed227a59a13279415cd6d3fd63..2c6bcb0b9ebc94b3309816fec313ed95af3b6218 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -559,20 +559,25 @@ int lex_do(lex_file *lex)
                lex->tok->ttype = TOKEN_IDENT;
 
                v = lex->tok->value;
-               if (!strcmp(v, "void") ||
-                   !strcmp(v, "int") ||
-                   !strcmp(v, "float") ||
-                   !strcmp(v, "vector") )
-               {
+               if (!strcmp(v, "void")) {
                        lex->tok->ttype = TOKEN_TYPENAME;
-                       switch (v[1]) {
-                               case 'o': lex->tok->constval.t = TYPE_VOID;    break;
-                               case 'n': lex->tok->constval.t = TYPE_INTEGER; break;
-                               case 'l': lex->tok->constval.t = TYPE_FLOAT;   break;
-                               case 'e': lex->tok->constval.t = TYPE_VECTOR;  break;
-                       }
-               }
-               else if (!strcmp(v, "for") ||
+                   lex->tok->constval.t = TYPE_VOID;
+               } else if (!strcmp(v, "int")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_INTEGER;
+               } else if (!strcmp(v, "float")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_FLOAT;
+               } else if (!strcmp(v, "string")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_STRING;
+               } else if (!strcmp(v, "entity")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_ENTITY;
+               } else if (!strcmp(v, "vector")) {
+                       lex->tok->ttype = TOKEN_TYPENAME;
+                   lex->tok->constval.t = TYPE_VECTOR;
+               } else if (!strcmp(v, "for") ||
                         !strcmp(v, "while") ||
                         !strcmp(v, "do"))
                        lex->tok->ttype = TOKEN_KEYWORD;
index 0dd972e169b5c0ac56d88a8deb9281057f675c3d..c753c59aa782325d9755fd195ec837a57d1ecd31 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1,7 +1,44 @@
 #include "gmqcc.h"
 #include "lexer.h"
 
+typedef struct {
+    lex_file *lex;
+    int      tok;
+} parser_t;
+
+bool parser_do(parser_t *parser)
+{
+    return true;
+}
+
 bool parser_compile(const char *filename)
 {
-    return false;
+    parser_t *parser;
+
+    parser = (parser_t*)mem_a(sizeof(parser_t));
+    if (!parser)
+        return false;
+
+    parser->lex = lex_open(filename);
+
+    if (!parser->lex) {
+        printf("failed to open file \"%s\"\n", filename);
+        return false;
+    }
+
+    for (parser->tok = lex_do(parser->lex);
+         parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR;
+         parser->tok = lex_do(parser->lex))
+    {
+        if (!parser_do(parser)) {
+            printf("parse error\n");
+            lex_close(parser->lex);
+            mem_d(parser);
+            return false;
+        }
+    }
+
+    lex_close(parser->lex);
+    mem_d(parser);
+    return true;
 }