πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

Operator precedence parsing

Operator precedence parsing

Operator precedence grammar is kinds of shift reduce parsing method. It is applied to a small class of operator grammars.

A grammar is said to be operator precedence grammar if it has two properties:

  • No R.H.S. of any production has a∈.
  • No two non-terminals are adjacent.

Operator precedence can only established between the terminals of the grammar. It ignores the non-terminal.

There are the three operator precedence relations:

a β‹— b means that terminal "a" has the higher precedence than terminal "b".

a β‹– b means that terminal "a" has the lower precedence than terminal "b".

a ≐ b means that the terminal "a" and "b" both have same precedence.

Precedence table:

Operator precedence parsing 3

Parsing Action

  • Both end of the given input string, add the $ symbol.
  • Now scan the input string from left right until the β‹— is encountered.
  • Scan towards left over all the equal precedence until the first left most β‹– is encountered.
  • Everything between left most β‹– and right most β‹— is a handle.
  • $ on $ means parsing is successful.

Example

Grammar:

E β†’ E+T/T  
T β†’ T*F/F  
F β†’ id

Given string:

w = id + id * id 

Let us consider a parse tree for it as follows:

Operator precedence parsing 6

On the basis of above tree, we can design following operator precedence table:

Operator precedence parsing 7

Now let us process the string with the help of the above precedence table:

Operator precedence parsing 8

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>