Site icon i2tutorials

Compiler Design-Operator precedence parsing

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:

 

Operator Precedence is only present or can be created between two terminals and the non-terminals are ignore.

 

Operator Precedence Relations:

 

  1.  a<b: Meaning, terminal b has higher precedence than terminal a.
  2.  a>b: Meaning, terminal a has higher precedence than terminal b.
  3. a=b: Meaning, Both terminals have equal precedence.

 

Precedence Table: 

+*()id$
+
*
(XX
)XX
idXX
$XX

Parsing Action:

  1. Add $ Symbol at both ends of the given input String.
  2. Until encountered with scan the input string from left to right.
  3. Scan the leftover equal precedence to the first ⋖ is encountered.
  4. Everything from leftmost to the rightmost handle.

 

 

Reference Link

Operator precedence parsing

Exit mobile version