parse syntax trees syntax semantic errors mini lecture
play

Parse & Syntax Trees Syntax & Semantic Errors Mini Lecture - PDF document

Parse & Syntax Trees Syntax & Semantic Errors Mini Lecture CSC 4181 Compiler Construction 1 Parse Tree Expression: a[index] = 4 + 2 Identify tokens: a identifier [ left bracket index identifier ] right bracket =


  1. Parse & Syntax Trees Syntax & Semantic Errors Mini ‐ Lecture CSC 4181 Compiler Construction 1 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 2 2 1

  2. Parse Tree • Expression: a[index] = 4 + 2 expression Assign ‐ expression expression = expression Subscript ‐ expression Additive ‐ expressive expression expression expression + [ expression ] Number 4 Number 2 Identifier a Identifier index 3 3 Syntax Tree • Also called “Abstract Syntax Tree” or AST • Expression: a[index] = 4 + 2 • Condensed version of Parse Tree • Excludes redundant information 4 4 2

  3. Syntax Tree • Expression: a[index] = 4 + 2 Assign ‐ expression Subscript ‐ expression Additive ‐ expression Number Identifier Identifier Number 4 a index 2 5 5 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 several decimal points in a number 6 6 3

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

  5. Semantic Errors • Non ‐ initialized variable: int i; i++; • Type incompatibility: int a = "hello"; 9 9 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend