Professional Documents
Culture Documents
Part 3
Part 3
Analysis
The provided information describes the semantic analysis phase of a compiler for a language with
classes, functions, and variables. The semantic analysis focuses on ensuring the program adheres
to the language's rules and identifying any errors related to variable types, function calls, and
class inheritance.
Symbol Tables:
A symbol table is used to store information about identifiers (variables, functions, classes) such
as their type and scope.
Separate symbol tables are created for the global scope, each class, and each function.
Inheriting classes use the symbol table of their parent class.
Type Checking:
Expressions, assignments, and return statements must involve compatible data types.
Function calls must use the correct number and type of arguments according to the function's
declaration.
Array accesses must use integer expressions as indices.
Circular Class Dependencies:**
Inheritance hierarchies cannot form circular dependencies (e.g., class A inherits from B, class B
inherits from A).
Member Access:
The dot operator (.) can only be applied to variables of a class type.
The right operand of the dot operator must be a member of the class on the left.
Design
Implementation Tools
The image depicts an example symbol table structure. It likely shows entries for various classes,
functions, and variables along with their types and scope information. This helps visualize how
the symbol table stores information for the compiler to perform semantic analysis.