You have to be careful how you implement your grammar rules such that you can 
recover sensibly from errors. Generally you build a tree or partial tree then 
analyze that. You may also need to specifically code for some potential missing 
elements, but again you have to be careful not to introduce ambiguities that 
break the normal grammar.

For hints on how to code rules that recover well from errors (especially in 
loops), see:

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

Jim

> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Andreas Heck
> Sent: Friday, May 14, 2010 6:59 AM
> To: [email protected]
> Subject: [antlr-interest] Parsing erroneous input
> 
> Hello everybody,
> 
> I have a parser based on the C target that I want to use to check for
> correct syntax in one program but I also want to use it to parse
> erroneous input to do autocompletion in another program.
> 
> If I just parse some input where a semicolon is missing on one line the
> parser recovers since the following statements are transformed into
> correct AST nodes but the code from the line which caused the error
> gets
> represented by two "Tree Node Error" nodes in the AST.
> 
> Unfortunately you can't count on perfectly valid input if you want to
> provide some form of autocompletion.
> 
> What is the best approach to parse erroneous input? Do I have to create
> a second grammar that also accepts input with common errors like a
> missing semicolon?
> 
> Or is there a better way where I can just use the parser which only
> accepts correct input? Maybe I could somehow get the code line which
> caused the error and use handwritten code for common error cases to
> extract the information I need? Or maybe there is a way to get the raw
> tokens that caused the problem from antlr or make it put the best
> partial derivation it can create into the AST?
> 
> Are there any other approaches?
> 
> 
> Best regards,
> 
> Andreas
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address




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