Sunteți pe pagina 1din 13

Unit –I

1. What are the two parts of a compilation? Explain briefly.


Analysis and Synthesis are the two parts of compilation. 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.

2. Illustrate diagrammatically how a language is processed.


Skeletal source program→Preprocessor→Source program→Compiler→Target assembly
program→Assembler→Relocatable machine code →Loader/ link editor ←library, reloadable object
files→Absolute machine code

3. What is a symbol table?


Symbol table is an important data structure created and maintained by compilers in order to store
information about the occurrence of various entities such as variable names, function names, objects,
classes, interfaces, etc. Symbol table is used by both the analysis and the synthesis parts of a compiler.

4. List the various compiler construction tools.


The following is a list of some compiler construction tools:
 Parser generators
 Scanner generators
 Syntax-directed translation engines
 Automatic code generators
 Data-flow engines

5. List the cousins of a compiler.


Cousins of the compiler are:
 Preprocessors
 Assemblers
 Loaders and Link-Editors

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.

7. What do you mean by cross-compiler?


A cross compiler is a compiler capable of creating executable code for a platform other than the one on
which the compiler is running.

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.

9. Write the differences between compiler and interpreter


No Compiler Interpreter
1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input .
2 Intermediate Object Code is Generated No Intermediate Object Code is Generated
3 Conditional Control Statements are Executes faster Conditional Control Statements are Executes slower
Memory Requirement : More (Since Object Code is
4 Memory Requirement is Less
Generated)
Every time higher level program is converted into lower
5 Program need not be compiled every time
level program
Errors are displayed for every instruction interpreted (if
6 Errors are displayed after entire program is checked
any)
10. What is linear analysis?
Linear analysis is one in which the stream of characters making up the source program is read from left to
right and grouped into tokens that are sequences of characters having a collective meaning.
Also called lexical analysis or scanning.

11. List the various phases of a compiler.


The following are the various phases of a compiler:
 Lexical Analyzer
 Syntax Analyzer
 Semantic Analyzer
 Intermediate code generator
 Code optimizer
 Code generator

12. What is translator? What are the different types of translators?


Programming language processor that converts a computer program written in one language to
another. Translator types are assembler, compiler, interpreter.

13. What is the role of a passer?


The parser collects sufficient number of tokens and builds a parse tree. Then by building the parse tree,
parse smartly finds the syntactical errors if any. It is also necessary that the parse should recover from commonly
occurring errors so that remaining task of process the input can be continued.

14. Mention some of the cousins of a compiler.


Cousins of the compiler are:
 Preprocessors
 Assemblers
 Loaders and Link-Editors

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.

16. Mention the back-end phases of a compiler.


The back end of compiler includes those portions that depend on the target machine and generally those
portions do not depend on the source language, just the intermediate language. These include
 Code optimization
 Code generation, along with error handling and symbol- table operations.

17. Define compiler-compiler.


Systems to help with the compiler-writing process are often been referred to as compiler-compilers,
compiler-generators or translator-writing systems.Largely they are oriented around a particular model of languages ,
and they are suitable for generating compilers of languages similar model.

18. Differentiate tokens, patterns, lexeme.


 Tokens-Sequence of characters that have a collective meaning.
 Patterns-There is a set of strings in the input for which the same token is produced as output. This set of
strings is described by a rule called a pattern associated with the token
 Lexeme- A sequence of characters in the source program that is matched by the pattern for a token.
19. List the operations on languages.
 Union - L U M ={s | s is in L or s is in M}

 Concatenation – LM ={st | s is in L and t is in M}


 Kleene Closure – L* (zero or more concatenations of L)
 Positive Closure – L+ ( one or more concatenations of L)

20. Write a regular expression for an identifier.


An identifier is defined as a letter followed by zero or more letters or digits. The regular expression for an
identifier is given as letter (letter | digit)*

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

22. What is the function of a hierarchical analysis?


