One Line Ques Ans1
One Line Ques Ans1
©net2net 23
One Line Answers
12. Define cross-compiler.
When a compiler runs on one machine and produces object code for another machine such a compiler is
called as cross–compiler.
13. What are advantages of bootstrapping?
1. A compiler can be written in the language it compiles.
2. An optimizing compiler can optimize itself.
14. Multipass compilers are preferable over single pass compilers. Comment.
True – A multi-pass compiler can be made to use less space than a single pass compiler, since the space
occupied by the compiler program for one pass can be reused by following pass.
15. What happens during table management of bookkeeping phase of compilation?
The table management, or bookkeeping, portion of the compiler keeps track of the names used by the
program and records essential information about each, such as its type (integer, real, etc.). The data
structures used to record this information is called a symbol table.
16. Good error handling is difficult. Comment.
Good error handling is difficult because certain errors can mask subsequent errors. Other errors, if not
properly handled, can spawn an avalanche of spurious errors.
17. Define: symbol table
Information about source program (identifiers, type, size, etc.) is stored in a data structure called a symbol
table, which is passed to back end.
18. Define: single-pass compiler
In this type of compiler all phases occur during a single pass i.e. a source program is processed only once,
during the translation.
19. Define: multi-pass compiler
While translating source program into target program, we read through a representation of entire source
program multiple times is called as multi-pass compilers.
20. List the functions that compiler.
1. Translate high level language to low level language.
2. Reporting errors and warnings.
21. Which phase of compiler is also known as scanning phase?
Lexical Analyzer
22. Which phase of compiler is also known as parsing phase?
Syntax Analyzer
Letter Letter/Digit
0 1 2
Delimiter
©net2net 25
One Line Answers
declarations
%%
translation rules
%%
auxiliary functions
18. What is manifest constant?
Manifest constants are identifiers declared to stand for a constant, e.g., the name of a token.
19. State the pattern for regular expression ‘signed number’ in lex language notation.
[+-]?[0-9]+
20. Write the purpose of lex library functions-yylex ( )and yyerror( ).
yylex()- The lexical analyzer yylex() produces tokens consisting of a token name and its associated
attribute value.
yyerror() – Called by scanner or parser to display error encountered.
21. What are sentinels?
The sentinel is a special character that cannot be part of the source program, and a natural choice is the
character eof.
22. How conflict can be resolved in Lex
When several prefixes of the input match one or more patterns:
1. Always prefer a longer prefix to a shorter prefix.
2. If the longest possible prefix matches two or more patterns, prefer the pattern listed first in the Lex
program.
23. Explain the advantage of a lexical analyzer generator.
Advantage of lexical analyzer generator is that human efforts are reduced. Otherwise using handcoding
technique we are only suppose to construct NFA for different regular expressions, convert it to DFA,
minimize it and then convert it into code. This is happening within fraction of seconds using scanner
generator.
24. State the pattern for regular expression “set of a’s and b’s of length 2”, in lex language notation .
[ab]{2}
25. State the pattern for regular expression “any character between ‘P’ and ‘S’ irrespective of its case”,
in lex language notation.
[P-Sp-s]
Chapter 3: Parser
1. What is parser?
A parser for grammar G is a program that takes as input a string w and produces as output either a parse
tree for w, if w is a sentence of G, or an error message indicating that w is not a sentence of G.
2. What are the two functions of parser?
1. Checks whether the tokens appearing in its input, which is the output of the lexical analyzer, occurs in
patterns that are permitted by the specification for the source language (grammar).
2. Imposes a tree like structure that is used by the subsequent phases of the compiler.
3. Define handle.
While reduction we find substring in the sentential form which matches RHS of some production. Such
substring is called handle.
4. What is handle pruning?
The process of discovering a handle in the sentential form & reducing it to the appropriate left-hand side
is called handle pruning.
5. What are the demerits of SLR?
1. It will not produce uniquely defined parsing action tables for all grammars.
©net2net 26
One Line Answers
2. Shift-Reduce conflict.
6. Why LR parsing is good and attractive?
1. LR parsers can be constructed for all programming language constructs for which CFG can be
written.
2. LR parser can detect syntactic error as soon as possible, when left-to-right scan of the input.
7. How will you change the given grammar to an augmented grammar?
If ‘G’ is a grammar with start symbol ‘S’ then GWis the augmented grammar for G, such that GWis G
with a new start symbol SWand with production SW→S.
8. Explain the need of augmentation.
To indicate to the parser that, when it should stop parsing and when to announce acceptance of the input.
Acceptance occurs when the parser is about to reduce by SW→S.
9. Let I is a set of LR(O) items, and X is a grammar symbol. Define GOTO(I, X)
GOTO(I,X)={CLOSURE({AαX.β})|Aα.Xβ is in I}
10. Construct LR(O) item for A→ →∈
LR(0) item for A→∈ is A→•
11. What do LL and LR stand for?
LL – First L indicates leftmost derivation and second L indicates input scanned from left to right.
LR – Input scanned from left to right and generates rightmost derivation in reverse.
12. Construct LR(0) items for following production: A XYZ.
AXYZ yields four items
A•XYZ
AX•YZ
AXY•Z
AXYZ•
13. Explain the function CLOSURE(I).
If I is a set of items for a grammar G, then the set of items CLOSURE(I) is constructed from I by the
rules.
1. Every item in I is in CLOSURE (I)
2. If Aα.Bβ is in CLOSURE (I) and Bγ is a production, add the item B.γ to I, if it isn’t already
there.
14. Define CLOSURE(I) operation in LR parsers.
For LR(1) item I, CLOSURE (I) is constructed as follows:
1. Everything in I is in CLOSURE(I)
2. If [Aα.Bβ,a] is in I and Bγ is a production then add β.γ,b] to CLOSURE (I) for every terminal
‘b’ in FIRST(βa)
15. Which type of conflict is not possible in LR parser?
Shift-Shift conflict is not possible in LR parser.
16. Which kind of parser is most common in compilers?
LALR(Look Ahead Left Right) parser is most common in compilers.
17. Recursive decent parser is bottom up type parser. State True or False.
False
18. What is left recursive grammar?
A grammar G is said to be left-recursive if it has a non-terminal A such that there is a derivation A→Aα
for some α
19. What is left factoring?
If A→αβ|αγ are two A-productions, and the input begins with a non-empty string derived from α, we do
not know whether to expand A to αβ or αγ. Left factoring the above grammar we get following
productions:
©net2net 27
One Line Answers
A→αA’
A’→β|γ
20. Left recursive grammars are not suitable for top down parsing. State true or false.
True.
21. List actions taken by shift reduce parser.
1. Shift
2. Reduce
3. Accept
4. Error
22. Define viable prefixes.
The set of prefixes of right sentential forms that can appear on the stack of a shift reduce parser are called
viable prefixes.
23. List down the conflicts during shift-reduce parsing.
1. Shift/reduce conflict: Parser cannot decide whether to shift or reduce.
2. Reduce/reduce conflict: Parser cannot decide which of the several reductions to make.
24. Differentiate Kernel and non-Kernel items.
Kernel items include the initial item, S’.S and all items whose dots are not at the left end. Whereas the
non-kernel items have their dots at the left end.
25. What are the components of LR parser?
1. An input.
2. An output.
3. A stack.
4. A driver program.
5. A parsing table.
26. List the different techniques to construct an LR parsing table?
1. Simple LR(SLR).
2. Canonical LR.
3. Lookahead LR (LALR).
27. YACC is a parser. State true or false.
False
28. What is the syntax for YACC source specification program?
Declarations
%%
Translation rules
%%
Supporting C-routines
29. How YACC resolves parsing action conflicts?
A reduce/reduce conflict is resolved by choosing the conflicting production listed first in the YACC
specification. A shift/reduce conflict is resolved by shifting action or introduce associativity and
precedence.
30. What are the actions performed by a shift reduce parser?
1. Shift
2. Reduce
3. Accept
4. Error
31. What is a recursive descent parser?
©net2net 28
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II
A parser that uses a set of recursive procedures to recognize its input with no backtracking is called a
recursive-descent parser.
32. Why is the precedence and associativity required in the declaration section of a yacc program?
A shift reduce conflicts can be removed by giving precedence and associativity in the declaration section
of a yacc program?
33. What is an operator grammar?
The grammar not having ∈-production and right-side of each production is not having two adjacent non-
terminals.
e.g. SS+S|S*S|id
34. State the relation between number of states in SLR and LALR parser.
Total number of states in SLR are approximately equal to LALR parser.
35. Do left factoring in the following grammar.
AaBcC | aBb | aB | a
BW
CW
After left factoring
AaBA’|a
A’cC|b|W
BW
CW
36. What is conflict? Which type of conflict cannot occur in LR parsers?
If there are multiple entries in LR parsing table then if say conflict has occur. Reduce/reduce can never
occur in LR parsers.
37. State the meaning of ‘UMINUS’ in yacc.
UMINUS represents unary minus. If used as %prec UMINUS then it indicated give precedence of unary
minus.
©net2net 29
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II
It is computed from the value of attributes at the siblings and parent of that node.
6. Define annotated parse tree.
A parse tree showing the values of attributes at each node is called an annotated parse tree.
7. What do you mean by a syntax tree?
Syntax tree is a variant of a parse tree in which each leaf represents an operand and each interior node
represents an operator.
8. When can semantic analysis be done?
Semantic analysis can be done during syntactic analysis or sometimes it is done at the final code
generation phase.
9. Mention the role of semantic analysis?
1. Semantic analysis checks the source program for semantic errors and gathers information for the
subsequent code-generation phase. It uses hierarchical structure to identify the operators and
operands of expressions and statements.
2. An important component of semantic analysis is type checking .In type checking the compiler
checks that each operator has operands that are permitted by the source language specification. In
such cases, certain programming language supports operand coercion or type coercion also.
10. What is dependency graph?
A dependency graph (DG) depicts the flow of information among the attribute instances in a particular
parse tree; an edge from one attribute instance to another means that the value of the first is needed to
compute the second.
11. What are two important classes of SDDs
1. The “S-attributed” and
2. The more general “L-attributed” SDD’s.
12. What is attribute grammar?
An SDD without side effect is sometimes called an attribute grammar. The rules in an attribute grammar
define the value of an attribute purely in terms of the values of other attributes and constants.
13. What is postfix SDT?
SDT’s with all actions at the right ends of the production bodies are called postfix SDT’s.
14. Give applications of SDT?
1. Construction syntax tree
2. Generating type
©net2net 30
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II
3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order
5. Define basic block.
A basic block contains sequence of consecutive statements, which may be entered only at the beginning
and when it is entered it is executed in sequence without halt or possibility of branch.
6. Define flow graph.
Relationships between basic blocks are represented by a directed graph called flow graph.
7. What is code optimization? Explain local optimization.
• It is a program transformation technique applied on intermediate code so that made the code
produced runs faster or takes less space.
• Local optimization applied over small segments of a program consisting of a few source statements.
8. What are the rules to find “leader” in basic block?
- The first statement in a basic block is a leader.
- Any statement which is the target of a conditional or unconditional goto is a leader.
- Any statement which immediately follows a conditional goto is a leader.
9. State some application of DAG
1. eliminating local common sub-expressions
2. eliminating dead code
3. reordering statements that do not depend on one another
4. applying algebraic laws to reorder operands of three-address instructions
10. What are dominators?
We say node d of a flow graph dominates node n, written d dom n, if every path from the entry node of
the flow graph to n goes through d. Note that under this definition, every node dominates itself.
11. What is a dominator tree?
A useful way of presenting dominator information is in a tree, called the dominator tree, in which the
entry node is the root, and each node d dominates only its descendants in the tree.
12. What is the use of dominator?
Dominators are used to detect the loops in a program, during data float analysis.
13. What is the need of ‘code optimization’?
1. To eliminate redundancies in program.
2. Computations in a program are rearranged or rewritten so to execution efficiency is improved,
which results in faster running machine code.
14. List different code optimization techniques.
1. Compile time evaluation
2. Common sub-expression elimination
3. Frequency reduction
4. Dead code elimination
5. Strength reduction.
15. What do you mean by ‘loop invariant’ computation?
This transformation takes on expression that yields the same result independent of the number of times a
loop is executed and places the expression before the loop.
16. What is ‘strength reduction’?
The strength reduction optimization replaces the occurrence of a time consuming operation by an
occurrence of a faster operation.
e.g. X = Y*2; can be replace as X = Y + Y;
©net2net 31
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II
©net2net 32
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II
4. Shift-Reduce conflict can occur in Rarely shift-reduce conflict Reduce-reduce conflict can
SLR can occur. occur in LALR
5. Good method Better method Most powerful (best) method.
6. Memory requirement is less. Memory requirement is Memory requirement is less.
large.
©net2net 33