[antlr-interest] Fragment for Parserrules

Alexander Gängel alexander at gaengel.de
Thu Jan 11 03:01:41 PST 2007

Here is a small Grammar to show my Problem:

    grammar small;
    start    :(Identifier |    '->' keyword    )+;
    Identifier:('a'..'z'|'A'..'Z'|'_') (Letter)*;
    Letter    :'a'..'z'|'A'..'Z'|'0'..'9'|'_'|'$';
    WS    :(' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;};

for this Grammar input like this is true:

word word -> test word -> test2

but I would like that if the Input is just test it would also be true
but then be identified as an Identifier not a keyword.

ok in this example I could put my keyword also into the start rule but
in actual grammar I'm working on I would use it with a lot of keyword
(about 20) inside  a Syntactic Predicates so I would prefer to make the
rule keyword a fragment so it#s just recognized inside the start rule
when a -> is found.

Ok I hope you now understand what I want.

maybe there is a better way to do such a thing with Antlr I just don't
know about it.


Kay Roepke schrieb:
> On 10. Jan 2007, at 12:27 , Alexander Gängel wrote:
>> I have some parserrule which should only be applied at special points,
>> the problem why I can't inline it because I use in an Syntactic
>> Predicate.
>> or is there some better way I just don't see
> could you post some sample code/grammar?
> I can't really see what you want to do here, that's easier to discuss
> if we have some sample stuff to
> talk about ;)
> cheers,
> -k
> --Kay Röpke
> http://classdump.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070111/1ee05355/attachment.html 

More information about the antlr-interest mailing list