[antlr-interest] Grammar reuse without dynamic binding

Johannes Luber JALuber at gmx.de
Fri Feb 6 00:32:03 PST 2009


> Hi,
> 
> I would like to reuse a grammar in this kind of way:
> I have Pascal grammar 'pas.g' and I need to create Estelle grammar
> 'est.g'.
> Some rules from Pascal must be extended in Estelle.
> 
> For example:
> 'pas.g'
> assignment_statement:
>      (variable_access | function_identifier) ":=" expression;
> 
> 
> 'est.g'
> assignment_statement:
>      pas.assignment_statement
>    | module_variable ":=" module_variable;
> 
> I would like that alternative pas.assignment_statement in 'est.g'
> assignment_statement rule expand to rules from 'pas.g', even though we
> call rule in 'est.g' grammar and some of rules (variable_access |
> function_identifier) ":=" expression are also redefined in 'est.g'.
> I would like to get effect of namespace rather than inheritance.
> Is there better solution than unique renaming all nonterminals in 'pas.g'?
> 
> Sorry for my poor English.
> Best Regards!
> Tomasz Ulinski

This sounds like a case for composite grammars described here: <http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars> You can then override only those rules which are different.

Johannes
-- 
Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a


More information about the antlr-interest mailing list