ref: c65b15611c17d3f264c71ee7f326c15d2e838431
parent: db85440bb52b69b15dc485069a639ef92a4d50fd
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Apr 21 14:47:00 EDT 2015
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.
--- 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
--- a/cc1/error.c
+++ b/cc1/error.c
@@ -44,13 +44,22 @@
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);
}
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -374,8 +374,10 @@
void
expect(uint8_t tok)
{
- if (yytoken != tok)
- unexpected();
+ if (yytoken != tok) {
+ softerror("unexpecetd '%s'", yytext);
+ yytoken = tok;
+ }
next();
}
--
⑨