aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2014-03-25 05:26:09 +0800
committerTeddy <[email protected]>2014-03-25 05:26:09 +0800
commit435a104dd5bc12c19e65001f2e8540eb30f1c4eb (patch)
tree5263ac1123c62430e9396b197e79e28dac8b5e5f
parent9e43ffed22d5ba25fe545a48ac732591c346aabb (diff)
lexical bugs
-rw-r--r--cibic.l5
-rw-r--r--main.c16
2 files changed, 17 insertions, 4 deletions
diff --git a/cibic.l b/cibic.l
index 26fca1f..cd9b6eb 100644
--- a/cibic.l
+++ b/cibic.l
@@ -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; }
diff --git a/main.c b/main.c
index 181dde2..463d290 100644
--- a/main.c
+++ b/main.c
@@ -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");