Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!lth.se!newsuser From: dag@control.lth.se (Dag Bruck) Newsgroups: comp.sources.wanted Subject: Re: YACC++ LEX++ Message-ID: <1990Dec18.095629.5729@lth.se> Date: 18 Dec 90 09:56:29 GMT References: <5140@tahoe.unr.edu> <3706@atomic.trl.mei.co.jp> Sender: newsuser@lth.se (LTH network news server) Organization: Department of Automatic Control, Lund, Sweden Lines: 68 Rebecca Hayhurst writes: > I'm looking for information, source on a LEX and YACC to produce > C++ code. I have successfully used the plain YACC and LEX supplied with our Sun system. YACC and LEX do not have any particular views on the contents of the actions; the trick is to make the C parser/scanner skeletons acceptable to the C++ compiler. The two files that must be changed are (on a Sun): /usr/lib/yaccpar /usr/lib/lex/ncform The following steps should bring you a long way: 1. Include the header file (enclosed below) in your .y and .l files. The file contains some declarations that the C++ compiler needs. 2. Modify the skeletons so they become legal C++ code. This essentially means that you will have to change the formal argument lists of the functions, etc. If you wrap your changes in #ifdef __cplusplus/#else/#endif, you will get a parser/scanner that is useful for *both* C and C++. Please note that your parser/scanner skeleton may be different from mine, so you may run into trouble I haven't discovered. Here is my header file: /* C++ definition for lex programs */ #ifdef __cplusplus #include extern int yydebug; extern int yylineno; extern int yynerrs; extern YYSTYPE yylval; extern void yyerror(const char *); extern int yylook(); extern int yyparse(); extern int yylex(); extern "C" { int yyless(); int yyreject(); int yywrap(); int yyback(int *, int); int yyinput(); void yyoutput(int); void yyunput(int); } #endif The `extern "C"' routines are in the LEX runtime library. Good luck. Dag M. Bruck -- Department of Automatic Control E-mail: dag@control.lth.se Lund Institute of Technology P. O. Box 118 Phone: +46 46-104287 S-221 00 Lund, SWEDEN Fax: +46 46-138118