Hierarchical analysis is one in which the tokens are grouped hierarchically into nested collections with
collective meaning. Also termed as Parsing.

23. What does a semantic analysis do?


Semantic analysis is one in which certain checks are performed to ensure that components of a program fit
together meaningfully. Mainly performs type checking.

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

25. What is a Structure editor?


A structure editor takes as input a sequence of commands to build a source program .The
structure editor not only performs the text creation and modification functions of an ordinary text editor but it
also analyzes the program text putting an appropriate hierarchical structure on the source program.

26. What are a Pretty Printer and Static Checker?


 A Pretty printer analyses a program and prints it in such a way that the structure of the program
becomes clearly visible.
 A static checker reads a program, analyses it and attempts to discover potential bugs with out running the
program.

27. Differentiate NFA and DFA


NFA or Non Deterministic Finite Automaton is the one in which there exists many paths for a specific input
from current state to next state. NFA can be used in theory of computation because they are more flexible and easier
to use than DFA .
Deterministic Finite Automaton is a FA in which there is only one path for a specific input from current
state to next state. There is a unique transition on each input symbol.(Write examples with diagrams).
28. What is €-closure of a state q0?
_-closure(q0 ) denotes a set of all vertices p such that there is a path from q0 to p labeled _. Example
:closure(q0)={q0,q1}

29. What is meant by DFA?


A deterministic finite automaton (DFA) also known as deterministic finite state machine — is a finite state
machine that accepts/rejects finite strings of symbols and only produces a unique computation (or run) of the automaton for
each input string. 'Deterministic' refers to the uniqueness of the computation.

Draw the transition diagram (automata) for an identifier.


An identifier can be defined as a string of letters and digits that begins with a letter.
Token letter stands for any of the symbols a, . . . , z, A, . . . , Z.
Token digit stands for 0, 1, . . . , 9.
The set of identifiers is specified by the state-transition diagram in Figure 1.

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

33. Define NFA with transition.


The is a character used to indicate null string.
i.e the string which is used simply for transition from one state toother state without any
input.
A Non Deterministic finite automata is a col ection of 5 tuples (Q, Σ. δ, q0, F )
where Q is a finite set of states, which is non empty.
Σ is a input alphabet, indicates input set.
δ is a transition function or a function def ine d for going to next state.
q0 is an initial state (q0 in Q)
F is a set of final states
34. Differentiate tokens, patterns, lexeme
Token: Token is a sequence of characters that can be treated as a single logical entity. Typical tokens are,
1) Identifiers 2) keywords 3) operators 4) special symbols 5)constants
Pattern: A set of strings in the input for which the same token is produced as output. This set of strings is
described by a rule called a pattern associated with the token.

Lexeme: A lexeme is a sequence of characters in the source program that is matched by the pattern for a
token

35. What are the various parts in LEX program?


declarations
%%
translation rules
%%
auxiliary procedures

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

37. Describe the language recognized by (aa/bb)*cc?


The set of all strings of which starts with aa or bb or may not be appear it must ends with cc

38. Define character class with example.


The notation [abc] where a, b, c are alphabet symbols denotes the regular expression a/b/c.
Example:
[A-z] = a | b | c | -------| z
Regular expression for identifiers using character classes
[a – z A – Z] [A – Z a – z 0 – 9] *

39. Define kleene closure or star closure ?


Star closure of L, denoted L*, is the set of those strings that can be formed by taking any number of
strings from L and concatenating all of them.
i
L* = L

40. What are the four functions of regular expression to DFA?


 Nullable (n)
 Firstpos (n)
 Last (n)
 Followpos (n)

41.Reg exp for the language that accepts all strings in which ‘a’ appears tripled overthe set Σ ={a}
reg exp=(aaa)*

42. What are the applications of pumping lemma?


