Hi,
That invalids should be valids, as atom.
antlr do some greedy at k*.
As you are in AST, maybe you want employ gunit to test AST output.
Regards.
2008/9/20 jack zhang <[EMAIL PROTECTED]>:
> Thanks. Now the warnings are cleared. The only issue I had is that for the
> following invalid inputs, it won't report error. Here is the grammar.
> 1) AND
> 2) OR
> 3) AND a
> 4) OR a
>
> ----------------------- CUT -------------------
> grammar Query;
>
> //=== Parser Option ===//
> options {
> output = AST;
> k=*;
> }
>
>
>
>
> //=== Lexer ===//
>
> LEFT_PAREN: '(';
> NOT: 'NOT';
> AND: 'AND';
> OR: 'OR';
> WORD: ('a'..'z' | 'A'..'Z' | '.' | ',' | '0'..'9')+ | '"'.+'"';
> RIGHT_PAREN: ')';
> WHITESPACE: (' ' | '\t' | '\r' | '\n') { $channel = HIDDEN; } ;
>
>
>
> //=== Parser ===//
> expr: orexpression*;
>
> orexpression
> : andexpression (OR andexpression)*
> ;
>
> andexpression
> : notexpression (AND notexpression)*
> ;
>
> notexpression
> : (NOT)? atom
>
> ;
>
> atom
> : WORD+
> | LEFT_PAREN! expr RIGHT_PAREN!
> ;
>
>
> --------------------------------------
>
>
>
>
>
>
>
>
> Thanks !
>
>
> --- On Fri, 9/19/08, Markus <[EMAIL PROTECTED]> wrote:
>
> From: Markus <[EMAIL PROTECTED]>
> Subject: Re: [antlr-interest] Alternative(s) 2 were disabled for that input
> To: [EMAIL PROTECTED]
> Date: Friday, September 19, 2008, 4:49 AM
>
> ----------------------- CUT -------------------
>>
>> //=== 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 <[EMAIL PROTECTED]> wrote:
>> From: jack zhang <[EMAIL PROTECTED]>
>> Subject: Alternative(s) 2 were disabled for that input
>> To: [EMAIL PROTECTED]
>> 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
>>
> ------------------------- CUT --------------------
> The parser complains because it can match a OR b OR c in two ways, one by
> using the kleene star * in or_expression twice and so matching two ORs with
> their corresponding expressions reduced to atoms, and the other one by using
> the kleene star * in or_expression once, and matching b OR c with another
> or_expression. You want to change or_expression (and similar and_expression)
> to
> or_expression
> : and_expression (OR and_expression)*
> ;
> so it always has to match the kleene star * twice and the parser won't
> complain about this anymore. I know the
> error messages can be sometimes quite
> confusing, and the best way to deal with this is to make a copy of your
> grammar and remove one rule at a time to see which one really causes the
> error. Then at least you know which rule to fix.
>
> Markus
>
>
> List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
>
>
>
>
> List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
>
>
>
--
致敬
向雅
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---