Recursive Descent Parser Error Recovery
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have syntax error handling in compiler Meta Discuss the workings and policies of this site About Us Learn syntax error handling in compiler design more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Computer Science Questions Tags Users Badges Unanswered Ask Question _ Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Basic idea behind error recovery in recursive-descent parsers up vote -2 down vote favorite I see that modern SW basically dominated by recursive descent parsers. These parsers try grammar production and back track to an alternative one in case of failure. Suppose BNF is program = (declaration)* "begin" (statement)* declaration = type_declaration | variable_declaration | function_declaration type_declaration = "range" name "to" name | "enum" (name)* variable_declaration = name ":" type_name statement = ... and suppose that user has entered user entered "range 10 to '15'" when declaration expected. The parser has failed to match the first type pattern but it also failed to match other alternatives and declarations and failed to parse the program. How do you recover? Should you track the "best match", which would be location of the "range 10 to '15'" and look for keywords met afterwards or what? Which mechanisms are used in practice, in popular parser combinators and generators like JavaCC? parsers share|cite|improve this question edited Jan 13 at 12:38 vonbrand 7,95232238 asked Jan 13 at 12:15 Valentin Tihomirov 1 "I see that modern SW basically dominated by recursive descent parsers" -- really? My impre
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error reporting and recovery in parser generators up vote 1 down vote favorite I think parser generators are a pretty nice tool to have in your programming toolkit so after playing http://cs.stackexchange.com/questions/51805/basic-idea-behind-error-recovery-in-recursive-descent-parsers around with some I wrote my own just to understand things better and it turned out to be better than I expected so I've stuck with it. One thing that has been bugging me lately though is error reporting and recovery. I don't do a very good job of it. I know one method is token synchronization but the trail seems to stop there. Other than rolling your own recursive descent parser and including all sorts of heuristics http://stackoverflow.com/questions/21950661/error-reporting-and-recovery-in-parser-generators what are some general purpose ways of handling error reporting and error recovery in parser generators? parsing error-handling parser-generator error-recovery share|improve this question asked Feb 22 '14 at 6:28 davidk01 1,97363157 What type of parser generator did you write? –Apalala Feb 22 '14 at 17:44 @Apalala: PEG with some bits of OMeta for semantic actions and predicates. –davidk01 Feb 22 '14 at 21:52 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote With PEG, which is top-down, you can implement the "cut" feature, either automatically, or for manual inclusion, so you can report errors as close to their source as possible. See Grako and the referenced article by Kota Mizushima. A "cut" invalidates alternatives after certain tokens are seen on the input, so the parser can know how to fail early. In general, I don't like error recovery as the errors reported after the first tend to be nuisance, as Turbo Pascal once proved. The general strategy for recovery is to perform rewrites, inserts or deletes, on the input sequence so the parser can continue. For a simple recovery strategy based solely on deletes (skipping input until an expected token), see section 5.9 of Wirth's A+D=P. share|improve this answer edited Feb 24 '14 at 14:17 answered Feb 23 '14 at 19:06 Apalala 4,59321434 1 I have implemented cuts. They are indeed pretty handy. &n
we can not allow these types of requests to continue. The restriction will syntax error handling be removed automatically once this activity stops. We apologize for this inconvenience. Please contact us with any questions or concerns regarding this matter: portal-feedback@hq.acm.org The ACM Digital Library is published by the Association for Computing Machinery. Copyright © 2010 ACM, Inc. Terms of Usage Privacy Policy Code of Ethics Contact Us