help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yyerrok is missing in C++ parser


From: Laurence Finston
Subject: Re: yyerrok is missing in C++ parser
Date: Mon, 11 Aug 2008 08:38:09 +0200 (CEST)

> The C examples show using yyerror and the examples compile and run okay. 
> But my C++ parser
> won't compile because (it says) yyerror was not declared in this context. 
> And when I look at 
> the generated code, the #define I see in the C scanners is missing.  This is
> a nuisance; is there
> anything I can do to make it (or the appropriate C++ analogue) appear?
> 

I usually use C++ in the actions of my parsers, but I never generate a C++ 
parser, so there may be some difference that you'll have to account for.

When generating a C parser, one has to declare `yyerror', `yylex' and 
possibly `yywrap' in the first section of the parser input file.  They may 
be defined somewhere else.  `yylex', of course, can be generated by Flex 
or lex, and I believe there's an option for having at least one of the 
others generated automatically by Flex and possibly by Bison.  One has to 
make sure that the declaration matches the function, which can be slightly 
tricky, if you're passing a parameter to `yyparse' and `yylex' and 
generating reentrant versions of these functions. 

Here's an example:

int 
yylex(YYSTYPE* lvalp, yyscan_t parameter);

int
yywrap(void);

int
yyerror(void* v, char const* s);

For what it's worth, I don't see any particular advantage in generating a 
C++ parser instead of a C parser, but that's just my opinion and I haven't 
kept up with developments with respect to this feature.

Laurence Finston

On Sun, 10 Aug 2008, kogorman wrote:

> 
> I'm developing a very simple parser to frontend to an existing C++ board game
> (named "six").
> 
> I'm following the examples as best I can, but my attempts at syntax error
> handling are failing.
> 
> The C examples show using yyerror and the examples compile and run okay. 
> But my C++ parser
> won't compile because (it says) yyerror was not declared in this context. 
> And when I look at 
> the generated code, the #define I see in the C scanners is missing.  This is
> a nuisance; is there
> anything I can do to make it (or the appropriate C++ analogue) appear?
> 
> For reference, the starting point for this project was the C++ example from
> the Bison docs, and
> the error processing from the multifunction calculator C example from the
> same docs.
> 
> Here's the scanner spec:
> http://www.nabble.com/file/p18919947/sixcl-parser.yy sixcl-parser.yy 
> 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/yyerrok-is-missing-in-C%2B%2B-parser-tp18919947p18919947.html
> Sent from the Gnu - Bison - Help mailing list archive at Nabble.com.
> 
> 
> 
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]