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

UP Lecture 11

UP Lecture 11

Compilers
Connecting the Dots
(202503)

Javier Gonzalez-Sanchez

December 14, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs Do not

    Forget ▪ Terminals: Represented in lowercase, enclosed in single or double quotes, or depicted as ovals in diagrams. ▪ Non-Terminals: Represented with an uppercase initial letter, enclosed in angle brackets (< >), or depicted as rectangles in diagrams.
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 8 jgs Case Study

    | English Grammar ▪ I work. ▪ She eats. ▪ They study. ▪ He does not like coffee. ▪ We don't go to school on Sundays. ▪ <statement> ::= <subject> <verb> <object>? | <negative-statement> ▪ <negative-statement> ::= <subject> <auxiliary> "not" <verb> <object>? ▪ <subject> ::= "I" | "you" | "he" | "she" | "it" | "we" | "they" ▪ <verb> ::= "work" | "eat" | "like" | "study" | "go" | ... ▪ <object> ::= "coffee" | "school" | "homework" | ... ▪ <auxiliary> ::= "do" | "does"
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 10 jgs Case Study

    | English Grammar ▪ Do you work? ▪ Does she like coffee? ▪ Where do they study? ▪ What does he eat? ▪ <question> ::= <yes-no-question> | <wh-question> ▪ <yes-no-question> ::= <auxiliary> <subject> <verb> <object> "?" ▪ <wh-question> ::= <wh-word> <auxiliary> <subject> <verb> <object> "?" ▪ <wh-word> ::= "what" | "where" | "when" | "why" | "who" | "how" ▪ <auxiliary> ::= "do" | "does"
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 12 jgs Test Yourselves

    ▪ Create syntax diagrams for the BNF/EBNF rules on slides 8 and 10. ▪ Create derivation trees for the inputs shown at the top of slides 8 and 10.
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs Case Study

    | A Grammar for JSON { "name": "Alice", "age": 30, "address": { "city": "New York", "zip": "10001" }, "phones": ["+1-800-555-1234", "+1-800-555-5678"] }
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 15 jgs Case Study

    | A Grammar for JSON Object Pair Array Value
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 16 jgs Case Study

    | A Grammar for JSON ▪ Object ::= "{" Pair ("," Pair )* "}" ▪ Pair ::= String ":" Value ▪ Value ::= String | Number | "true" | "false" | "null" | Object | Array ▪ Array ::= "[" Value ("," Value )* "]" ▪ String ::= "string" ▪ Number ::= "integer"
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs Case Study

    | A Grammar for JSON {"name":false, "age" :100 }
  9. Dr. Javier Gonzalez-Sanchez | Compilers | 19 jgs Case Study

    | A Grammar for JSON {"name":false, "age" :100, "grades”:[1,2,3] }
  10. Dr. Javier Gonzalez-Sanchez | Compilers | 20 jgs Case Study

    | A Grammar for JSON {"name":false, "age" :100, "grades":{ "labs":[1,2,3] } }
  11. Dr. Javier Gonzalez-Sanchez | Compilers | 21 jgs Test Yourselves

    ▪ Create derivation trees for the inputs shown on slides 17 to 20, even though we have already completed some of them. Try to build them from scratch on your own.
  12. Dr. Javier Gonzalez-Sanchez | Compilers | 22 jgs Homework Syntax

    Diagrams for Java: - Class - Attributes - Methods - Parameters - Instruction (stop here) Do not forget static, final, public, private, data-types, abstract, extends, implements …
  13. jgs Compilers Javier Gonzalez-Sanchez, Ph.D. jgonzalezs@up.edu.mx Spring 2025 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.