Pumping lemma is used to check if a language is regular or not.
(i) Assume that the language(L) is regular.
(ii) Select a constant ‘n’.
(iii)Select a string(z) in L, such that |z|>n.
(iv)Split the word z into u,v and w such that |uv|<=n and |v|>=1.
(v)You achieve a contradiction to pumping lemma that there exists an ‘i’ Such that uvi
w is not in L.Then L is not a regular language.

43. What is the closure property of regular sets?


The regular sets are closed under union, concatenation and Kleene closure.
r1Ur2= r1 +r2

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)*

46.Lists on the closure properties of Regular sets.


(i) Union,(ii)Concatenation,(iii)Closure,(iv)Complementation,(v)Intersection,(vi)Transpose,(vii)Substitutions,
(viii)Homomorphism

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.

48. Show that (r*)*=r* for a regular expression r,


(r*)*=={ε,r,rr,………….}= r*

49. Differentiate regular expression and regular language.


1. Regular language
The set of regular languages over an alphabet is defined recursively as below. Any language belonging to
this set is a regular language over .
Definition of Set of Regular Languages :
Basis Clause: , {} and {a} for any symbol a are regular languages.
Inductive Clause: If Lr and Ls are regular languages, then Lr Ls , LrLs and Lr* are regular languages.
Extremal Clause: Nothing is a regular language unless it is obtained from the above two clauses.

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

2. Define ambiguous grammar? (May/June2016)


A CFG is said to ambiguous if there exists more than one derivation tree for the given input string i.e., more
than one LeftMost Derivation Tree (LMDT) or RightMost Derivation Tree (RMDT).

3. Construct a parser tree for -(id+id)? (Nov/Dec2016)


E → E + E | E * E | ( E ) | - E | id

4. What is meant by handle pruning? (Nov/Dec2016)


A rightmost derivation in reverse can be obtained by handle pruning.If w is a sentence of the grammar at
hand, then w = γn, where γn is the nth right-sentential form of some as yet unknown rightmost derivation
S = γ0 => γ1…=> γn-1 => γn = w

5. Eliminate the left recursion for the grammar A→Ac|Aad|bd (Apr/May2017)


A→βA’
A’→αA’|ε

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.

7. Draw syntax tree for the expression a=b*-c+b*-c (Nov/Dec2017)

8. What are the three storage allocation strategies? (Nov/Dec2017)


1. Static allocation - lays out storage for all data objects at compile time
2. Stack allocation - manages the run-time storage as a stack.
3. Heap allocation - allocates and deallocates storage as needed at run time from a data area known as heap.

9. Mention the types of LR parser.


 SLR parser- simple LR parser
 LALR parser- lookahead LR parser
 Canonical LR parser

10. What are the problems with top down parsing?


The following are the problems associated with top down parsing:
Backtracking
Left recursion
Left factoring
Ambiguity

11. What is a operator precedence parser?


A grammar is said to be operator precedence if it possess the following properties:
1. No production on the right side is ε.
2. There should not be any production rule possessing two adjacent non terminals at the right hand side.

12. List the advantages and disadvantages of operator precedence parsing.


Advantages
This typeof parsing is simple to implement.
Disadvantages
1. The operator like minus has two different precedence(unary and binary).Hence it is hard to
handle tokens like minus sign.
2. This kind of parsing is applicable to only small class of grammars.

13. What is dangling else problem?


Ambiguity can be eliminated by means of dangling-else grammar which is show below:
stmt → if expr then stmt
| if expr then stmt else stmt
| other

14. Write short notes on YACC.


YACC is an automatic tool for generating the parser program.
YACC stands for Yet Another Compiler Compiler which is basically the utility available from UNIX.
Basically YACC is LALR parser generator.It can report conflict or ambiguities in the form of error messages.
15. List the properties of LR parser.
1. LR parsers can be constructed to recognize most of the programming languages for which the context
free grammar can be written.
2. The class of grammar that can be parsed by LR parser is a superset of class of grammars that can be
parsed using predictive parsers.
3. LR parsers work using non backtracking shift reduce technique yet it is efficient one.

