[antlr-interest] antlr v3 grammar inheritance
Austin Hastings
Austin_Hastings at Yahoo.com
Tue Oct 9 10:34:52 PDT 2007
Are you using the "tokenVocab" option to force the two parsers to share
a common token numbering scheme?
=Austin
Mihai Gheorghe wrote:
> 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
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.488 / Virus Database: 269.14.6/1059 - Release Date: 10/9/2007 8:44 AM
>
More information about the antlr-interest
mailing list