[antlr-interest] Advice on best practice?

Jim Idle jimi at temporal-wave.com
Wed Oct 12 11:15:42 PDT 2011


Avoid backtracking like the plague if you need performance. But if you are
careful in the order of your alts and use it on just a few
decisions/rules, then it might not be so bad (but remember that your error
messages will be weak).

If k=1 on a decision then ANTLR will work that out so you don't need to
specify but if you want to avoid ANTLR following every possible alt then
you can use k=1 on a particular rule or sub rule to avoid ambiguity
errors. Basically if you know that a decision will be correct at k=1 even
though ANTLR can see ambiguities, then tell it so. Before 3.4 this would
still give a warning unless you added a 1 token predicate, but I believe
that Ter changed this for 3.4 so that I could remove a lot of those
predicates from my own T-SQL grammar.

Jim



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ruslan Zasukhin
> Sent: Wednesday, October 12, 2011 11:05 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Advice on best practice?
>
> Hi All, Terrence, Jim,
>
> I have review FAQs, other docs and list ...
> But sop far cannot find isolated advices/tips of kind
>
>
> * Tend develop grammar as k=1
>    AVOID to use k=*, because this is slower ...
>
> OR reverse
>
> * No problems to use k=*
>  Always prefer to use k=*  and do not worry ... Speed will be fine..
>
> OR
>
> * always tend to (not)? Use  backtrack option.
>     and if you use it then use memoize also ...
>
>
> In the ANTLR3/Examples/C  I see options as
>
>
> ====================
> grammar C;
>
> options
> {
>     backtrack    = true;
>     memoize    = true;
>     k        = 2;
>     language    = C;
> }
> ====================
>
>
> But what is official point of view at current state ?
>
>
>
> --
> Best regards,
>
> Ruslan Zasukhin
> VP Engineering and New Technology
> Paradigma Software, Inc
>
> Valentina - Joining Worlds of Information
> http://www.paradigmasoft.com
>
> [I feel the need: the need for speed]
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list