16. Define LR(0) items.


An LR(0) item of a grammar G is a production of G with a dot at some position of the right side. Thus,
production A → XYZ yields the four items
A→.XYZ
A→X.YZ
A→XY.Z
A→XYZ.

17. What is meant by 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. An equivalent definition of a viable prefix is that it is a prefix of a right sentential form that does
not continue past the right end of the rightmost handle of that sentential form.

18. Define handle.


A handle of a string is a substring that matches the right side of a production, and whose reduction to the
nonterminal on the left side of the production represents one step along the reverse of a rightmost derivation.
A handle of a right – sentential form γ is a production A→β and a position of γ where the string β may be found and
replaced by A to produce the previous right-sentential form in a rightmost derivation of γ. That is , if S =>αAw
=>αβw,then A→β in the position following α is a handle of αβw.

19. What are kernel & non-kernel items?


Kernel items, whish include the initial item, S'→ .S, and all items whose dots are not at the left end.
Non-kernel items, which have their dots at the left end.

20. What is phrase level error recovery?


Phrase level error recovery is implemented by filling in the blank entries in the predictive parsing table with
pointers to error routines. These routines may change, insert, or delete symbols on the input and issue appropriate
error messages. They may also pop from the stack.

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

23. What are the goals of error handler in a parser?


The error handler in a parser has simple-to-state goals:
 It should report the presence of errors clearly and accurately.
 It should recover from each error quickly enough to be able to detect subsequent errors.
 It should not significantly slow down the processing of correct programs.
24. What is phrase level error recovery?
On discovering an error, a parser may perform local correction on the remaining input; that is, it
may replace a prefix of the remaining input by some string that allows the parser to continue. This is known
as phrase level error recovery.

25. How will you define a context free grammar?


A context free grammar consists of terminals, non-terminals, a start symbol, and productions.
i. Terminals are the basic symbols from which strings are formed. “Token” is a synonym for terminal.
Ex: if, then, else.
ii. Nonterminals are syntactic variables that denote sets of strings, which help define the language
generated by the grammar. Ex: stmt, expr.
iii. Start symbol is one of the nonterminals in a grammar and the set of strings it denotes is the
language defined by the grammar. Ex: S.
iv. The productions of a grammar specify the manner in which the terminals and nonterminals can be
combined to form strings Ex: expr id

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.

27. Differentiate sentence and sentential form.

Sentence Sentential form


 If Sw then the string w is called  If S  then  is a sentential form of G.
Sentence of G.  Sentential form may contain non
 Sentence is a string of terminals. terminals.
Sentence is a sentential form with no
nonterminals.

28. Give the definition for leftmost and canonical derivations.


 Derivations in which only the leftmost nonterminal in any sentential form is replaced at each step are
termed leftmost derivations
 Derivations in which the rightmost nonterminal is replaced at each step are termed canonical
derivations.

29. What is a parse tree?


A parse tree may be viewed as a graphical representation for a derivation that filters out the choice
regarding replacement order. Each interior node of a parse tree is labeled by some nonterminal A and that
the children of the node are labeled from left to right by symbols in the right side of the production by
which this A was replaced in the derivation. The leaves of the parse tree are terminal symbols.

30. What is an ambiguous grammar? Give an example.


 A grammar that produces more than one parse tree for some sentence is said to be ambiguous
 An ambiguous grammar is one that produces more than one leftmost or rightmost derivation for the
same sentence.
Ex:
E E+E / E*E / id

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 AA for some
string.

33. Define left factoring.


Left factoring is a grammar transformation that is useful for producing a grammar suitable for
predictive parsing. The basic idea is that when it is not clear which of two alternative productions to use to
expand a nonterminal “A”, we may be able to rewrite the “A” productions to refer the decision until we
have seen enough of the input to make the right choice.

34. Left factor the following grammar:


S → iEtS | iEtSeS |a
E → b.

Ans:
The left factored grammar is,
S → iEtSS′ | a
S′ → eS | ε
E→b

