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

UP Lecture 06

UP Lecture 06

Compilers
Syntaxis
(202402)

Javier Gonzalez-Sanchez

December 09, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs Review |

    Lexical Analysis Are the following STRINGS correct or not? Why? § 000000005 § 000000009 § 000000009.1 § 000000005 § 000000005.1 § 0x0000002 § 0123456789
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs Review |

    Lexical Analysis Are the following STRINGS correct or not? Why? § 1.2e---3++ § $50 § float ________________ = 5; § double x = 000000.1; § '''a' § '\''b' § '\'b'
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs Review |

    Lexical Analysis Are the following STRINGS correct or not? Why? § " \\\\\\\\\\a" § "Hello""world" § abc"Hello" § ''’ § '\x’ § ’\a' § ’\w’ § "\\\"
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 6 jgs Question For

    each cases indicate whether it is possible or not to generate a regular expression or a DFA. i. Detect the balance of N parenthesis in a string that has N parenthesis nested and any characters in between the parenthesis. ii. Is it possible to detect binary strings with the same quantity of 0’s and 1’s (it does not matter the order or sequence).
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 7 jgs Next Step

    þ Lexical Analysis ☐ Syntactic Analysis
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 8 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
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 9 jgs Where are

    we now? After lexical analysis, we have a series of tokens. But we can not: I. define a regular expression matching all expressions with properly balanced parentheses. II. i.e., define a regular expression matching all functions with properly nested block structure. void a () { b (c); for (;;) {a=(-(1+2)+5); } }
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 10 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
  9. Dr. Javier Gonzalez-Sanchez | Compilers | 11 jgs Where are

    we now? Now, we want to: I. Review the structure described by that series of tokens II. Report errors if those tokens do not properly encode a structure
  10. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 13 5 /

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

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

    ( 7 + 20 ) Integer operator delimiter integer operator integer delimiter Grammar | Derivation LINE 5 * something ( something 7 + 20 )
  13. jgs Dr. Javier Gonzalez-Sanchez | Compilers | 16 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
  14. Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs Homework Review

    Recursion Solve the Problem Set #1 in preparation for your exam
  15. 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.