Generating a parser that does not directly subclass LLkParser
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Curtis_Clifton
Posted On:   Wednesday, June 6, 2001 10:16 AM

I have several grammars where the generated parsers need to share some functionality. I would like create an abstract parser class, MyAbstractParser , that subclasses antlr.LLkParser . Then the parsers generated from my grammar files should extend MyAbstractParser . I haven't found a way to do this in ANTLR and would appreciate suggestions. I'm working on a compiler for MultiJava (a conservative extension to Java with open classes and multiple dispatch). My compiler is based on the Kopi Java compiler (kjc). The good folks at DMS who developed kjc used a customized version of ANTLR. I am working to switch to the standard ANTLR so I can take advantage of updates and bug fixes. kjc uses the pattern I described a   More>>

I have several grammars where the generated parsers need to share some functionality. I would like create an abstract parser class, MyAbstractParser , that subclasses antlr.LLkParser . Then the parsers generated from my grammar files should extend MyAbstractParser .



I haven't found a way to do this in ANTLR and would appreciate suggestions.



I'm working on a compiler for MultiJava (a conservative extension to Java with open classes and multiple dispatch). My compiler is based on the Kopi Java compiler (kjc). The good folks at DMS who developed kjc used a customized version of ANTLR. I am working to switch to the standard ANTLR so I can take advantage of updates and bug fixes. kjc uses the pattern I described above (i.e., abstract parser class). It accomplishes this by adding a new option to ANTLR:



superClass = "at.dms.compiler.Parser"



If there isn't a clean technique that accomplishes the same thing in ANTLR, what are the chances of the functionality being added? I would be more than happy to submit the necessary patches.



-- Curt

   <<Less

Re: Generating a parser that does not directly subclass LLkParser

Posted By:   Terence_Parr  
Posted On:   Thursday, June 7, 2001 03:20 PM

The simplest thing to do is to use "composition/delegation" instead of inheritance. If you want X to be the superclass for two grammars, then just add a reference to an object of type X to both grammars and add methods to delegate functionality to the contained object. You can override standard methods this way and so on.
About | Sitemap | Contact