Slide 1

Slide 1 text

jgs Compilers Lecture 15: Syntactic Errors Dr. Javier Gonzalez-Sanchez [email protected]

Slide 2

Slide 2 text

jgs Second Project Our Language

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs Our Grammar 1. PROGRAM

Slide 5

Slide 5 text

Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs Our Grammar 2. METHODS 3. BODY

Slide 6

Slide 6 text

Dr. Javier Gonzalez-Sanchez | Compilers | 6 jgs Our Grammar 4. TYPE Add spanish!

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Dr. Javier Gonzalez-Sanchez | Compilers | 9 jgs Our Grammar 12. A 13. B 11. E

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Dr. Javier Gonzalez-Sanchez | Compilers | 11 jgs Our Grammar 15. VARIABLE 16. WHILE 17. IF

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Dr. Javier Gonzalez-Sanchez | Compilers | 13 jgs Our Grammar 22. FOR 23. SWITCH 21. DOWHILE

Slide 14

Slide 14 text

jgs Test Yourselves

Slide 15

Slide 15 text

Dr. Javier Gonzalez-Sanchez | Compilers | 15 jgs Our Grammar throw new RuntimeException("Expected …");

Slide 16

Slide 16 text

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; }

Slide 17

Slide 17 text

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; } }

Slide 18

Slide 18 text

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; } }

Slide 19

Slide 19 text

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"); } }

Slide 20

Slide 20 text

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"); } }

Slide 21

Slide 21 text

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); ; } }

Slide 22

Slide 22 text

Dr. Javier Gonzalez-Sanchez | Compilers | 22 jgs Test Case 01

Slide 23

Slide 23 text

Dr. Javier Gonzalez-Sanchez | Compilers | 23 jgs Test Case 02

Slide 24

Slide 24 text

Dr. Javier Gonzalez-Sanchez | Compilers | 24 jgs Test Case 02

Slide 25

Slide 25 text

Dr. Javier Gonzalez-Sanchez | Compilers | 25 jgs Test Case 02

Slide 26

Slide 26 text

Dr. Javier Gonzalez-Sanchez | Compilers | 26 jgs Questions

Slide 27

Slide 27 text

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.