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 12:19:59 +0200 (CEST)

On Mon, 11 Aug 2008, kogorman wrote:

> 
> All this is true, but beside the point.  What's missing is yyerrok, not
> yyerror.

This is what you wrote:

> >> But my C++ parser
> >> won't compile because (it says) yyerror was not declared in this context. 

> I've got the required yyerror and yylex.

I found this in the file of C++ code generated by Bison:

#define yyerrok         (yyerrstatus = 0)

Are you perhaps typing `yyerrorok' instead of `yyerrok'?

> 
> I'm using a C++ setup because I don't want to mix FILE* and C++ streams,
> and just because it seems the Right Thing To Do (TM).

Of course, you can avoid using objects of type `FILE' and pointers 
to them if you want, but I don't see any reason why one shouldn't 
use them and C++ streams in the same program and/or compilation 
units.  `popen', for example, returns a `FILE*' and I don't know of
any function from the C++ STL that does the same thing and returns 
a stream object instead.  One might even have a reason to use 
file descriptors.  Generating C++ parser or generating a C 
parser that contains C++ code is just a matter of taste, not 
a question of right or wrong.  
  

Laurence

> 
> Laurence Finston wrote:
> > 
> >> 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
> >> 
> > 
> > 
> > _______________________________________________
> > address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/yyerrok-is-missing-in-C%2B%2B-parser-tp18919947p18922339.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]