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

UP Lecture 15

UP Lecture 15

Compilers
Parser II
(202503)

Avatar for Javier Gonzalez-Sanchez

Javier Gonzalez-Sanchez PRO

December 18, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs KEYWORD {class,

    return, print} STRING Language Actions Expressions (operators) Instructions Control Structures ARITHMETIC OPERATORS { +, -, *, /, =} LOGIC OPERATORS { &, |, ! } RELATIONAL OPERATORS {<, >, ==, !=, <=, >=} KEYWORD { if, else, do, while, for, switch, case } Data INTEGER FLOAT HEXADECIMAL CHAR KEYWORD { void, int, char, string, float, boolean } KEYWORD { true, false } BINARY Delimiter : ; , ( ) { } [ ] Our Language OCTAL IDENTIFIER
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 7 jgs Our Grammar

    5. PARAMS 6. ASSIGNMENT 7. EXPRESSION
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 8 jgs Our Grammar

    9. Y 10. R 8. X What about >= or <= ?
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 10 jgs Our Grammar

    14. C What about call a method and use the returned value?
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 12 jgs Our Grammar

    19, CALL_METHOD 20. PARAM_VALUES 18. RETURN
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 15 jgs Our Grammar

    throw new RuntimeException("Expected …");
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 16 jgs Assignment 2

    | Input Are there syntactical errors? class Test1{ int x; float x; string x; char x; void x; boolean x; }
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 17 jgs Assignment 2

    | Input Are there syntactical errors? class Test2{ void metodo() { int x; x = 5; x = 05; x = 0x5ff; x = 5.55; x = "five"; x = '5'; x = false; } }
  9. Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs Assignment 2

    | Input Are there syntactical errors? class Test3 { void metodo() { x = "hello" + "world" – 'w' * 5 / 3.4; x = y – hello & 0xffff | 05; x = -7; x = !y; x = (cse340 + cse310) / cse101 ; x = false + x + x + x + x / x > x && x==5; } }
  10. Dr. Javier Gonzalez-Sanchez | Compilers | 19 jgs Assignment 2

    | Input Are there syntactical errors? class Test4 { void metodo() { x = 0; int x; y = 1 + 1; x = (0b11) +(05 – 0xFF34); while (2 == "hi") { a = 2 > (4 + Y); if (true) { if( 2 + 2 ) {} else {} } } print ("hello" + "world"); } }
  11. Dr. Javier Gonzalez-Sanchez | Compilers | 20 jgs Assignment 2

    | Input Are there syntactical errors? class Test5 { void metodo() { x = 0; int x; y = 1 + 1; x = (0b11) +(05 – 0xFF34); while (2 == "hi") a = 2 > (4 + Y); if (true) { if( 2 + 2 ) {} else {} } print ("hello" + "world"); } }
  12. Dr. Javier Gonzalez-Sanchez | Compilers | 21 jgs Assignment 2

    | Input Are there syntactical errors? class Test6 { void metodo() { if ( if ( if (x – 3) {} ) ) { print ("hello" + "world"); } if (); if (x > 5); ; } }
  13. 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.