[antlr-interest] Disregarding subrule ordering

Royne Borrud royne.borrud at gmail.com
Fri Dec 2 04:08:08 PST 2005


Thanks for the suggestions. I'm new to ANLR in general and treeparsers
in particular, so I'll have to look into that a bit further I guess.
Is there some rule-of-thumb for when to use treeparsers? I've only
done some small grammars so far (mostly flex/bison), and haven't seen
the *need* for an extra step with a treeparser so far, though it might
simplify post-processing.

In this particular case, if I declare a number of booleans (or a
bitset) in my parser and do something like below:

object:
    KW_OBJECT
    IDENTIFIER
    LBRACE { //set all bools to false here
    (
        { !param1bool }? param1 { param1bool = true; }
        { !param2bool }? param2 { param2bool = true; }
        { !param3bool }? param3 { param3bool = true; }
        { !optParam1bool }? optParam1 { optParam1bool = true; }
        { !optParam2bool }? optParam2 { optParam2bool = true; }
    )*
    RBRACE { if(! (param1bool && param2bool && param3bool) ) throw ....)

Haven't tested this yet so it might not even work, but other than pure
design considerations; are there reasons for not doing this directly
in the parser?
I'm beginning to think I might just dodge this by enforcing strict
ordering and be done with it. Since I'm designing the grammar for my
own small script ground up I can do as I please... :) OTOH I really
like the free ordering...


More information about the antlr-interest mailing list