diff options
-rw-r--r-- | cibic.l | 5 | ||||
-rw-r--r-- | main.c | 16 |
2 files changed, 17 insertions, 4 deletions
@@ -64,12 +64,12 @@ digit [0-9] return INT_CONST; } -'([^\'\\]|\\.)' { +'([^\'\\]|\\.|\\[0-7][0-7]?[0-7]?|\\[xX][0-9a-fA-F]+)' { yylval.strval = strdup(yytext); return CHAR_CONST; } -\"[^\n\"]*\" { +\"[^\n\"]*\" { yylval.strval = strndup(yytext + 1, strlen(yytext) - 2); return STR_CONST; } @@ -79,6 +79,7 @@ digit [0-9] "==" { return OPT_EQ; } "!=" { return OPT_NE; } "<=" { return OPT_LE; } +">=" { return OPT_GE; } "<<" { return OPT_SHL; } ">>" { return OPT_SHR; } "++" { return OPT_INC; } @@ -5,6 +5,7 @@ extern int yyparse(); extern FILE *yyin; +char *fname; int yywrap() { return 1; @@ -15,10 +16,17 @@ int yyerror(char *s) { void print_ast() { yyparse(); + if (fname) + printf("AST for file: \"%s\"\n", fname); + else + printf("AST for stdin\n"); + if (ast_root) + { cnode_debug_print(ast_root, 1); + } else - fprintf(stderr, "Syntax Error\n"); + fprintf(stdout, "Syntax Error\n"); } void print_help() { @@ -51,7 +59,8 @@ int main(int argc, char **argv) { } if (optind == argc - 1) { - yyin = fopen(argv[argc - 1], "r"); + fname = argv[argc - 1]; + yyin = fopen(fname, "r"); if (!yyin) { fprintf(stderr, "Error while opening file."); @@ -59,7 +68,10 @@ int main(int argc, char **argv) { } } else if (optind == argc) + { + fname = NULL; yyin = stdin; + } else { fprintf(stderr, "Only one source file is exepected.\n"); |