[antlr-interest] How do I find what Antlr is really telling me?

Jim Idle jimi at temporal-wave.com
Wed Jan 12 09:30:16 PST 2011


I think that you might be better not using a grammar construct if the
consume is always at the trailing end of the verb (but remember that not
all SQL requires termination with ';' which makes it a terrible language
to parser in general.)

You can insert an action, or a dummy rule that uses code to consume until
the SEMI token is discovered. You can adopt the code from this article:

http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery


But basically all you need (for Java) is:

select_statement : SELECT swallow_to_semi;

swallow_to_semi:
@init
{
	while (input.LA(1) != SEMI) { input.consume(); }
}
: ;

The problem with your other rule is that ANTLR is trying to work out
lookahead and so on. You might try the k=1 option on that individual rule,
but the code above is neater I think and will not give warnings because of
it. You might find though, that having this empty rule results in overall
ambiguities that have to be solved with k=1 and/or predicates.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Alan Lehotsky
> Sent: Tuesday, January 11, 2011 2:19 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] How do I find what Antlr is really telling
> me?
>
> I've massaged the PLSQL.g grammar which has a number of rules of the
> form:
>
> select_statement :  SELECT swallow_to_semi;
>
> update_statement : UPDATE swallow_to_semi;
>
> ...
>
> swallow_to_semi :  ~( SEMI )+
>
>
> These all seem to do the right thing, but I get a warning from Antlr
> that says
>
> warning(200): plsql.g:815:39; Decision can match input such as
> "{BLOCK..DIVIDE, OR..END, BODY..RETURN, TEMPORARY..INOUT_,
> TRANSACTION..VERTBAR}" using multiple alternatives: 1, 2 As a result,
> alternative(s) 2 were disabled for that input
>
>
> But line 815 is in fact the swallow_to_semi rule, so it must have
> subsumed this rule into some other rule with multiple selections.
>
>
>
> NOTICE  from Ab Initio: If received in error, please destroy and notify
> sender, and make no further use, disclosure, or distribution. This
> email (including attachments) may contain information subject to
> confidentiality obligations, and sender does not waive confidentiality
> or privilege.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list