[antlr-interest] How to skip evaluating part of a rule?

Charles Chan chancharles at gmail.com
Fri May 14 13:29:22 PDT 2010


Thanks, Marcin. I am walking thru the returned tree to do the
evaluation instead. This seems to be cleaner.

Charles


On Fri, May 14, 2010 at 3:23 PM, Marcin Rzeźnicki
<marcin.rzeznicki at gmail.com> wrote:
> On Fri, May 14, 2010 at 6:25 PM, Charles Chan <chancharles at gmail.com> wrote:
>> Hi, all. I have a parser optimization question for you guys. In my
>> grammar (below), I have to evaluate an OR condition and an AND
>> condition. We all know that "true OR true/false" is always true and
>> "false AND true/false" is always false. So, technically, if I can skip
>> evaluating RHS under those conditions.
>>
>> Is there a way for me to incorporate this kind of optimization in my
>> grammar? Currently, I am retrieving the values from a Map so that
>> performance is okay but I plan to retrieve them from DB, so any
>> optimization to skip the retrieval process would be great.
>>
>> Any idea?
>>
>
> Sync to follow set if you have simple rules, where no element of
> follow can possibly be present within the rule you're escaping from.
> In your case you can freely sync to ';' so that should solve your
> problems. In any case you can define special flag, like SKIPPING_STATE
> = 10000; - set backtracking state to this value so you know that you
> are escaping and continue with parsing, no actions will be taken so
> you should be fine with this solution to. Just remember to unset
> backtracking state on exit.
>
>
> --
> Pozdrawiam
> Marcin Rzeźnicki
>


More information about the antlr-interest mailing list