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

UP Lecture 07

UP Lecture 07

Compilers
Grammar I
(202402)

Javier Gonzalez-Sanchez

December 10, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs High-Level Languages

    X,E,G,O,O #e1,I,I,0,7 @ OPR 19, AX STO x, AX LIT 5, AX OPR 21, AX LOD #e1,AX CAL 1, AX OPR 0, AX 5 Virtual Machine (interpreter) // sorce code int x; int foo () { read (x); print (5); } main () { foo (); } Lexer Parser Semantic Analyzer Code Generation 01001010101000010 01010100101010010 10100100000011011 11010010110101111 00010010101010010 10101001010101011 Assembler compilation execution
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 15 jgs Outline Language

    Lexical Analysis (Lexer) Rules Symbols Token Tools Regular Expression DFA Syntactic Analysis (Parser) Grammar (Rules) Terminal Non-terminal Tools BNF (Backus-Naur Form) Syntax Diagrams
  3. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 16 5 /

    20 integer operator integer Grammar | Derivation LINE 5 / 20
  4. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 17 - 5

    - - 20 operator integer operator operator integer Grammar | Derivation LINE something - 5 - something - 20
  5. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 18 5 *

    ( 7 + 20 ) Integer operator delimiter integer operator integer delimiter Grammar | Derivation LINE 5 * something ( something 7 + 20 )
  6. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 19 Grammar |

    Derivation LINE Keyword (type) ID ( something Keyword (type) ID ) { something . . . . } Word token void keyword m ID ( delimiter int keyword X ID ) delimiter { delimiter . . . . . . . . } delimiter
  7. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 21 5 /

    20 integer operator integer E ⇒ E OP E ⇒ integer OP E ⇒ integer / E ⇒ integer / integer Grammar | Derivation Derivation Tree Grammar 01
  8. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 22 Grammar |

    Derivation Derivation Tree Grammar 01 5 * ( 7 + 20 ) Integer operator delimiter integer operator integer delimiter E ⇒ E OP E ⇒ integer OP E ⇒ integer * E ⇒ integer * (E) ⇒ integer * (E OP E) ⇒ integer * (integer OP E) ⇒ integer * (integer + E) ⇒ integer * (integer + integer)
  9. 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.