[antlr-interest] Difficult to explain prediction error

Burton Samograd burton.samograd at markit.com
Thu Aug 16 09:49:55 PDT 2012


Re-sending in case this question was missed.  Any feedback or help appreciated.

--
Burton Samograd

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Burton Samograd
Sent: Tuesday, August 14, 2012 12:48 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Difficult to explain prediction error

Hello,

I have the following rule in my tree walker:

filter
        : ( return_type[...] selection_logic[...] )* { return_type | { /* handle nothing */ } )

which causes no warnings or errors from the Antlr compiler.  It seems to be working well but in one case where I have a certain return_type.  return_type is a selection of rules similar to the following in the grammar:

return_type: (return_a|return_b|return_c|return_d) ;

return_a : RETURNA ;

return_b : RETURNB ;

return_c : RETURNC ( LPAREN float RPAREN )? -> ^(RETURNC float?)

return_d : RETURND ( LPAREN float COMMA float RPAREN )? -> ^(RETURNC float+)

return_c and return_d are tokens with optional parameters after them.

The problem is when I try a single return_c without the parameters.  A single return_d without parameters does not have a problem.

I've single stepped into the generated Antlr tree walker and have found that it is throwing an exception and giving the following error
message:

-unknown source-(0)  : error 3 : ()* loopback of 520:7: ( return_type[...] selection_logic[...] )*, at offset 0, near UP :
cannot match to any predicted input...

This is caused by an exception that is generated when stepping over a function called cdfa37.predict.

I'm having problems understanding why this exception is being generated because the * after the rule in the above error message should cause the rule to be skipped and move onto the next one, which is a single (optional) return_type.

And like I said, this rule passes pretty much all of the test cases except for one that I have found. Can anybody shed some light on why my grammar is behaving this way?

--
Burton Samograd

________________________________
This e-mail, including accompanying communications and attachments, is strictly confidential and only for the intended recipient. Any retention, use or disclosure not expressly authorised by Markit is prohibited. This email is subject to all waivers and other terms at the following link: http://www.markit.com/en/about/legal/email-disclaimer.page

Please visit http://www.markit.com/en/about/contact/contact-us.page? for contact information on our offices worldwide.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address

This e-mail, including accompanying communications and attachments, is strictly confidential and only for the intended recipient. Any retention, use or disclosure not expressly authorised by Markit is prohibited. This email is subject to all waivers and other terms at the following link: http://www.markit.com/en/about/legal/email-disclaimer.page

Please visit http://www.markit.com/en/about/contact/contact-us.page? for contact information on our offices worldwide.


More information about the antlr-interest mailing list