[antlr-interest] Early exit exception in positive closures
Andreas Meyer
andreas.meyer at smartshift.de
Tue Mar 10 09:03:21 PDT 2009
Sam Harwell schrieb:
> When at all possible, avoid using semantic predicates, as they will
> greatly slow down your grammar relative to a properly left-factored
> grammar.
Hmhmh ... but as long as they are just {...}? predicates instead of the
gated semantic predicates {..}?=>, aren't they only executed when there
is an ambiguity? Or do they prevent ANTLR from generating something more
clever?
> If the negated set works, it is probably your best option for
> now. Maybe I can add a subtract set operation you can test, although I
> couldn't check it in officially since it deviates from the grammar
> language spec. Then you could write the following with no predicates (no
> predicates with short lookahead is optimal):
>
> // the keyword rule must be a set for this to work, which is "any single
> one of the following tokens"
> (identifier | keyword-(KW123|KW456))+ rule_with_keywords?
>
Something like this would be great. But. if it deviates from the ANTLR
grammar, I have another suggestion that would not violate the garmmar
language spec: would it be possible to remove KW123 and KW456
automatically, by letting ANTLR look at "rule_with_keywords"? When
setting an option { greedy=false; } ? :-) So, maybe there is a certain
token set computed, that decides if one should stay within the loop or
exit the loop. With greedy=false, the token-set could be reduced by
FIRST(rule_with_keywords) or any other rule that may follow the loop.
I also thought about something like:
id
: ID
| KW1 { avoid }
| KW2 { avoid }
| KW3 { avoid }
.
.
;
which would mean that, whenever during grammar analysis there is an
ambiguity between a token with "avoid" and the same token without avoid,
prefer the one without avoid. Does this sound reasonable? I find it
interesting :-)
> You never responded to my offer to check out making the ANTLR Tool
> faster at analyzing your grammar. 20 seconds is a long time and I'm sure
> it can be improved. :)
>
>
I really appreciate that offer and would be happy if I could help
improve ANTLR, but sending the grammar itself is not possible,
unfortunately ... is there some way you could send me a patched version
of ANTLR that produces a logfile, which I can send to you?
Greetings,
Andreas Meyer
More information about the antlr-interest
mailing list