scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit c65b15611c17d3f264c71ee7f326c15d2e838431
parent db85440bb52b69b15dc485069a639ef92a4d50fd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Apr 2015 18:47:00 +0200

Recover from expect() errors

In this case the solution is very easy, because the only thing
the code must to do is to return the token expected by the
compiler.

Diffstat:
Mcc1/cc1.h | 2+-
Mcc1/error.c | 13+++++++++++--
Mcc1/lex.c | 6++++--
3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -3,7 +3,7 @@ extern void error(char *fmt, ...); extern void warn(char *fmt, ...); extern void unexpected(void); - +extern void softerror(char *fmt, ...); /* definitions of types */ #define CTX_OUTER 0 diff --git a/cc1/error.c b/cc1/error.c @@ -44,13 +44,22 @@ error(char *fmt, ...) va_start(va, fmt); warn_helper(-1, fmt, va); va_end(va); - failure = 1; longjmp(recover, 1); } void -unexpected(void) +softerror(char *fmt, ...) { + va_list va; + va_start(va, fmt); + warn_helper(-1, fmt, va); + va_end(va); + failure = 1; +} + +void +unexpected(void) +{ error("unexpected '%s'", yytext); } diff --git a/cc1/lex.c b/cc1/lex.c @@ -374,8 +374,10 @@ next(void) void expect(uint8_t tok) { - if (yytoken != tok) - unexpected(); + if (yytoken != tok) { + softerror("unexpecetd '%s'", yytext); + yytoken = tok; + } next(); }