[antlr-interest] Help on recursive tree grammar rule
Paulius Juodisius
juodaspaulius at gmail.com
Mon Jul 23 22:38:44 PDT 2012
Hi,
I am fairly new to Antlr and trying to learn all its features. Currently
I am struggling to define tree grammar where tree visitor would return
objects that have reference to previously created objects. More
specifically parser grammar a rule has a recursion to itself. However I
am not sure on how recursive rule can be defined in tree grammar in with
a respect to parent tree node expression.
Below I will briefly describe my language samples and snippets from
combined grammar.
I need to parse such expressions:
entity1/entity2/property
entity1/entity2/entity3/property
and so on..
From a tree grammar I am expecting to get an objects that conform to
following classes.
class property {
ientity source;
}
interface ientity
class entity: ientity{
ientity source;
}
class root: ientity {}
I have defined parser rules:
entityPropertyRef
: linkedEntities property -> ^(ENTITYPROPERTY linkedEntities
property)
;
linkedEntities
: entity^ (linkedEntities)*;
;
entity: MEMBER "/"!;
property: MEMBER;
and lexer rules:
MEMBER: LETTER ( NAMECHAR )* ;
fragment LETTER
: 'a'..'z'
| 'A'..'Z'
;
fragment NAMECHAR : LETTER | DIGIT | '_' ;
fragment DIGIT : '0'..'9';
Sincerely,
Paulius
More information about the antlr-interest
mailing list