diff options
author | Teddy <[email protected]> | 2014-03-26 03:12:31 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-03-26 03:12:31 +0800 |
commit | af5df36aa343234c945fa6eae30d9bb03551e1a5 (patch) | |
tree | cf66d88a4c707d5fcac52cd89aa0759c7ca09742 /main.c | |
parent | 2883565cc927fcc3de2297ed69500b8c59a4f625 (diff) |
fancy error report
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -4,6 +4,8 @@ #include "cibic.tab.h" #include "ast.h" +extern char linebuff[]; +extern char *lptr; extern int yyparse(); extern FILE *yyin; char *fname; @@ -12,8 +14,17 @@ int yywrap() { return 1; } -int yyerror(char *s) { - fprintf(stderr, "%s\n", s); +void print_error(char *err_msg, int row, int col) { + *lptr = '\0'; + fprintf(stderr, "%d:%d: %s\n%s\n", + row, col, err_msg, linebuff); + while (--col) putchar(' '); + putchar('^'); +} + +int yyerror(char *err_msg) { + print_error(err_msg, + yylloc.first_line, yylloc.first_column); return 0; } |