Operator Precedence Grammar and Parser

Definitions

Expressions could be written in an unambiguous, fully parenthesized form. However, this is less convenient for the programmer.

Precedence numbers

Precedence specifies which operations in a flat expression are to be performed first.
Usually,

  • .
  • ^
  • unary -
  • * /
    • -
  • = <> >= > <= <
  • not
  • and
  • or
  • :=
Associativity

Associativity specifies which operations are to be performed first when adjacent operators have the same precedence.

How operator precedence parser works(give example)

Shift & Reduce

  • Operands
  • Operator
  • (
  • )
  • End

Citation:

  • Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools
  • UT Austin CS375: Compilers by G.Novak.