[antlr-interest] rewrite smth like "type: (primitive|complex) multiplicity?"
Felix Dorner
felix_do at web.de
Thu Mar 6 04:54:09 PST 2008
Hey,
I have a grammar rule for specifying the type of a variable.
vardef : Identifier ':' type;
type : (PrimitiveType | complexType) ('['IntegerLiteral']')?;
PrimitiveType : 'int' | 'boolean';
complexType : Identifier ('*' Identifier)* -> Identifier+;
I'd like the trees for vardefs like this, i.e. introduce an additional
type subtree.
(VAR i (TYPE int 4))
(VAR j (TYPE int))
(VAR k (TYPE abc def ghi 5))
To achieve this I try something like:
type : ... -> ^(TYPE (PrimitiveType | ComplexType) IntegerLiteral? // or
type: (e=...) ->^(TYPE $e.tree IntegerLiteral?
but this does not work. I can't find another solution but to respecify
the type rule like this:
type : primitiveType ('['IntegerLiteral']'?) -> ^(TYPE primitiveType
IntegerLiteral?)
| complexType ('[IntegerLiteral']' )?-> ^(TYPE complexType
IntegerLiteral?)
I bet there are solutions with more style? Thanks,
Felix
More information about the antlr-interest
mailing list