35. What is parsing?


Parsing is the process of determining if a string of tokens can be generated by a grammar.

36. What is Top Down parsing?


Starting with the root, labeled, does the top-down construction of a parse tree with the starting nonterminal,
repeatedly performing the following steps.
i. At node n, labeled with non terminal “A”, select one of the productions for “A” and construct children
at n for the symbols on the right side of the production.
ii. Find the next node at which a sub tree is to be constructed.

37. What do you mean by Recursive Descent Parsing?


Recursive Descent Parsing is top down method of syntax analysis in which we execute a set of
recursive procedures to process the input. A procedure is associated with each nonterminal of a grammar.

38. What is meant by Predictive parsing?


A special form of Recursive Descent parsing, in which the look-ahead symbol unambiguously
determines the procedure selected for each nonterminal, where no backtracking is required.

39. Define Bottom Up Parsing.


Parsing method in which construction starts at the leaves and proceeds towards the root is called as
Bottom Up Parsing.

40. What is Shift-Reduce parsing?


A general style of bottom-up syntax analysis, which attempts to construct a parse tree for an input
string beginning at the leaves and working up towards the root.

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.

42. Define LR (0) items.


An LR (0) item of a grammar G is a production of G with a dot at some position of the right side.
Thus the production A → XYZ yields the following four items,
A → .XYZ
A → X.YZ
A → XY.Z
A → XYZ.

43. What is meant by an operator grammar? Give an example.


A grammar is operator grammar if,
i. No production rule involves “” on the right side.
ii. No production has two adjacent nonterminals on the right side..
Ex:
E → E+E | E-E | E*E | E/E | EE | (E) | -E | id

44. What are the disadvantages of operator precedence parsing?


i. It is hard to handle tokens like the minus sign, which has two different precedences.
ii. Since the relationship between a grammar for the language being parsed and the operator – precedence
parser itself is tenuous, one cannot always be sure the parser accepts exactly the desired language.
iii. Only a small class of grammars can be parsed using operator precedence techniques.

45. State error recovery in operator-Precedence Parsing.


There are two points in the parsing process at which an operator-precedence parser can discover the
syntactic errors:
i. If no precedence relation holds between the terminal on top of the stack and the current input.
ii. If a handle has been found, but there is no production with this handle as a right side.

46. What is meant by goto function in LR parser? Give an example.


 The function goto takes a state and grammar symbol as arguments and produces a state.
 The goto function of a parsing table constructed from a grammar G is the transition function of a
DFA that recognizes the viable prefixes of G.
Ex:
goto(I,X)
Where I is a set of items and X is a grammar symbol to be the closure of the set of all items [A→ X.]
such that [A→.X] is in I
47. What are kernel and non kernel items?
i. The set of items which include the initial item, SS, and all items whose dots are not at the
left end are known as kernel items.
ii. The set of items, which have their dots at the left end, are known as non kernel items.

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.

49. Define parser.


Hierarchical analysis is one in which the tokens are grouped hierarchically into nested collections with
collective meaning.Also termed as Parsing.

50. Mention the basic issues in parsing.


There are two important issues in parsing.
 Specification of syntax
 Representation of input after parsing.

51. Briefly explain the concept of derivation.


Derivation from S means generation of string w from S. For constructing derivation two things are
important.
i) Choice of non terminal from several others.
ii) Choice of rule from production rules for corresponding non terminal.
Instead of choosing the arbitrary non terminal one can choose
i) either leftmost derivation – leftmost non terminal in a sentinel form
ii) or rightmost derivation – rightmost non terminal in a sentinel form

52. Define a context free grammar.


A context free grammar G is a collection of the following
 V is a set of non terminals
 T is a set of terminals
 S is a start symbol
 P is a set of production rules
G can be represented as G = (V,T,S,P)
Production rules are given in the following form
Non terminal → (V U T)*

S-ar putea să vă placă și