12 Mark Questions With Answer-1
12 Mark Questions With Answer-1
UNIT I
INTRODUCTION TO COMPILING
1. Define compiler?
A compiler is a program that reads a program written in one language (source language) and
translates it into an equivalent program in another language (target language) and the compiler reports to its
user the presence of errors in the source program.
AXIOM DESCRIPTION
r/s = s/r / is commutative
r/(s/t)=(r/s)/t / is associative
(rs)t=r(st) concatenation is associative
r(s/t)=rs/rt concatenation distributes over /
r**=r* * is idempotent
● Write the lexical analyzer in a conventional systems-programming language using the I/O facilities
of that language to read the input.
● Write the lexical analyzer in assembly language and explicitly manage the reading of input.
9. Define regular expression?
● It is built up out of simpler regular expression using a set of defining rules. Each regular expression
„r□ denotes a language L(r). The defining rules specify how L(r)
is formed by combining in various ways the languages denoted by the sub expressions of r.
5. Define CFG?
Many programming language has rules that prescribe the synta tic structure of well-formed programs. The
syntax of programming language constru ts can be described by CFG. Conditional statement defined by a
rule uch as; If S1 and S2 are statements and E is an expression, then
“If E then S1 else S2” is a statement.
(Approved by AICTE and Affiliated to Anna University, Chennai)
27, Thayanur, Trichy – 620009
6. Define ambiguity?
A grammar that produces more than one parse tree for some sentences is said to be ambiguous.
● More efficient lexical analyzers can be constructed automatically from R.E than from arbitrary grammars.
● Separating the syntactic structure of a language into lexical and non lexical parts provides a convenient
way of modularizing the front end of a compiler into two manageable-sized component
10. Define left factoring?
The process of factoring out of common prefixes of alternates is called as left factoring.
17 .Define handle?
A handle of a string is a substring that matches the right side of a production, and whose reduction to the non-
terminal on the left side of the production represents one step along the reverse of a right most derivation.
19. What are the two common ways of determining precedence relations should hold between a pair of
terminals?
● Based on associative and precedence of operators.
● Construct an unambiguous grammar for the language, a grammar that reflects the correct associativity and
precedence in its parse tree.
It is an £-free operator grammar in which the precedence relations <., =., and .> constructed as above are
disjoint. That is for any pair of terminals a and b, never more than one of the relations a<.b, a=.b, and a.>b is
true.
.
1. What are the advantages of generating an intermediate representation?
o Ease of conversion from the source program to the intermediate code.
o Ease with which subsequent processing can be performed from the intermediate code
6. What are the functio s used to create the nodes of syntax trees?
● Mknode (op, left, right)
● Mkleaf (id,entry)
● Mkleaf (num, val)
7. What are the functions for constructing syntax trees for expressions?
● The construction of a syntax tree for an expression is similar to the translation of the expression
into postfix form.
● Each node in a syntax tree can be implemented as a record with several fields.
(Approved by AICTE and Affiliated to Anna University, Chennai)
27, Thayanur, Trichy – 620009
8. Define DAG. Give an example?
● DAG is a directed acyclic graph for an expression identifies the common sub expression
in the expression.
Example: DAG for the expression a- 4 *c
P1 = mkleaf(id,a) P2 = mknum(num,4)
P3 = mkleaf(id,c) P4 = mknode(„*-->,p2,p3)
P5 = mknode(„-„,p1,p4)
21. What are the three address code for a or b and not c?
The three address sequence is
T1:= not c
T2:= b and T1 T3:= a or T2.
22. Write a three address code for the expression a < b or c < d?
100: if a<b goto 103
10 t1:=0
1:
10 goto 104
2:
10 t1:=1
3:
10 if c<d goto
4: 107
(Approved by AICTE and Affiliated to Anna University, Chennai)
27, Thayanur, Trichy – 620009
10 2:=0
5:
10 goto 108
6:
10 t2:=1
7:
10 t3:=t1 or t2
8:
24. What are the various data structures used for implementing the symbol table?
● Linear list
● Binary tree
● Hash table
● Mktable(previous)
● Enter(table, name,type,offset)
● Addwidth(table,width)
● Enterproc(table, name new table)
34. Give the 2 attributes of syntax directed translation into 3-address code ?
● E.place, the name that will hold the value of E and
● E.code , the sequence of 3-addr statements evaluating E.
38. Write the 3-addr code for the statements a =b*-c + b*-c?
Three address codes are: a=b*-c + b*-c
T1 = -c T2 = b*T1 T3
= -c T4 = b*T3
T5 = T2+T4 a:= T5.
Names are bound to storage as a program is compiled, so there is no need for a run time support package.
Stack allocation is defined as a process which manages the run time as a Stack. It is based on the idea of a
control stack; storage is organized as a stack, And activation records are pushed and popped as activations
begin and end.
8. Write the addressing mode and associated costs in the target machine.
14. What are the actions to perform the code generation algorithms?
● Invoke a function get reg to determine the location L.
● Consult the address descriptor for y to determine y□, the current location of y.
● If the current values of y and/or z have no next uses, are not live on exit from the block, and are in
register, alter the register descriptor.