Can a parser recovery error be automatically determined by grammar?

I am writing a LALR parser generator as a pet project.

I use the purple dragon book to help me with the design, and what I am building from it is that there are four error recovery methods in the parser:

  • Panic mode: start typing input characters until you find the character previously selected by the compiler developer.
  • Phrase level recovery: change the input string to something that allows the current production to reduce
  • Production Errors: Predict errors by including them in grammar
  • Global correction: the path to a more complex version of recovery at the phrase level (as I understand it)

Two of them require modification of the input line (which I would like to avoid), and the other two require that the compiler developer anticipate errors and design error recovery based on their knowledge of the language. But the parser also has knowledge of the language, so I'm curious if there is a better way to recover parsing errors without first selecting synchronization tokens or filling the grammar with error processes.

Instead of choosing sync tokens, can the parser simply process characters according to all non-terminals, can the current production decrease as sync tokens? I didn’t know very well how well this would work - I imagine that the parser is in the chain of progressive productions, but, of course, not how paired analyzers work from the bottom up. Will it be too many non-local errors trying to find a working state? Will it try to resume the parser in an invalid state? Is there a good way to pre-populate the analyzer table with valid error actions, so there is no need to explain the actual syntax layout where to go next when an error occurs?

+3
1

, . , , . (, , , , .)

, . (Sippu Soisalon-Soininen). ( , , ACM , , , .)

yacc " " " ". , ( ), , , ( ), . ., , Russ Cox.

+3

All Articles