Search code examples
compiler-construction

What is the difference between operator grammar and operator precedence grammar? Explain with examples too


What is the difference between operator grammar and operator precedence grammar? Explain with examples too. I am preparing for exam and I am not able to find it.


Solution

  • Operator Grammar : A grammar that is generated to define the mathematical operators or identifier is called operator grammar with some restrictions on grammar.

    example: E->E+E/E*E/id

    where as; An operator precedence grammar is a context-free grammar that has the property that no production has either an empty right-hand side (null productions) or two adjacent non-terminals in its right-hand side. example:

    S->SAS/a
    A->bSb/b 
    

    Although, we can convert it into an operator grammar:

    S->SbSbS/SbS/a
    A->bSb/b  
    

    hope it would help you..for further learning purpose you can check out this

    https://www.geeksforgeeks.org/theory-computation-operator-grammar-precedence-parser/