0

I'm constructing an English-like domain specific language with ANTLR. Its keywords are context-sensitive. (I know it sounds dirty, but it makes a lot of sense for the non-programmer target users.) For example, the usual logical operators such as or and not are to be treated as identifiers when surrounded in brackets, [like this and this]. My current approach looks like this:

bracketedStatement
    : '[' bracketedWord+ ']'
    ;

bracketedWord
    :   (~(']')+
    ;

This, when combined with lexical definitions such as the following:

AND: 'and' ;
OR: 'or' ;

Produces the warning"Decision can match input such as "{AND..PROCESS, RPAREN..'with'}" using multiple alternatives: 1, 2". I'm clearly creating ambiguity for ANTLR, but I don't know how to resolve it. How do I fix this?

nicael
  • 18,550
  • 13
  • 57
  • 90
Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52
  • Could you show a more complete example? In ANTLR, the order of the rules is important, and may lead to ambiguity. – Apalala Oct 18 '13 at 04:56
  • 1
    `~(']')` inside a parser rule does not do what you think it does. See: http://stackoverflow.com/questions/8284919/negating-inside-lexer-and-parser-rules – Bart Kiers Oct 18 '13 at 05:41
  • Possible duplicate of [Negating inside lexer- and parser rules](https://stackoverflow.com/questions/8284919/negating-inside-lexer-and-parser-rules) – Mark Rotteveel Dec 01 '18 at 13:57

1 Answers1

0

For anyone who finds this, check out this stack overflow question. It clarifies how to use the negation symbol correctly.

Community
  • 1
  • 1
Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52