]> git.mdlowis.com Git - proto/gir.git/commitdiff
Reworked parser and tree printing
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 29 Jun 2015 01:15:13 +0000 (21:15 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 29 Jun 2015 01:15:13 +0000 (21:15 -0400)
build.rb
source/parser.c
source/world.c

index 95f832846b7f9c0cb6f58b95fa66cf433885b450..813b3b9e4ceefe45d093cd032513ffd4e04e877b 100755 (executable)
--- a/build.rb
+++ b/build.rb
@@ -6,18 +6,16 @@ require './modules/build-system/setup'
 #------------------------------------------------------------------------------
 # Define the default compiler environment
 main_env = BuildEnv.new do |env|
-  env["CFLAGS"]  += ['-O3', '-Wall', '-Wextra', '-Werror', '--std=c99', '--pedantic']
-  env["CPPPATH"] += Dir['modules/libcds/source/**/'] +
-                    Dir['modules/libc/source/**/']
+  env["CFLAGS"]  += ['-O3', '-Wall', '-Wextra', '--std=c99', '--pedantic']
+  env["CPPPATH"] += Dir['modules/libc/source/**/']
 end
 
 #------------------------------------------------------------------------------
 # Release Build Targets
 #------------------------------------------------------------------------------
 # Build third party libraries
-main_env.Library('build/lib/libcds.a', FileList['modules/libcds/source/**/*.c'])
 main_env.Library('build/lib/libc.a',   FileList['modules/libc/source/**/*.c'])
-runtime_libs = ['build/lib/libcds.a', 'build/lib/libc.a']
+runtime_libs = ['build/lib/libc.a']
 
 # Build the parser
 main_env.Program('parser',  FileList['source/*.c'] + runtime_libs)
index 85f16f13d3c89cdd0dba67d06314113a0c56c861..68bc24d6e2b6c3c3bb8c6c6abbd1dd0e00cd6493 100644 (file)
  *****************************************************************************/
 // Types
 typedef struct AST {
-    int type;
     slist_node_t link;
     slist_t children;
+    char* text;
+    int type;
 } AST;
 
 typedef struct strbuf_t {
@@ -107,6 +108,7 @@ static void ast_print(AST* tree, int depth);
 // String Buffer
 static void strbuf_init(strbuf_t* buf);
 static void strbuf_putc(strbuf_t* buf, int ch);
+static char* strbuf_string(strbuf_t* buf);
 
 /*
  *****************************************************************************/
@@ -163,7 +165,6 @@ static AST* unary_send(void)
         AST* msg = ast_new(UNARY_MSG);
         ast_add_child(msg, expr);
         ast_add_child(msg, ast_tok(IDENTIFIER));
-        printf("%d\n", (int)slist_size(&msg->children));
         expr = msg;
     }
     return expr;
@@ -290,9 +291,13 @@ static bool optional(int expected)
  *****************************************************************************/
 static int token(void)
 {
+    // Re-init the token
+    strbuf_init(&Token);
+
     // Skip any whitespace.
     whitespace();
 
+    // Get the next real token
     if (EOF == current()) {
         return EOF;
     } else if ('$' == current()) {
@@ -461,15 +466,18 @@ static void fetch(void)
  *****************************************************************************/
 static AST* ast_new(int type)
 {
-    AST* tree  = (AST*)calloc(1,sizeof(AST));
+    AST* tree  = (AST*)malloc(sizeof(AST));
+    memset(tree, 0, sizeof(AST));
     tree->type = type;
     return tree;
 }
 
 static AST* ast_tok(int type)
 {
+    AST* ast  = ast_new(type);
     expect(type);
-    return ast_new(type);
+    ast->text = strbuf_string(&Token);
+    return ast;
 }
 
 static void ast_add_child(AST* parent, AST* child)
@@ -481,7 +489,7 @@ static void ast_print(AST* tree, int depth)
 {
     int indent = depth * 2;
     printf("%*s(", indent, "");
-    printf("%d", tree->type);
+    printf("%d %s", tree->type, tree->text ? tree->text : "");
     if (slist_size(&tree->children) == 0) {
         printf(")\n");
     } else {
@@ -521,10 +529,10 @@ static void strbuf_putc(strbuf_t* buf, int ch)
 //        strbuf_putc(buf, *str++);
 //}
 
-//static char* strbuf_string(strbuf_t* buf)
-//{
-//    char* str = buf->string;
-//    strbuf_init(buf);
-//    return str;
-//}
+static char* strbuf_string(strbuf_t* buf)
+{
+    char* str = buf->string;
+    strbuf_init(buf);
+    return str;
+}
 
index 3f6c6f7af658bcda7c281ba173315f28861802aa..dab195c666fd6f2cb08371fc96657ca519d8248f 100644 (file)
@@ -4,6 +4,7 @@
   */
 //#include "world.h"
 
+#if 0
 #include "set.h"
 #include "map.h"
 
@@ -55,5 +56,9 @@ void world_init(void)
     HashSet   = object_clone(Object);
     HashMap   = object_clone(Object);
 }
+#endif
 
+void world_init(void)
+{
+}