Xref: utzoo comp.lang.c++:8835 gnu.g++:1022 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!rex!samsung!uakari.primate.wisc.edu!sdd.hp.com!decwrl!shelby!neon!lma From: lma@Neon.Stanford.EDU (Larry M. Augustin) Newsgroups: comp.lang.c++,gnu.g++ Subject: Re: yacc/lex experience... Message-ID: <1990Aug7.025211.14584@Neon.Stanford.EDU> Date: 7 Aug 90 02:52:11 GMT References: <3006@zipeecs.umich.edu> <4049@czech.sw.mcc.com> Organization: Computer Science Department, Stanford University Lines: 30 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