Semantic Analyzer
Semantic Analyzer
AN ANNOTATED PARSE TREE. is a parse tree showing the values of the attributes at
each node. The process of computing the attribute values at the nodes is called
annotating or decorating the parse tree.
An attribute is said to be Synthesized attribute if its parse tree node value is determined
by the attribute value at child nodes.
29. What is an inherited attribute? Give example.
Type checking is the process of verifying that each operation executed in a program
respects the type system of the language. This generally means that all operands in
any expression are of appropriate types and number. Much of what we do in the
semantic analysis phase is type checking.
Detect errors: I Memory errors, such as attempting to use an integer as a pointer. I Violations of
abstraction boundaries, such as using a private field from outside a class. I Help compilation: I
When Python sees x+y, its type systems tells it almost nothing about types of x and y, so code
must be general. I In C, C++, Java, code sequences for x+y are smaller and faster, because
representations are known
LALR parser
Try all possible types of each overloaded function (possible but brute force method!)
Top down: narrow set of possible types based on what could be used in an expression