Question

I have an application where I already have a parser for one sort of grammar and I need to add a second different grammar for another purpose.

Is it possible to have more than one?

And if so how do you get another entry point?

Thanks

david allan finch

Was it helpful?

Solution

I think you can to this by using the --name-prefix option to Bison, and the --prefix option to Flex.

In both cases they allow you to replace the default "yy" prefix used on the functions generated with a prefix of your own choice.

OTHER TIPS

Yes, it's possible.

yacc should have a -p flag, where you can specify a different prefix instead of the default "yy".

The file generated by lex conatins only one symbol used outside: yylex. You can compile with -Dyylex=mySecondLex, for example.

Not a direct answer, but you may want to consider using a more generic approach such as GoldParser which allows you to use a generic engine to process the LALR and DFA tabled generated from your grammars.

This way around, you can use any number of different grammars in the same application, and changing the grammar does not create new source code but rather just new table files (which could be included as embedded resource or similar).

Standard lex and yacc have no way of doing that. Flex and Bison do, as do some other implementations. Since you said (in a comment) that you aren't using flex and bison, which versions of lex and yacc are you using?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top