Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UP Lecture 10

UP Lecture 10

Compilers
Precedence of Operators II
(202602)

Javier Gonzalez-Sanchez PRO

December 13, 2023

Transcript

25 slides
  1. Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs Layering Rule

    1 Rule 2 Rule 3 Rule 4 Rule 5 . . . . . Leaf (Terminals, i.e., Tokens) Root Start symbol Layers
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs Conclusion 2.

    Create New Rules to Establish Levels of Precedence for Operators
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs Layering 1

    2 4 5 3 inputs: ▪ 1 + 2 + 3 < 4 * 5 ▪ 1 * 2 + 3 + 4 < 5 ▪ 1 < 2 + 3 + 4 * 5 ▪ 1 + 2 < 3 * 4 + 5 ▪ 1 + 2 * 3 < 4 + 5 1 * 2 < 3 + 4 * 5
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 8 jgs Exercise 2

    Include rules for handling parenthesis into the previous grammar. The grammar should accept as correct the following expressions: 10 * 20 + 15 (10 * 20) + 15 10 * (20 + 15) (10) * (20) + (15) (10 * 20 + 15) 10 * (20) + 15
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs Exercise 3

    Include rules to accept variables names (identifiers) in expressions. The grammar should accept as correct the following expressions: A * 20 + time (x * y) + 15 10 * (ASU + cse340) (10) * (20) + (15) (hello * world + Arizona) 10 * (counter) + 15
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 17 jgs Exercise 4

    Provide a Grammar with Precedence of operators and Associativity for this: 10 + 20 > 15 & -10 != 1 | 20 / ( 10 + 1) < 5
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs Precedence Precedence

    of operators | & ! < > == != <= >= + - * / - ( )
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 23 jgs Practice ((3

    + 5) * 2 > 10) && (8 / (4 + 1) == 1 || 7 - 3 < 2)
  9. jgs Compilers Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2026 Copyright. These

    slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming