Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.

Similar presentations


Presentation on theme: "Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture."— Presentation transcript:

1 Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture

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

3 Parse Tree 3 expression Assign-expression expression = Subscript-expressionAdditive-expressive expression [ ] Identifier aIdentifier index Number 4Number 2 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 4

5 Syntax Tree Expression: a[index] = 4 + 2 5 Assign-expression Subscript-expressionAdditive-expression Identifier a Identifier index Number 4 Number 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 6

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

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

9 Semantic Errors Non-initialized variable: int i; i++; Type incompatibility: int a = "hello"; 9


Download ppt "Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture."

Similar presentations


Ads by Google