On 09/24/2009 10:56 PM, Heiko Folkerts wrote:
> Hi Indhu and David,
> OK, maybe indhu is right and modifying the token creation is the wrong way to 
> solve my error handling problems. When I try to retrieve user friendly error 
> messages from wrong input the recognizer state gives me nothing to help me. 
> The backtracking tries all paths and returns a no viable path exception. E.g. 
> this is an excerpt from the grammar:
> statement:
>      actionexpression
>      | statecheck;
> statecheck: stateobject (stateoption  | ) compoperator selectedstate  ->  
> ^(STATECHECK stateobject ^(COMPERATOR compoperator) selectedstate 
> stateoption) |
>      stateobject (stateoption  | ) compoperator paramname->  ^(STATECHECK 
> stateobject ^(COMPERATOR compoperator) ^(PARAMREF paramname) stateoption);
> actionexpression: actionobject (actionoption | ) action ->  
> ^(ACTIONEXPRESSION actionobject action actionoption);
>
> The stateobject rules etc. use syntactic predicates to check wether the input 
> is a correct keyword - thant engine is an legal object.
>
> Now if I enter the input "engine;" where engine is an object (stateobject and 
> actionobject have the same meaning) I need to tell the user that we expect 
> either an actionexpression or an statecheck instead of the ';'.
>
> I am coding in C so until ANTLR 3.2 the catch block in the grammar was not 
> supported.
>
> So how would i deal best in such situations?
>
> Thx
>    
This is a side effect of using global backtracking. You won;t be able to 
deal with it effectively unless you left factor your grammar and get rid 
of the backtracking. You should think of backtracking as something to 
use when the input is pretty much guaranteed to be correct and the 
language seems too difficult to parse otherwise. I have only found 
VBScript to be such a language myself as it is interpreted and very 
ambiguous without runtime context.

Jim

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/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
-~----------~----~----~----~------~----~------~--~---

Reply via email to