[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: error: else without a previous if
From: |
Joel E. Denny |
Subject: |
Re: error: else without a previous if |
Date: |
Wed, 13 Jan 2010 15:51:23 -0500 (EST) |
User-agent: |
Alpine 1.00 (DEB 882 2007-12-20) |
Hi Tys,
On Wed, 13 Jan 2010, tys lefering wrote:
> when updating today bison, gnulib and autoconf from git repo
> and installing bison the generated yacc parser does not compile
> with this error when using gcc or g++:
>
> y.tab.c: In function ?yyparse?:
> y.tab.c:5998: error: ?else? without a previous ?if?
> source code part of the parser is here
> if (yysyntax_error_status == 0)
> yyerror (yymsg);
> else /* <-- y.tab.c:5998: error: ?else? without a previous ?if?*/
> yyerror (YY_("syntax error"));
> when changing parser code to this adding '{' and '}' gcc / g++ does accept
> it:
>
> if (yysyntax_error_status == 0) {
> yyerror (yymsg);
> } else {
> yyerror (YY_("syntax error"));
> }
>
> any solution ? maybe add the '{' '}' in the yacc parser code ?
yyerror is supposed to be a function according to the Bison manual, but
your grammar file defines it as braced code:
> #ifndef yyerror
> #define yyerror(x) { \
> SPRINTF(message,"unexpected %s \"%s\" (%s)", \
> ((yychar<0)?"(?)":yytokname[YYTRANSLATE(yychar)]), \
> (strlen(yytext)<48?yytext:"(?)"),x); \
> syntaxerror(line_nr,pos_nr,message);\
> }
> #endif
Thus, the Bison-generated trailing semicolon looks like a separate
statement after your yyerror's closing brace. That ends the `if'
construct.
I have another patch coming that will just happen to change this passage
of code in such a way that this won't be a problem anymore. However, I'm
not sure when I'll get around to proposing it.
Regardless, it would be best if you changed yyerror to a function or at
least a function invocation.