Error Recovery: LR parsing
Again Error Recovery: LR parsing is the topic of freestudy9. Additionally, we had tried to make it easy for a point to point information as possible as well.
- An LR parser will detect an error when it consults the parsing error entry.
- Consider the grammar, E-> E+E | E*E | (E) | id
- Parsing table given below shows error detection and recovery.
The error routines are as follow:
- E1: push an imaginary id onto the stack and cover it with state 3. Issue diagnostics “missing operands”. This routine called from states 0, 2, 4 and 5, all of which expect the beginning of an operand, either an id or left parenthesis. Instead, an operator + or *, or the end of the input found.
- E2: remove the right parenthesis from the input. Issue diagnostics “unbalanced parenthesis right parenthesis This routine is called from states 0, 1, 2, 4, 5 on finding right parenthesis”. parenthesis.
- E3: push + onto the stack and cover it with state 4 Issue diagnostics “missing operator”. This routine is called from states 1 or 6 when expecting an operator and an id or right parenthesis is found.
- E4: push right parenthesis onto the stack and cover it with state 9. Issue diagnostics “missing right parenthesis”. This routine is called from states 6 when the end of the input is found. State 6 expects an operator or right parenthesis.
StackInputError message and action: Error Recovery: LR parsingSyntax Directed Definitions: Error Recovery: LR parsing
- The syntax directed definition is a generalization of context-free grammar in which each grammar symbol has an associated set of attributes.
- Types of attributes in Error Recovery: LR parsing,
1. Synthesized attribute
2. Inherited attribute
- Difference between synthesized and inherited attribute,
NoSynthesized Attribute and Inherited attribute
1 Value of synthesized attribute at a Values of the inherited attribute at a node can compute the value of attributes at the children of that of an attribute at the parent and/or node in the parse tree.siblings of the node.
2 Pass the information from bottom to Pass the information top to bottom on top in the parse tree.the parse tree or from left siblings to the right siblings