1 / 15

Compiler Errors

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

kim-sherman
Télécharger la présentation

Compiler Errors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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.

  4. Lexical ErrorsCan not resolve symbol • Identifier not declared • Misspelled class robot instead of Robot • Misspelled identifier Robot karel = new Robot(); Karle.move(); Karel.turnLeft();

  5. 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();

  6. Lexical Errors Can not be applied • Type mismatch • Giving a method the incorrect number/type of parameters

  7. 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?

  8. 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)

  9. 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)

  10. 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

  11. 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!

  12. 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

  13. 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

  14. 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()?

  15. 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

More Related