aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2014-03-26 03:12:31 +0800
committerTeddy <ted.sybil@gmail.com>2014-03-26 03:12:31 +0800
commitaf5df36aa343234c945fa6eae30d9bb03551e1a5 (patch)
treecf66d88a4c707d5fcac52cd89aa0759c7ca09742 /main.c
parent2883565cc927fcc3de2297ed69500b8c59a4f625 (diff)
fancy error report
Diffstat (limited to 'main.c')
-rw-r--r--main.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/main.c b/main.c
index 2e6fb35..d36dd6c 100644
--- a/main.c
+++ b/main.c
@@ -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;
}