[antlr-interest] 'any order' operator in ANTLR?

Thomas Brandon tbrandonau at gmail.com
Wed Aug 6 07:19:49 PDT 2008


The alternate is to simply recognise (A|B|C)+ and detect duplicates in
either a code block or a subsequent analysis phase. An advantage of
this approach is you can imeadiately provide better error reporting. A
syntactic solution would likely require you to also add error handling
code to sensibly report the error to the user. And probably requires
ANTLR (or yourself) to generate correct output to allow subsequent
processing to continue. The disadvantage is the requirement of target
specific code. Though I suspect in all but the simplest real world
solution there would be many such constraints not specifiable in ANTLR
so one more makes little difference and it is in fact cleaner to.keep
them all together outside of the grammar.
It also occurs that the presence of such productions in a lexer
(assuming that was intentional) is somewhat odd and perhaps indicates
nonoptimal seperation of lexer and parser duties.

Tom.
On Wed, Aug 6, 2008 at 10:49 PM, Marc Bischof <atlan at gmx.li> wrote:
> Hello List,
>
> I question if an 'any order' operator makes sense in grammar development.
> Do you already considered this?
>
> I will explain what I mean in a short example:
>
> You want to model a rule S with 3 optional nonterminals (call them A B and C)
> where the order of occurrence is not relevant.
>
> So far without too much overhead you will model that like this (forcing a
> fixed order):
>
> S : A? B? C?
>
> To omit overhead, I think that for such cases it might be more clear to have
> an 'any order' operator (called  '~' here).
> With that operator one can say:
>
> S : (A? B? C?)~
>
> What do you think? Did I miss s.th.? Is it already possible with ANTLR?
>
> Cheers Marc
>


More information about the antlr-interest mailing list