Semantic Analysis: Difference between revisions
From Wiki**3
(New page: == Semantic Analysis == * Abstract syntax tree; nodes * Symbols and types * Symbol table * Varible and function declarations * Type checking) |
No edit summary |
||
Line 1: | Line 1: | ||
* Abstract syntax tree; nodes | * Abstract syntax tree; nodes | ||
* Symbols and types | * Symbols and types | ||
Line 6: | Line 4: | ||
* Varible and function declarations | * Varible and function declarations | ||
* Type checking | * Type checking | ||
== Type Checking Example: Compact == | |||
The package provided here contains the Compact compiler. | |||
This version has been improved to perform type checking in the C generator visitor. This visitor uses a second visitor to check types before deciding on which code to generate. The checks are related with the use of boolean expressions in tests (while, if, and if-else nodes) and with type consistency in operators (in this case, although we could have decided otherwise, operators such as + and - must have arguments of the same type and this type must be integer). In addition, the compiler now checks if a variable has the proper type in certain cases (for instance, in the tests mentioned above). | |||
== Simple Type Checking Example == | |||
The following example considers a simple grammar and performs the whole of the semantic analysis process and, finally, generates the corresponding C code. The semantic analysis process must account for variables (they must be declared before they can be used) and for their types (all types must be used correctly). | |||
* [[Simple Semantic Analysis Example (and C generation)]] | |||
[[category:Compilers]] | |||
[[category:Teaching]] |
Revision as of 17:15, 11 May 2008
- Abstract syntax tree; nodes
- Symbols and types
- Symbol table
- Varible and function declarations
- Type checking
Type Checking Example: Compact
The package provided here contains the Compact compiler.
This version has been improved to perform type checking in the C generator visitor. This visitor uses a second visitor to check types before deciding on which code to generate. The checks are related with the use of boolean expressions in tests (while, if, and if-else nodes) and with type consistency in operators (in this case, although we could have decided otherwise, operators such as + and - must have arguments of the same type and this type must be integer). In addition, the compiler now checks if a variable has the proper type in certain cases (for instance, in the tests mentioned above).
Simple Type Checking Example
The following example considers a simple grammar and performs the whole of the semantic analysis process and, finally, generates the corresponding C code. The semantic analysis process must account for variables (they must be declared before they can be used) and for their types (all types must be used correctly).