Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

​26. What is an annotated parse tree?

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​.

27. What is attributed grammar?

Attribute grammar is a special form of context-free grammar where some additional


information (attributes) are appended to one or more of its non-terminals in order to
provide context-sensitive information. Each attribute has well-defined domain of values,
such as integer, float, character, string, and expressions.
Attribute grammar is a medium to provide semantics to the context-free grammar and it
can help specify the syntax and semantics of a programming language. Attribute
grammar (when viewed as a parse-tree) can pass values or information among the
nodes of a tree.
E ​→​ E ​+​ T ​{​ E​.​value​ ​=​ E​.​value​ ​+​ T​.​value​ ​}

28. What is synthesized attribute? Give example.

An attribute is said to be Synthesized attribute if its parse tree node value is determined 
by the attribute value at child nodes. 

The production must have non-terminal as its head. 

It can be evaluated during a single bottom-up traversal of parse tree. 


Synthesized attributes can be contained by both the terminals or non-terminals. 

Synthesized attribute is used by both S-attributed SDT and L-attributed STD. 

 
 
29. What is an inherited attribute? Give example.

An attribute of a nonterminal on the right-hand side of a production is called an ​inherited


attribute​.
● S → ABC
● A can get values from S, B and C. B can take values from S, A, and C. Likewise,
C can take values from S, A, and B.

30. Say something about type checking and its importance.

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

31. What is the parser used by YACC?

LALR parser

YACC (yet another compiler-compiler) is an ​LALR(1)​ (LookAhead, Left-to-right,


Rightmost derivation producer with 1 lookahead token) parser generator. YACC was
originally designed for being complemented by Lex.
32. Give you idea of how function overloading will be handled by the compiler​.

Try all possible types of each overloaded function (possible but brute force method!)

Keep track of all possible types

Discard invalid possibilities

At the end, check if there is a single unique type

Overloading can be resolved in two passes:

Bottom-up: compute set of all possible types for each expression

Top down: narrow set of possible types based on what could be used in an expression

Intermediate code generation


33. What are various intermediate code forms? Why is this phase needed?

Intermediate Forms of a Program:

ASTs: Abstract Syntax Trees

DAGs: Directed Acyclic Graphs

You might also like