Escolar Documentos
Profissional Documentos
Cultura Documentos
4. Define lexeme?
The character sequence forming a token is called lexeme for the token.
8. Write the syntax for three-address code statement, and mention its properties.
Syntax: A= B op C
Three-address instruction has at most one operator in addition to the
assignment symbol. The compiler has to decide the order in which
operations are to be done.
The compiler must generate a temporary name to hold the value
computed by each instruction.
Some three-address instructions can have less than three operands.
11. Define the rule to develop an unambiguous grammar from ambiguous grammar.
If S->αSβSγ / α1 / α2 / α3 / α4 /. ……/ αn is an ambiguous grammar than
Unambiguous grammar becomes
S-> αSβS1γ / S1
S1->α1 / α2 / α3 / α4 /. ……/ αn
25. Write down the sequence of auxiliary definitions for the following.
Decimal, Real, Exponential.
Digit = 0|1|… 9
Integer = Digit
Sign = +|-|E
Signed-integer = Sign Integer
Decimal = Signed-integer. Integer| Signed-Integer| Sign. Integer
Exponential = (Decimal| Signed-Integer) E Signed-Integer
Real = Decimal Exponential
35. How will you change the given grammar to an augmented grammar?
If ‘G ‘ is a grammar with start symbol ‘S’ then G′ is the augmented
grammar for G, such that G′ is G with a new start symbol S′ and with production
S′ÆS.
37. What are the rules for “ Closure operation” in SLR parsing?
If ‘I’ is a set of items for grammar G then Closure (I) is the set of
items constructed from I by the following 2 rules.
Initially every item in I is added to Closure (I)
If AÆα.Bβ is in Closure(I) and BÆα to I , then add the item BÆ.α to I, if it
is not
already there. Apply this until no more new items can be added to Closure (I).
39. How to make an ACTION and GOTO entry in SLR parsing table?
i. If [AÆα .aβ] is in Ii and goto (Ii, a)=Ij then set ACTION [I, a]=Shift j. Here
‘a’ must be a terminal.
ii. If [AÆα.] is in Ii then set ACTION [I, a] to “ reduce AÆα” for all a in
FOLLOW (A), here A should not be S′.
iii. If S′ÆS is in Ii then set ACTION (i, $) to “ accept”
40. What are the rules to apply Closure function in CLR parser?
Let ‘L’ is a set of LR (1) items for grammar then 2 steps can compute Closure of
I.
41. Find the item I0 for the following grammar using CLR parsing method.
G: SÆAS
SÆb
AÆSA
AÆa
I0: S′Æ. S , $
SÆ.AS , $
SÆ.b , $
AÆ.SA , a|b
AÆ.a , a|b
SÆ.AS , a|b
SÆ.b , a|b
46. What is the new production added to the YACC on error recovery
When parser generated by YACC encounters errors, then YACC
pops symbol from its stack until it finds the topmost state on its stack whose
underlying set of items includes an item of the form AÆ. error α
a +
* *
b uminus b uminus
51. In compiler how three address statements can be represented as records with fields
for the operator and operands.
¾Quadruples.
¾Triples.
¾Indirect triples.
52. Define quadruple and give one example.
A quadruple is a data structure with 4 fields like operator, argument-1 ,
argument-2 and result.
Example: a=b*-c
55. What are the two methods of translation to find three-address statements in Boolean
expression?
• Numerical method
• Control flow method
56. Generate three address code for “ if A<B then 1 else 0” , using numerical method.
E.val=19
E.val=15 + T.val=4
T.val=15 F.val=4
F.val=3 digit.lexval=5
digit.lexval=3
64. When procedure call occurs, what are the steps to be takes placed?
• State of the calling procedure must be saved, so that it can resume after
completion of procedure.
• Return address is saved, in this location called routine must transfer after
completion of procedure
65. What are the demerits in generating 3-address code for procedure calls?
Consider, b=abc (I, J) .It is very difficult to identify whether it is array
reference or it is a call to the procedure abc.
68. What are the different data structures used for symbol table?
Lists
Self-organizing lists.
Search tree.
Hash table
do
{
/*since n was just listed, surely m is not yet listed */
}
begin
list m
n=m;
end
end
LABEL(n)=max(2,l1, l2 ) if l1# l2
= l1 +1 if l1= l2
90. List any two structure preserving transformations adopted by the optimizer?
The structure preserving transformations adopted by the optimizer are,
Basic blocks.
Flow graphs.
98. Write down the postfix notation for the following statement.
If c*d+e then if a-b then a+c else a+c*d else c*d+e.
Answer: cd*e+ab-ac+acd*+cd*e+
101. What is the main difference between phase and pass of a compiler?
A phase is a sub process of the compilation process whereas combination of one
or more phases into a module is called pass.
Complier is a program that reads a program written in one language –the source
language- and translates it into an equivalent program in another language- the target
language. In this translation process, the complier reports to its user the presence of
the errors in the source program.
The analysis part breaks up the source program into constituent pieces and creates
an intermediate representation of the source program.
The synthesis part constructs the desired target program from the
intermediate representation.
104.Define interpreter.
105.Define linker.
Linker is a program that combines (multiple) objects files to make an
executable. It converts names of variables and functions to numbers (machine
addresses).
106.Define editor.
Editors may operate on plain text, or they may be wired into the rest of the
complier, highlighting syntax errors as you go, or allowing you to insert or delete
entire syntax constructed at a time.
107.Define profiler
Profiler is a program to help you see where your program is spending its
time, so you can tell where you need to speed it up.
Literal table is a table that stores “ literal” values, mainly strings and variables
names that may occur in many places. Only one copy of each unique string and name
needs to be allocated in memory.
Let L={A, B… … … Z, a,b,… … z}, D={0,1,… … .9}. Determine the languages
represented by L (LUD)* and L*.
L(LUD)* is the set of all strings of letters and digits beginning with a letter.
L+ is the set of all strings of letters including the empty string.
110.Define Assembler.
111.Define Loader.
Debugger is a program to help you see what is going on when your program runs.
It can print the values of variables, show what procedure called what procedure to get
where you are, run up to a particular line, run until a particular variables gets a special
value etc.
Often the phases of a compiler are collected into a front-end and back-end.
Front-end consists of those phases that depend primarily on the source program and
largely independent of the target machine. Back-end consists of those phases that
depend on the target machine language and generally those portions do not depend on
the source language, just the intermediate language. In back end we use aspects of
code optimization, code generation, along with error handling and symbol table
operations.
115.Define Passes.
The rules and regulations used to form a language are known as syntax. The
meaning given to a programming construct is known as semantics.
The stream of characters making up the source program is read from left-to-
right and grouped into tokens that are sequence of characters having a collective
meaning.
¾Preprocessors.
¾Assemblers.
¾Two pass assembly.
¾Loader and link editors.
i. This buffering scheme works quite well most of the time but with it
amount of lookahead is limited.
ii. Limited lookahead makes it impossible to recognize tokens in situations
where the distance, forward pointer must travel is more than the length
of buffer.
¾Easy to understand.
¾Imparts a structure to a programming language.
¾Acquiring new constructs.
128. What are the different strategies that a parser can recover from a syntactic error?
¾Panic mode.
¾Phrase level.
¾Error productions.
¾Global correction.
Terminals are the basic symbols from which the strings are formed.
Shift reduce parsing constructs a parse tree for an input string beginning at
the leaves and working up towards the root i.e., “ reducing” a string w to the start
symbol of a grammar.
¾Shift.
¾Reduce.
¾Accept.
¾Error.
The set of prefixes of right sentential forms that can appear on the stack of a
shift reduce parser are called viable prefixes.
¾Shift/reduce conflict.
Parser cannot decide whether to shift or reduce.
¾Reduce/reduce conflict.
Parser cannot decide which of the several reductions to make.
140. Differentiate Kernel and non-Kernel items.
Kernel items, which include the initial item, S’ -> .S and all items whose
dots are not at the left end. Whereas the nonkernel items have their dots at the left
end.
¾An input.
¾An output.
¾A stack.
¾A driver program.
¾A parsing table.
¾Simple LR(SLR).
¾Canonical LR.
¾Lookahead LR (LALR).
Boolean expressions are composed of the boolean operators (and, or, not)
applied to elements. That are boolean variables or relational expressions.
We take the cost of an instruction to be one plus the costs associated with
the source and destination address modes. This costs corresponds to the length (in
words) of the instruction. Address modes involving registers have cost zero, while
those with a memory location or literal in them have cost one, because such operands
have to be stored with the instruction.
The identifiers appearing in procedure definitions are special and are called
formal parameters.
An activation tree depicts the way control enters and leaves activations.
It keeps track of live procedure activations. Push the node for activation
onto the control stack as the activation begins and to pop the node when the
activation ends.
1) Static allocation.
It lays out storage for all data objects at compile time.
2) Stack allocation.
It manages the runtime storage as a stack.
3) Heap allocation.
It allocates and deallocates storage as needed at runtime
from a data area.
¾Call by value.
¾Call by reference.
¾Copy restores.
¾Call by name
1. For the regular expression , (a / b)*abb . Draw the NFA. Obtain DFA from
NFA. Minimize DFA using ∏new construction.
Hints:
• NFA
• ∈-closure computation
• DFA diagram
• Minimization steps
• Minimized DFA
2. Explain the various phases of a compiler in detail. Also write the output for
the following expression after each phase a=b*c-d
Hints:
Lexical analysis
Syntax analysis and semantic analysis
Intermediate code generation
Code optimization
Code generation
3. Explain in detail about compiler construction tools.
Hints:
LEX
YACC
Syntax Directed Translation
Code generator
17.Construct quadruples and triples and indirect triples for any 3-address statement.
Hints:
¾Construct quadruples table
¾Develop triples table
¾Construct indirect triple table.
18.Write syntax directed translation scheme for generating three address code foe
Boolean expression using back patch method.
Hints:
Write syntax directed translation schemes
Explain with an example.
19.Explain syntax directed translation scheme of flow of control statements and give one
example.
Hints:
Write semantic rules for if , while , if… else statements
Give an example.
20. Explain syntax directed translation scheme of procedure call statements and give one
example
Hints:
Write semantic rules for procedure call statements and give one example.
21.Explain in detail about loop optimization techniques.
Hints:
Loop test replacement
Dead code elimination
Code motion
Code movement