]> git.mdlowis.com Git - proto/gir.git/commitdiff
Added support for chaning the input file and added comments to the whitespace lexical...
authorMike D. Lowis <mike.lowis@gentex.com>
Fri, 29 May 2015 20:43:19 +0000 (16:43 -0400)
committerMike D. Lowis <mike.lowis@gentex.com>
Fri, 29 May 2015 20:43:19 +0000 (16:43 -0400)
source/main.c

index 0075a142c95fa80dbf40990e490e9f4d2c23da7f..e5394e38ea11bd685215fe5e8c7a9ca78c650f28 100644 (file)
@@ -47,6 +47,7 @@ typedef struct AST {
 } AST;
 
 // Globals
+static FILE* File;
 static int CurrChar = ' ';
 static int CurrTok  = UNKNOWN;
 static intptr_t Token_Buffer[1024];
@@ -278,8 +279,16 @@ static int token(void)
 
 static void whitespace(void)
 {
-    while (isspace(current()))
-        discard();
+    while(isspace(current()) || ('#' == current())) {
+        if ('#' == current()) {
+            discard();
+            while (('\n' != current()) && (EOF != current()))
+                discard();
+            discard();
+        } else {
+            discard();
+        }
+    }
 }
 
 static int symbol(void)
@@ -387,12 +396,12 @@ static int current(void)
 
 static void append(void)
 {
-    CurrChar = getchar();
+    CurrChar = fgetc(File);
 }
 
 static void discard(void)
 {
-    CurrChar = getchar();
+    CurrChar = fgetc(File);
 }
 
 static void expect_ch(int ch)
@@ -403,7 +412,6 @@ static void expect_ch(int ch)
         lex_error();
 }
 
-
 /* Tree Routines
  *****************************************************************************/
 AST* Tree(int type, int num_children)
@@ -467,6 +475,7 @@ void push_reduce(int type, int nchildren)
  *****************************************************************************/
 int main(int argc, char** argv) {
     extern void world_init(void);
+    File = stdin;
     world_init();
     printf(":> ");
     while(true) {