190 likes | 417 Views
Compiler Errors. Syntax error Lexical Can not resolve/find symbol Can not be applied Execution error Oh wait, a run time error Intent error It ran, but it did not accomplish the task. Syntax error. Missing semicolons ; Unmatched/missing parenthesis ( ) Unmatched curly braces { }
E N D
Compiler Errors • Syntax error • Lexical • Can not resolve/find symbol • Can not be applied • Execution error • Oh wait, a run time error • Intent error • It ran, but it did not accomplish the task
Syntax error • Missing semicolons ; • Unmatched/missing parenthesis ( ) • Unmatched curly braces { } • Misspelled reserved words • What are reserved words? • They are words that have special meaning in Java. A few examples: • public, class, void, static, main, new
Lexical ErrorsCan not resolve symbol • What’s a symbol • Identifier • For example: reference name – karel, … • Method name • For example: turnLeft(), move(), … • Anything that follows the . In a Robot name • Class name • For example: Robot, IceSkater, Mana, Magnet, (Alice) • Type • Matching Classes – more later.
Lexical ErrorsCan not resolve symbol • Identifier not declared • Misspelled class robot instead of Robot • Misspelled identifier Robot karel = new Robot(); Karle.move(); Karel.turnLeft();
Lexical Errors Can not resolve symbol Continued: • Asking an Object to perform a task it does not recognize Robot karel = new Robot(); karel.turnRight(); karel.mve(); karel.turnleft();
Lexical Errors Can not be applied • Type mismatch • Giving a method the incorrect number/type of parameters
Lexical Errors Can not be applied • Type mismatch Robot karel HurdlerRobot student = new HurdlerRobot(); student = karel; • HurdlerRobot can not be applied to Robot • HurdlerRobot can do more than a Robot? Student.turnRight(); //student can tR, butcan a Robot?
Lexical Errors Can not be applied • Giving a method the incorrect number/type of parameters karel.move(5); • move(int) can not be applied to move(void)
Lexical Errors Can not be applied - Again • Taking it a step further • Consider the method Lab03.takeTheField(Athlete arg) Robot karel = new Robot(); Lab03.takeTheField(karel); • Compile error, takeTheField(Robot) can not be applied to takeTheField(Athlete)
Execution ErrorsOh wait, a run time error • No compiler error, but the program terminates during execution For example: • Robot with no beepers attempts to put a beeper • Robot tries to pick beeper with no beepers • Robot tries to walk through a wall • Divide by zero
Intent Error • Logic error • Program gracefully terminates • No run time exception • Guess who catches this error • If you answered myself (the student), you can earn more points by fixing the error. • If you answered the teacher, you will lose points!
Summary • Syntax error Robot karel = new Robot(); karel. move() // spaces & ; karel.move; // () • Lexical • Can not resolve/find symbol KAREL.move; // misspelling identifier Robot sam = new robot(); // misspelled Robot
Summary • Lexical • Can not be applied Robot karel = new Robot(1.5, 2, West, 0); Can not apply double (1.5) to int int look like Integers (no decimal point) double have a decimal point with or without numbers following Karel.turnLeft(3); can not apply int to void void means that no argument/parameter expected
Summary • Execution Error • It runs - it dies while executing Move through walls beeper issues Unsafe methods move(), pickBeeper(), putBeeper() Safe Methods turnLeft() What about turnRight()?
A final word • First the compiler checks syntax • Then the compiler checks all symbols Remember what symbols are? • Then the compiler checks if it can apply what it has been asked. • If the answer to all the above is yes, Run the program and see what happens