Lex/Yacc: Multiple parsers in one file

"Christoph B." <dj.cyberdance@gmx.at>
29 Mar 2006 18:55:45 -0500

          From comp.compilers

Related articles
Lex/Yacc: Multiple parsers in one file dj.cyberdance@gmx.at (Christoph B.) (2006-03-29)
Re: Lex/Yacc: Multiple parsers in one file parcour@gmail.com (Joshua Shinavier) (2006-04-01)
Re: Lex/Yacc: Multiple parsers in one file oliver@first.in-berlin.de (Oliver Bandel) (2006-04-03)
Re: Lex/Yacc: Multiple parsers in one file ogilviep@xs4all.nl (Paul Ogilvie) (2006-04-08)
| List of all articles for this month |

From: "Christoph B." <dj.cyberdance@gmx.at>
Newsgroups: comp.compilers
Date: 29 Mar 2006 18:55:45 -0500
Organization: Compilers Central
Keywords: parse, question, comment
Posted-Date: 29 Mar 2006 18:55:45 EST

Hello everybody,


Thanks for supporting me on my C/C++ problem, finally I got it fixed and
my parser is working pretty fine now. Unfortunately the next problem is
to be solved. I need to merge the input of two different files (or file
types), that need different parsers. They do not need to be parsed
simultaneously but because these files are related quite closely to each
other, I would prefer to put the parsers together in one.


Does anyone know where to find a simple example on how to use mulitple
parsers in one file? Or maybe someone can give me instructions or a
short example?


Again, I believe I should mention that I am really a newbie on lex/yacc
and that I am quite new to coding C++ as well.


So what I believe I need is two different lex files for two different
syntaces. But one yacc file should be enough I believe. I've been
googling for quite some time, what I found out is that yacc and lex
support a -P parameter that gives the global variables different
suffices. So what I know is that it IS possible to combine multiple
parsers, but I do not know HOW exactly they can be merged.


Thank you very much for your help in advance,
Yours
Christoph Bouvier
[This has come up before. If you really want different parsers, you put the two
grammars in separate files and use -p to give the parsers different names. If they
are similar, you can often combine them and have the lexer provide a different
initial token so it knows what it's parsing, e.g.:


start: FOO foo-start-rule | BAR bar-start-rule ;


-John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.