- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# What are Precedence Relations in Operator Grammar?

For terminals a and b in an Operator Grammar we can have the following precedence Relations −

**a =. b(Equal Precedence)**− If R.H.S of production is of form α a β b γ, where β can be ε or single non-terminal then a =. b.

Here, α and γ can be any strings.

**Example** − In grammar, S → m A c B e d

On Comparing mAcBed with αaβbγ

α = mA, a = c, β = B, b = e, γ = d

Α | A | β | b | γ |

mA | C | B | e | d |

So, comparing a with c and b with e we get c =.e.

We can also make a different combination for a and b.

In Grammar S → m A c Bed

α = ε, a = m, β = A, b = c, γ = Bed

Α | A | β | b | γ |

Ε | M | A | c | Bed |

So, comparing a with m and b with c

∴ m =. c

**a<.b (Less then)**

If R.H.S of production is of form α a A β and A ⟹+ γb$ where γ is ε or single nonterminal then a <.b.

**Example** − In Grammar S → m A c D

A → i

On comparing m A c D with α a A β and A → i with A → γb$

Α | A | A | β |

Ε | M | A | cD |

A → | Γ | b | $ |

A → | E | i | ε |

∴ α = ε, a = m, A = A, β = cD

∴ γ = ε,

and b = i

∴ Applying the rule,

a <. b means m <. i

**a .> b (Greater Than)**

If R.H.S of production is of form αAbβ and A ⟹+ γa$ where $ is ε or single nonterminal then a .> b.

**Example** − In Grammar S → m A c D

A → i

On comparing m A cD with α a bβ and A → i with A → γa$

Α | A | b | β |

M | A | c | D |

Α → | Γ | a | $ |

Α → | E | i | ε |

∴ α = m, A = A, b = c, β = D

On comparing i with γa $

∴ γ = ε, a = i, $ = ε

∴ On applying the rule,

a .> b means i .> c.

The Precedence relations between terminals symbols can also be shown by a Parse Tree −

**Algorithm for Computing Operator Precedence Relations**

**Input** − An Operator Grammar

**Output** − A Precedence Relations between terminals and symbols.

**Method**

**begin**- For each production A → B
_{1}, B_{2}, … … … . B_{n}

for i = 1 to n – 1

If B_{i} and B_{i+1} are both terminals then

set B_{i} = B_{i+1}

If i ≤ n − 2 and B_{i} and B_{i+2}are both terminals and B_{i+1} is non-terminal then

set B_{i} = B_{i+2}

If B_{i}is terminal & B_{i+1}is non-terminal then for all a in LEADING (B_{i+1})

set B_{i} <. a

If B_{i}is non-terminal & B_{i+1} is terminal then for all a in TRAILING (B_{i})

set a . > B_{i+1}

- end

- Related Articles
- What are LEADING and TRAILING operation of an operator precedence grammar?
- Explain Operator grammar and precedence parser in TOC
- What is Operator Precedence Parsing?
- What is the operator precedence in C#?
- PHP Operator Precedence
- According to Java Operator precedence, which operator has the highest precedence?
- What is C Operator Precedence and Associativity?
- What is Operator Precedence Parsing Algorithm in compiler design?
- Operator Precedence and Associativity in C
- Can we change operator precedence in Python?
- Evaluating a mathematical expression considering Operator Precedence in JavaScript
- What are Precedence Functions in compiler design?
- What are clauses in English Grammar?
- How Can MySQL operator precedence affect result set?
- In MySQL, how does the precedence of ! operator in comparison with NOT operator depends upon HIGH_NOT_PRECEDENCE SQL mode?