[antlr-interest] AST=type inheritance

Jörg Domaschka joerg at domaschka.org
Wed Jun 22 11:35:40 PDT 2005


Hi everybody,

I have some problems with antlr's grammar inheritance. have a look at the
following:

----------------------------------------------------------------------------
----
class IDLParser extends Parser;
options{
/* some options */
}

tokens {
INTERF="interface"<AST=InterfNode>;
/* more tokens */
}

interf
: (l:"local"! | a:"abstract"!)? INTERF^
name:identifier!
(i:opt_inheritance_spec b:LCURLY! (export)* RCURLY!)?
{
#INTERF.setText(#name.getText());
if(#i != null) {
#INTERF.setInherit();
}
/* and so on... */
----------------------------------------------------------------------------
----
this results in the java-code:

public final void interf() throws RecognitionException, TokenStreamException
{
/* ... */
    InterfNode tmp15_AST = null;
    tmp15_AST = (InterfNode)astFactory.create(LT(1),"InterfNode");
################################################################
further I have something like:

class EIDLParser extends IDLParser;
/* tokens and options */
/* labels */
----------------------------------------------------------------------------
----
now the above code looks different, though the definition of "interf" is not
changed, nor is INTERF

public final void interf() throws RecognitionException, TokenStreamException
{
/* ... */
AST tmp16_AST = null;
tmp16_AST = astFactory.create(LT(1));
################################################################

all type information is lost. I think the reason is, the implicit
exportVocab and importVocab done by the inheritance mechanism doesn't keep
the types, since the format is like
INTERF="interface"=5
now my question:
is there any way to force antlr ex- and importing also class names? I'm
thankful for every reply, even if it's just a hack or a hint which source
code files are responsible for exporting and importing.

thanks a lot,
sincerely

Joerg



More information about the antlr-interest mailing list