Operator precedence parsing
Operator Precedence Parsing is applied to a small class of operators. It is similar to the shift-reduce Parsing method.
It is said to be Operator Precedence parsing when it has the following two properties:
- R.H.S of any production a∊
- Two non-terminals should not be adjacent to each other.
Operator Precedence is only present or can be created between two terminals and the non-terminals are ignore.
Operator Precedence Relations:
- a<b: Meaning, terminal b has higher precedence than terminal a.
- a>b: Meaning, terminal a has higher precedence than terminal b.
- a=b: Meaning, Both terminals have equal precedence.
Precedence Table:
| + | * | ( | ) | id | $ | |
| + | ⋗ | ⋖ | ⋖ | ⋗ | ⋖ | ⋗ |
| * | ⋗ | ⋗ | ⋖ | ⋗ | ⋖ | ⋗ |
| ( | ⋖ | ⋖ | ⋖ | X | ⋖ | X |
| ) | ⋗ | ⋗ | X | ⋗ | X | ⋗ |
| id | ⋗ | ⋗ | X | ⋗ | X | ⋗ |
| $ | ⋖ | ⋖ | ⋖ | X | ⋖ | X |
Parsing Action:
- Add $ Symbol at both ends of the given input String.
- Until encountered with ⋗ scan the input string from left to right.
- Scan the leftover equal precedence to the first ⋖ is encountered.
- Everything from leftmost ⋖ to the rightmost ⋗ handle.
Reference Link
