-
Notifications
You must be signed in to change notification settings - Fork 1
Type Checking
A Compiler must check that a source code follows both syntactic and semantic conventions of the programming language that it is designed for, this checking is called Static Check (There is another check called Dynamic Check), which ensures that certain kinds of programming errors are detected and reported before Code Generation. Examples of static checks are:
- Type Checks: ex. an operator is applied to an incompatible operand.
- Flow of Control Checks: statements that cause flow of control to leave a context (or block) like break statements must have a place to transform the control to.
- Uniqueness Checks: ex. an Object should only be defined once.
at this phase of Compiler Design we should focus on the Type Checking, some of the above checks folded into other activities, for ex. as we enter information about a name into a symbol table, we can check if the name is declared uniquely.
Type checking is the process of second passing the AST, that we have from previous processes, searching for any final Semantic Errors before the Code Generation process. [ img of Type Checking Position p344 DB]
so a Type Checker verfies that the type of a construct matches that expected by its context. for ex.:
- the built in Arithmatic Operator in C++ mod requires integer operands, so a type checker must verfiy that the operands are integer.
- the type checker must verify that dereferencing is only applied to pointers.
- the type checker must verfiy that indexing is only applied to arrays.
- the type checker must verify that a user-defined function is only applied to the correct number and type of arguments.
- and so forth...
- what is a construct?