|
From: | Thomas Lavergne |
Subject: | multiple grammars/parser with common parts |
Date: | Tue, 09 Mar 2004 13:57:29 +0100 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.1) Gecko/20020826 |
Hi all,I think I can now figure out how to write grammar files and use the semantic actions to create my objects with specified arguments. However, I have a question more on the conception point of vie of complex packages using bison/flex: Here is the situation. Imagine I have classes representing geometrical objects (spheres, rectangles,...). I have an executable Exe1 which wants to perform the instantiation of objects while parsing an input file with bison's actions. That's fine with one bison parser interfaced with yyparse(). Now, let's imagine I want to write another executable Exe2 which uses part of the same grammar (and underlying classes, hence the same grammar actions) along with other classes and grammar rules that are specific to him. I do not want to duplicate the common part of these two grammars because it is time consumming and will soon be a pain to maintain ; and I do not want Exe1 to learn for the part of grammar that is specific to Exe2 (and vice-versa). The question is how can I have multiple parsers with common parts in their grammar (both symbolic and semantic)?
In my parser file (bison.y), I am allowed to use #include, #ifdef, etc... so I think I can manage this by compiling twice my bison.y but with different prefix (-p prefix) and some #ifdef EXE1 and #ifdef EXE2 blocks. Anyway, I would like to know if there is any other solution (providing that this one works: not tested)?
Thanks for reading me and proposing your ideas. Thomas
[Prev in Thread] | Current Thread | [Next in Thread] |