Supergrammar and C++ generation (a possible better solution)
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Michael_Lindig
Posted On:   Wednesday, March 21, 2001 10:47 PM

Hi, in the actual release of ANTLR the produced cpp code for a parser which are defined as: class SubParser extends SuperParser; includes all rules of SuperParser. A better solution is: Generate the parser output files for SuperParser as normal. SubParser should inherit from SuperParser instead of LLkParser: class SubParser : public SuperParser The rules from SuperParser should be included as: public: void a_SuperParser_Rule() { // include some trace rules SuperParser::a_SuperParser_Rule(); } The trace options shall only be valid for a   More>>

Hi,

in the actual release of ANTLR the produced cpp code for a parser which are defined as:


class SubParser extends SuperParser;

includes all rules of SuperParser.

A better solution is:

Generate the parser output files for SuperParser as normal.

SubParser should inherit from SuperParser instead of LLkParser:

class SubParser : public SuperParser

The rules from SuperParser should be included as:

			
public: void a_SuperParser_Rule()
{
// include some trace rules
SuperParser::a_SuperParser_Rule();
}


The trace options shall only be valid for actual grammar file this means trace statements should only be included for SubParser.

If no super grammar specified then all undefined rules shall be generated as SuperParser rule.

What do You think about that ? It is possible or not ? Make it sense ?

Michael

   <<Less

Re: Re: Supergrammar and C++ ...

Posted By:   Michael_Lindig  
Posted On:   Monday, March 26, 2001 02:52 AM

I think a solution can be :



Make all superrules virtual. Generate only the rules for sub grammar which are specified in the grammar file. 

If one has override a rule then the virtual call does the new rule of sub grammar.

Re: Supergrammar and C++ generation (a possible better solution)

Posted By:   Terence_Parr  
Posted On:   Saturday, March 24, 2001 11:05 AM

Howdy. Good thoughts. The problem is that grammar inheritance differs from Java/C++ inheritance in the sense that a subrule can alter the actual code generation needed by the superrule! Hence, simply allowing super::rule() to do the work is actually not valid. I wonder if we could simply detect when the superrule did not change and then just call super. Hmm...
About | Sitemap | Contact