[antlr-interest] On to the next issue: error(211)

Gavin Lambert antlr at mirality.co.nz
Tue Nov 11 11:41:42 PST 2008


At 01:52 12/11/2008, Hendrik Maryns wrote:
 >The thing I am having trouble with is that, with the idea of
 >polymorphism etc., I'd like to have things dealt with at the
 >appropriate place.
 >
 >I have rules like
 >
 >atomic : atomicHead variable label ;
 >
 >atomicHead : EQUALITY | DOMINANCE | INCLUSION | 
 ;
 >
 >and depending on the value of atomicHead, I 
want a different Java
 >object to be created.

If you have input AST fragments like this:
   ^(EQUALITY a b)
   ^(DOMINANCE a b)
   ^(INCLUSION a b)
   ^(INVERSE a)

then they're trivial to parse with AST 
rules.  The job of the parser is usually to 
translate the sequential token stream into a tree 
structure that conveys the intended meaning; the 
tree parser then goes through that tree and does 
whatever you want.  The tree grammar is usually 
very simple and you should almost never need to 
use any predicates in it.

(Though I'm not sure why you're calling this 
"atomic".  It seems like an odd choice of name 
for something that seems to require neighbouring symbols as well.)

 >I cannot do
 >
 >atomic return [Formula result] : atomicHead[$variable.result,
 >$label.result] variable label { $result = $atomicHead.result; };
 >
 >since $variable.result and $label.result will not have been
 >evaluated at that point.

atomic returns [Formula result]
   : ^(EQUALITY variable expr) { $result = new
         Equality($variable.result, $expr.result); }
   | ^(DOMINANCE ...



More information about the antlr-interest mailing list