[comp.archives] [c++...] Re: yacc/lex experience...

lma@Neon.Stanford.EDU (Larry M. Augustin) (08/07/90)

Archive-name: bison++/07-Aug-90
Original-posting-by: lma@Neon.Stanford.EDU (Larry M. Augustin)
Original-subject: Re: yacc/lex experience...
Archive-site: wilbur.stanford.edu [36.14.0.30]
Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)

In article <4049@czech.sw.mcc.com> krohn@czech.sw.mcc.com (Eric Krohn) writes:
>In article <3006@zipeecs.umich.edu> bagchi@dip.eecs.umich.edu (Ranjan Bagchi) writes:
>]     Does anyone have any experience with using yacc & lex in
>] conjunction with c++/g++?  I've got a yyparse function which I would
>] like to make a member function of class say...foo.  
>]     I'm assuming that everything could be done with a sed script, but
>] I really don't know about all the functions which need name-changes.
>
>I have turned yyparse into a member function for two different programs.
>Among the advantages are turning the global variables used to communicate
>with yyparse into member variables, and access to members variables and
>functions within the yacc actions.  With a little doctoring of the y.tab.c,
>you can have multiple coexisting parsers, each within its own class.
>
>The definition of yyparse must have its name changed to member function
>syntax (Parser::yyparse, for example).  It is wise to make yychar,
>yylval, yydebug, yylex(), and yyerror() into member variables/functions
>also.  Have your sed (or perl) script delete the global
>definitions/forward declarations of yychar, yylval, yyparse, yydebug,
>and yyerrflag.  If you want multiple parsers, or if you like data
>hiding, make all the other global yy* names static.

I have a version of bison (I call it bison++) that I hacked up some
time ago to generate a parser class in this vein.  It's available via
anonymous ftp on wilbur.stanford.edu.

Larry M. Augustin			ERL 414
lma@sierra.stanford.edu			Computer Systems Lab
lma@dayton.stanford.edu			Stanford University
(415) 723-9285				Stanford, CA 94305