[antlr-interest] Alternative(s) 2 were disabled for that input
jack zhang
jackgzhang2 at yahoo.com
Thu Sep 18 16:47:51 PDT 2008
Sorry I forget to attach the grammer. Here it is
grammar Query;
//=== Parser Option ===//
options {
output = AST;
k=*;
}
//=== Lexer ===//
OR: 'OR';
AND: 'AND';
NOT: 'NOT';
WORD: ('a'..'z' | 'A'..'Z' | '.' | ',' | '0'..'9')+ | '"'.+'"';
LEFT_PAREN: '(';
RIGHT_PAREN: ')';
WHITESPACE: (' ' | '\t' | '\r' | '\n') { $channel = HIDDEN; } ;
//=== Parser ===//
expr: orexpression*;
orexpression
: andexpression (OR orexpression)*
;
andexpression
: notexpression (AND andexpression)*
;
notexpression
: (NOT)? atom
;
atom
: WORD+
| LEFT_PAREN! expr RIGHT_PAREN!
;
--- On Thu, 9/18/08, jack zhang <jackgzhang2 at yahoo.com> wrote:
From: jack zhang <jackgzhang2 at yahoo.com>
Subject: Alternative(s) 2 were disabled for that input
To: antlr-interest at antlr.org
Date: Thursday, September 18, 2008, 4:46 PM
Hi,
I keep getting following errors:
warning(138): Query.g:0:0: grammar Query: no start rule (no rule can obviously be followed by EOF)
warning(200): Query.g:27:40: Decision can match input such as "OR" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): Query.g:31:39: Decision can match input such as "AND" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): Query.g:39:7: Decision can match input such as "WORD" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
I kind of understand why because if the input is "OR" the parser will just freak out. What I want do is a simple boolean query input validator
(1) valid input:
a OR b
c AND d
a OR b AND
d
(2) invalid input:
a AND
AND b (This is not working)
What's wrong with the grammer? I really cannot figure it out.
Thanks !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080918/580e149d/attachment.html
More information about the antlr-interest
mailing list