bagchi@dip.eecs.umich.edu (Ranjan Bagchi) (08/06/90)
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. again...calling upon the knowledge banks ofthe net... -rj bagchi@eecs.umich.edu
eapu034@orion.oac.uci.edu (Carl F. Edman) (08/06/90)
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. > > again...calling upon the knowledge banks ofthe net... > > -rj > bagchi@eecs.umich.edu Not exactly, but using g++ 1.37.1 and bison 1.11, I was able to modify the bison.simple/hairy files so that they compile without errors under g++. Really not very difficult and even when you make the change 2 warning messages remain which indicate that labels are defined but not used (You really should be able to turn of these labels.). Possibly not the most elegant solution, but , I assure you, quite workable. If you don't want to go to the trouble and do the modifications yourself, drop me a line (at the address in the signature, please) and I can send/ftp the changed files to you. Carl Edman Theorectial Physicist,N.:A physicist whose | Send mail existence is postulated, to make the numbers | to balance but who is never actually observed | cedman@golem.ps.uci.edu in the laboratory. | eapu034@orion.oac.uci.edu
krohn@czech.sw.mcc.com (Eric Krohn) (08/06/90)
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.
With a little care, your script will be able to process output from the
different UNIX yaccs, the PD Berkeley yacc, and bison. Some things to watch
for are:
* The call to getenv from Berkeley yacc (fixed in a recent release).
* The calls to free in SunOS 4.0 yacc (Sun broke with AT&T cfront tradition and
reverted to declaring void free (char *) instead of void free (void *)).
Having used hand coded lexers, I cannot say anything offhand about wrapping
lex output in a C++ class.
--
Eric J. Krohn
krohn@sw.mcc.com
lma@Neon.Stanford.EDU (Larry M. Augustin) (08/07/90)
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