From: Mike D. Lowis Date: Fri, 29 May 2015 20:43:19 +0000 (-0400) Subject: Added support for chaning the input file and added comments to the whitespace lexical... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e4ec1648cfd5f458d029e587e8878c3ca7319033;p=proto%2Fgir.git Added support for chaning the input file and added comments to the whitespace lexical rule --- diff --git a/source/main.c b/source/main.c index 0075a14..e5394e3 100644 --- a/source/main.c +++ b/source/main.c @@ -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) {