Semantic Checks - Base
Semantic Checks
As the parser only does syntactic checking, additional semantic checks are implemented:
- Checking for uses of undeclared variables
- Checking for multiple declarations of variables with the same name in the same scope
- Checking for multiple definitions of functions with the same name
- Checking for calls to unknown functions
- Checking for presence of
main
and correct signature - Checking that all execution paths of a non-void function return a value
- You may assume that there is no dead code
- Type checking (remember, neither implicit nor explicit type conversions)
- Includes checking arguments and return types for call expressions
- Don't forget that an array's type includes its size
Semantic checking may stop on the first error encountered.
In addition to the AST, symbol tables are created and used for semantic checking. Be sure to correctly model shadowing.