Presentation is loading. Please wait.

Presentation is loading. Please wait.

What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.

Similar presentations


Presentation on theme: "What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree."— Presentation transcript:

1 What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree

2 Translators

3 Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and optimisation Library routines

4 Translators – Module Knowledge Areas Syntax analysis describe what happens during syntax analysis explaining how errors are handled So, you need to be able to: State what syntax analysis is Describe the process of syntax analysis Explain the position of syntax analysis in the compilation process. You may do this through a combination of diagrammatic and written evidence. Discuss the link between lexical analysis and syntax analysis with particular reference to the passing of lexical tokens to the syntax analyser Explain the part that syntax analysis plays in identifying errors in source code

5 Translators – Syntax Analysis IF A>5 THEN A = A * 2 ELSE A = A * 3 A = A + 2 Explain the relationship between the table and the code (M)

6 Translators – Syntax Analysis Explain the relationship between the table and the numbers 1 2 3 4 5 2 6 2 7 8 9 2 6 2 7 10 2 6 2 11 8 What is the significance of ‘2’ in the above sequence? (M)

7 Translators – Syntax Analysis The journey PhaseInputOutput Lexer Sequence of characters Sequence of tokens ParserSequence of tokens Parse tree

8 Translators – Syntax Analysis The Parser - Overview Performs syntax analysis Imposes syntactic structure on a sentence Parse trees are used to expose the structure Parsers, accepts a string of tokens and builds a parse tree representing the program

9 Translators – Syntax Analysis Symbol Table - Overview The symbol table is a data structure used by all phases of the compiler to keep track of user defined symbols and keywords During early phases (lexical and syntax analysis) symbols are discovered and put into the symbol table During later phases symbols are looked up to validate their usage

10 Translators – Syntax Analysis Symbol Table - Actions add a new name add information for a name access information for a name determine if a name is present in the table remove a name revert to a previous usage for a name (close a scope)

11 Translators – AST AST - Why The syntax tree is a structure which can be guaranteed syntactically correct and only readable in one way - there are no issues with precedence of operations in how the program works

12 Translators – AST AST - How What is happening here? Simple operation of 2 * 3 in a symbolic layout

13 Translators – AST AST - How Which are the operators and which are the operands? The operator is root and the operands are descendants of the root

14 Translators – AST AST - How Consider the program statement 2 * 3 + 4 Create an AST to represent this

15 Translators – AST AST - How Which AST is correct for the statement 2 * 3 + 4? Why? (M)


Download ppt "What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree."

Similar presentations


Ads by Google