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

UP Lecture 09

UP Lecture 09

Compilers
Grammar III
(202402)

Javier Gonzalez-Sanchez

December 12, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  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 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
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 6 jgs Exercise 1

    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
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs Exercise 2

    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
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 16 jgs Exercise 3

    Provide a Grammar that is Not ambiguous with Precedence of operators and Associativity for this: 10 + 20 > 15 & -10 != 1 | 20 / ( 10 + 1) < 5
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 17 jgs Exercise 3

    | Note Precedence of operators | & ! < > == != <= >= + - * / - ( )
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 21 jgs Parser |

    Input and Output { 0; 1 + 2; 3 * (4 + hello); }
  8. jgs Compilers Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2024 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.