Documente Academic
Documente Profesional
Documente Cultură
6. What is an interpreter?
Computer language processor that translates a program line-by-line (statement-by-statement) and carries out
the specified actions in sequence. In contrast, an assembler or compiler completely translates a program written in a
high-level language (the source program) into a machine-language program (the object program) for later execution.
8. What is a compiler?
A compiler 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. The compiler reports to its user the presence of
errors in the source program.
15. List the phases that constitute the front end of a compiler.
The front end consists of those phases or parts of phases that depend primarily on the source language and
are largely independent of the target machine. These include
Lexical and Syntactic analysis
The creation of symbol table
Semantic analysis
Generation of intermediate code
A certain amount of code optimization can be done by the front end as well. Also includes error handling that goes
along with each of these phases.
21. Mention the various notational shorthands for representing regular expressions.
One or more instances (+)
Zero or one instance (?)
Character classes ([abc] where a,b,c are alphabet symbols denotes the regular expressions a | b | c.)
Non regular sets
24. List the various error recovery strategies for a lexical analysis.
Possible error recovery actions are:
Panic mode recovery
Deleting an extraneous character
Inserting a missing character
Replacing an incorrect character by a correct character
Transposing two adjacent characters
24. What are the main two parts of compilation? What are they performing?
The two main parts are
Analysis part breaks up the source program into constituent pieces and creates an intermediate
representation of the source program.
Synthesis part constructs the desired target program from the intermediate representation
letter
letter, digit
30. Define NFA with ε-transition. Is the NFA’s with ε-transitions are more powerful than the NFA’s without
ε-transition?
The NFA with ε moves defined by 5tuple or quintyple as similarly as NFA, except δ (Q,Σ,δ,qo,F) with all
components as before and δ: Qx(ΣU{ε}) = 2Q
No, NFA with ε transition and NFA without ε-transition have the same power.
31. Find the ε-closure of the states 1, 3
ε -closure(1) = {1,2,3,6,7,4}
ε -closure(3) = {3,6,7,1,4,2}
ξ
ξ 2 3 ξ
a
Start 1 ξ
6 7
ξ ξ
4 5
Lexeme: A lexeme is a sequence of characters in the source program that is matched by the pattern for a
token
36. What is a regular expression? State the rules, which define regular expression?
Regular expression is a method to describe regular language
Rules:
1) ϵ-is a regular expression that denotes {ϵ} that is the set containing the empty string
2) If a is a symbol in ϵ,then a is a regular expression that denotes {a}
3) Suppose r and s are regular expressions denoting the languages L(r ) and L(s) Then,
a) (r )/(s) is a regular expression denoting L(r) U L(s).
b) (r )(s) is a regular expression denoting L(r )L(s)
c) (r )* is a regular expression denoting L(r)*.
d) (r) is a regular expression denoting L(r ).
41.Reg exp for the language that accepts all strings in which ‘a’ appears tripled overthe set Σ ={a}
reg exp=(aaa)*
r1.r2= r1r2
( r )*=r*
The class of regular sets are closed under complementation, substitution, homomorphism and inverse homomorphism.
44.Reg exp for the language such that every string will have atleast one ‘a’ followed by atleast one ‘b’.
R=a+b+
45. Write the exp for the language starting with and has no consecutive b’s .
reg exp=(a+ab)*
47. Let R be any set of regular languages. IsUR regular? Prove it.
Yes. Let P,Q be any two regular languages .As per theorem
L( R )=L(P UQ)
=L(P+Q)
Since ‘+’ is a operator for regular expresstions L( R ) is also regular.
2. Regular expression
Regular expressions are used to denote regular languages. They can represent regular languages and
operations on them succinctly.
The set of regular expressions over an alphabet is defined recursively as below. Any element of that set is a regular
expression.
Basis Clause: , and a are regular expressions corresponding to languages , {} and {a}, respectively, where a is an element
.
Inductive Clause: If r and s are regular expressions corresponding to languages Lr and Ls , then ( r + s ) , ( rs ) and ( r*) are
regular expressions corresponding to languages Lr Ls , LrLs and Lr* , respectively.
Extremal Clause: Nothing is a regular expression unless it is obtained from the above two clauses.
50. Write are to denote a language L which accepts all the strings which begin or end with either 00 or 11.
The r.e consists of two parts:
L1=(00+11) (any no of 0’s and 1’s) =(00+11)(0+1)*
L2=(any no of 0’s and 1’s)(00+11) =(0+1)*(00+11)
Hence r.e R=L1+L2 =[(00+11)(0+1)*] + [(0+1)* (00+11)]
Unit-II
1. Write the algorithm for FIRST and FOLLOW in parser?
FIRST
1. If X is terminal, then FIRST(X) IS {X}.
2. If X → ε is a production, then add ε to FIRST(X).
3. If X is non terminal and X → Y1,Y2..Yk is a production, then place a in FIRST(X) if for some i , a is in
FIRST(Yi) , and ε is in all of FIRST(Y1),…FIRST(Yi-1);
FOLLOW
1. Place $ in FOLLOW(S),where S is the start symbol and $ is the input right endmarker.
2. If there is a production A → αBβ, then everything in FIRST(β) except for ε is placed in FOLLOW(B).
3. If there is a production A → αB, or a production A→ αBβ where FIRST(β) contains ε , then everything in
FOLLOW(A) is in FOLLOW(B).
6. What are the various conflicts that occur during shift reduce parsing? (Apr/May2017)
Shift/Reduce Conflict:
Enough terms have been read and a grammar rule can be recognized according to the accumulated terms. In
this situation, the parser can make a reduction. If, however, there is also another grammar rule which calls
for more terms to be accumulated and the look ahead token is just what the second grammar rule expected.
In this situation, the parser may also make a shift operation. This dilemma faced by the parser is called the
Shift/Reduce Conflict.
Reduce/Reduce Conflict:
Enough terms have been read and two grammar rules are recognized based on the accumulated terms. If the
parser then decides to make a reduction, should it reduces the accumulated terms according to the first or
second grammar rules? This type of difficulty faced by the parser is called the Reduce/Reduce Conflict.
21. What is the output of syntax analysis phase? What are the three general types of parsers for grammars?
Parser (or) parse tree is the output of syntax analysis phase.
General types of parsers:
1) Universal parsing
2) Top-down
3) Bottom-up
22.What are the different strategies that a parser can employ to recover from a syntactic error?
Panic mode
Phrase level
Error productions
Global correction
26. Define context free language. When will you say that two CFGs are equal?
A language that can be generated by a grammar is said to be a context free language.
If two grammars generate the same language, the grammars are said to be equivalent.
31. Why do we use regular expressions to define the lexical syntax of a language?
i. The lexical rules of a language are frequently quite simple, and to describe them we do not need a
notation as powerful as grammars.
ii. Regular expressions generally provide a more concise and easier to understand notation for tokens than
grammars.
iii. More efficient lexical analyzers can be constructed automatically from regular expressions than from
arbitrary grammars.
iv. 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 components.
32. When will you call a grammar as the left recursive one?
A grammar is a left recursive if it has a nonterminal A such that there is a derivation AA for some
string.
Ans:
The left factored grammar is,
S → iEtSS′ | a
S′ → eS | ε
E→b
41. Define handle. What do you mean by handle pruning? Nov/Dec 2004, April/May 2005
An Handle of a string is a sub string that matches the right side of production and whose reduction
to the nonterminal on the left side of the production represents one step along the reverse of a
rightmost derivation.
The process of obtaining rightmost derivation in reverse is known as Handle Pruning.
48. Why SLR and LALR are more economical to construct than canonical LR?
For a comparison of parser size, the SLR and LALR tables for a grammar always have the same
number of states, and this number is typically several hundred states for a language like Pascal. The
canonical LR table would typically have several thousand states for the same size language. Thus, it is
much easier and more economical to construct SLR and LALR tables than the canonical LR tables.