[antlr-interest] Question on aborting rule based on pattern
Stanimir Stamenkov
stanio at myrealbox.com
Mon Jul 24 00:28:59 PDT 2006
/Stanimir Stamenkov/:
> You need to put 'aaa' and 'ccc' productions as alternatives to some
> rule, like:
[...]
Or may be I haven't understood you goal correctly and you might need
a syntactic predicate [1] in the 'ddd' rule:
aaa : "AAAA" SPACE bbb ccc ;
bbb : ( ddd )+ ;
ddd : ("XXX") => ccc
| ha:ATOM ":" SPACE eee SPACE ; // Rule 1
eee : hva:ATOM (":" hvap:ATOM)* ;
ccc : "XXX" ":" SPACE ((cccentry)+ ; // Rule 2
Or if the 'ATOM' lexer rule tests for literals it would match the
"XXX" literal and I think no predicate is necessary:
ddd : ccc
| ha:ATOM ":" SPACE eee SPACE ; // Rule 1
But I see ambiguity arises and finally you may need to change the
'aaa' and 'bbb' rules:
aaa : "AAAA" SPACE bbb ;
bbb : ( ddd )+ ccc ;
ddd : ha:ATOM ":" SPACE eee SPACE ; // Rule 1
eee : hva:ATOM (":" hvap:ATOM)* ;
ccc : "XXX" ":" SPACE ((cccentry)+ ; // Rule 2
The above given the 'ATOM' lexer rule tests for literals.
[1] http://www.antlr.org/doc/metalang.html#SyntacticPredicates
--
Stanimir
More information about the antlr-interest
mailing list