[antlr-interest] antlr v3 grammar inheritance

Mihai Gheorghe anonftp at gmail.com
Tue Oct 9 10:26:30 PDT 2007


Using ANTLR v3.0.1,
I'm trying to inherit rules from one grammar to another, like this:

//========================Start file Base.g3=========================
grammar Base;

baseRule
    : F1
    | F2
    | F3
    | F4
    ;

F1
    : 'F1'
    ;
F2
    : 'F2'
    ;
F3
    : 'F3'
    ;
F4
    : 'F4'
    ;

f5
    : 'Something'
    ;

WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    ;
//========================End file Base.g3=========================

//========================Start file Extended.g3=========================
grammar Extended;

options {
 superClass=BaseParser;
}


compilationUnit
    : func1N
    | ABC
    ;

func1N
    : g1
    ;

g1
    : F1
    | F2
    ;

g2
    : F3
    | F4
    ;

ABC
    : 'ABC'
    ;

WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    ;
//========================End file Extended.g3=========================


but ANTLR doesn't recognize rules defined in Base when called from Extended

I've checked the documentation but found no examples. Instead I got:

http://www.antlr.org/wiki/display/ANTLR3/inheritance+or+some+other+grammar+sharing+mechanism
http://www.antlr.org/wiki/display/ANTLR3/add+superClass+to+lexer

Are these IMPLEMENTED in ANTLR v3.0.1?

Does anybody solved the problem of grammar inheritance in v3?

-- 
Best regards,
Mihai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071009/a4506ba6/attachment.html 


More information about the antlr-interest mailing list