Interfacing yacc/lex with C++

Rob Horn aardvark at cooper.cooper.EDU
Thu Sep 20 09:39:35 AEST 1990


interfacing C++ with Yacc is messy, but easily done.
Yacc itself produces C code with the users actions imbedded in it
unchanged. Yacc does not care if your actions are valid C

since C++ is a superset of C, the Yacc/Lex generated code can be compiled 
with the C++ compiler. example:

%token SPAM MOOSE FOOBAR . . .
	ferret	: SPAM MOOSE
			{ // C++ code }
		| SPAM SPAM
			{ // C++ code }
		;
%%

Yacc will completely ignore what the actions you give it are and will put
them unchanged into the file it produces.
The version of Yacc I have used produces an old style C code, and thus the 
C++ compiler will print out a bunch of horrible warnings 
"warning: yyparse() old style declaration. type int assumed. " and such,
but will produce no errors, provided the actions are acceptable C++ code.



More information about the Comp.lang.c mailing list