1 / 9

Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture

Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture. Parse Tree. Expression: a[index] = 4 + 2 Identify tokens: a identifier [ left bracket index identifier ] right bracket = assignment operator 4 number + plus sign 2 number. expression. Assign-expression. expression.

aulii
Télécharger la présentation

Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture

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. Parse & Syntax TreesSyntax & Semantic ErrorsMini-Lecture

  2. Parse Tree • Expression: a[index] = 4 + 2 • Identify tokens: a identifier [ left bracket index identifier ] right bracket = assignment operator 4 number + plus sign 2 number

  3. expression Assign-expression expression = expression Subscript-expression Additive-expressive expression expression expression [ expression ] Number 4 Number 2 Identifier a Identifier index Parse Tree • Expression: a[index] = 4 + 2

  4. Syntax Tree • Also called “Abstract Syntax Tree” or AST • Expression: a[index] = 4 + 2 • Condensed version of Parse Tree • Excludes redundant information

  5. Assign-expression Subscript-expression Additive-expression Number 4 Identifier index Number 2 Identifier a Syntax Tree • Expression: a[index] = 4 + 2

  6. Syntax Errors • Syntax error- an error in the syntax (the rules of formation) of a sequence of characters or tokens that is intended to be written in a particular programming language. • Example is: entering an invalid equation into a calculator, such as opening brackets without closing them, or sever decimal points in a number

  7. Syntax Errors • In Java, the following is a syntactically correct statement:system.out.println("Hello World"); • while the following is not:system.out.+println("Hello World");

  8. Semantic Errors • Semantic error: Writing a valid programming structure with invalid logic. • The compiler will generate instructions that the computer will execute, because it understands the syntax of the programming statements, but the output will not be correct.

  9. Semantic Errors • Non-initialized variable:inti;i++; • Type incompatibility:inta = "hello";

More Related