Compiler Design Assignment Compiler Design

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

1.

“Symbol table is a data structure”- justify with respect to the different

implementation techniques, operations and information being stored.

Ans .

A symbol table is a data structure, where information about program objects is gathered.

• Used to store the information about the variables and their storages used in source program. Symbol
Table (name, information)

• Used in both the analysis and synthesis phases.

• The symbol table is built up during the lexical and syntactic analysis.

• A search is made to observe that the current name is appeared in the table earlier or not. If not, it is
entered into it during lexical and syntactic analysis.

• This information is used at various stages of compilation process e.g. semantic analysis, code
generation etc.

• It is an aid to detect the errors and simultaneous recover or correct those errors also.

Symbol Table Mechanisms

• Organizing the table- Information storage Various types of data structures linear lists, tree structure,
hash tables etc. may be used.

• Accessing values from table- Information access Efficient accessing methods and searching algorithms
are used as speed is an important issue.

Symbol Table Management

• It is essentially concerned with:

1. The symbol table’s storage structure.

2. Its construction in the analysis phase.


3. Its use during the whole compilation.

Symbol Table Management

The information should be stored in such a manner that one should be able to retrieve the following
capabilities:

1. An identifier or name is included in the table or not.

2. A name has to be added in the table.

3. The proper information is to be retrieved or accessed with respect to a name.

4. A new information is to be added with respect to a name.

5. Deleting a pair or groups of pairs of a table.

2. “The strictness of Chomsky classification of grammar increases from Type-0 to

Type-3”- comment using grammatical forms.

According to Chomsky hierarchy , grammars are divided of 4 types: 


Type 0 known as unrestricted grammar.
Type 1 known as context sensitive grammar.
Type 2 known as context free grammar.
Type 3 Regular Grammar.

Type 0: Unrestricted Grammar: 


In Type 0 
Type-0 grammars include all formal grammars. Type 0 grammar language are recognized by
turing machine. These languages are also known as the Recursively Enumerable languages. 
Grammar Production in the form of 
Alpha -> Beta
where 
alpha is ( V + T)* V ( V + T)* 
V : Variables 
T : Terminals. 
Beta is ( V + T )*. 
In type 0 there must be at least one variable on Left side of production. 

Type 1: Context Sensitive Grammar) 


Type-1 grammars generate the context-sensitive languages. The language generated by the
grammar are recognized by the Linear Bound Automata  
In Type 1 
I. First of all Type 1 grammar should be Type 0. 
II. Grammar Production in the form of 

Alpha -> Beta

| Alpha | <= |Beta| 

Type 2: Context Free Grammar: 


Type-2 grammars generate the context-free languages. The language generated by the
grammar is recognized by a Pushdown automata. Type-2 grammars generate the context-
free languages. 
In Type 2, 
1. First of all it should be Type 1. 
2. Left hand side of production can have only one variable. 
|Alpha| = 1. 
Their is no restriction on Beta

Type 3: Regular Grammar: 


Type-3 grammars generate regular languages. These languages are exactly all languages
that can be accepted by a finite state automaton. 
Type 3 is most restricted form of grammar. 
Type 3 should be in the given form only : 
V –> VT* / T*. 
(or) 
V –> T*V /T* 

3. Show that the bottom up parsing is right most derivation in reverse.


Ans.
In top down parser we traverse the parse tree from top to down and left to right and derive the
required string .In top down parser left most derivation is followed means when we are deriving
the string we always change the leftmost non terminal by terminals  with the help of given
production rules.

on the other hand in case of bottom up parser for a given string we replace terminals by non
terminals with the help of given production rules and finally reaches to start symbol.It follows
rightmost derivation in reverse order .In rightmost derivation we replace rightmost non terminals
by terminals.

4.  “Recursive Descent Parsing uses backtracking approach” – comment. 

Recursive Descent Parsing

Recursive descent is a top-down parsing technique that constructs the parse tree from the top
and the input is read from left to right. It uses procedures for every terminal and non-terminal
entity. This parsing technique recursively parses the input to make a parse tree, which may or
may not require back-tracking. But the grammar associated with it (if not left factored) cannot
avoid back-tracking. A form of recursive-descent parsing that does not require any back-
tracking is known as predictive parsing.
This parsing technique is regarded recursive as it uses context-free grammar which is
recursive in nature.

5. State the different cases of Thompson’s constructional formula. Convert the


following RE into corresponding NFA-Epsilon transition using the same:
(00+1) *(11+0)*

Ans. different cases of Thompson’s constructional formula are:


Case 1 − For a regular expression ‘a’, we can construct the following FA −
Case 2 − For a regular expression ‘ab’, we can construct the following FA −

Case 3 − For a regular expression (a+b), we can construct the following FA −

Case 4 − For a regular expression (a+b)*, we can construct the following FA −
6. What are the various stages of compilation? A statement in a language beingwritten, explain how the
different phases of the compiler performs theirresponsibility over it:

Ans .

the compilation process is a sequence of various phases. Each phase takes input from its
previous stage, has its own representation of source program, and feeds its output to the next
phase of the compiler.
7. Construct a DAG for the expression: (((a+a)+(a+a)) + ((a+a)+(a+a)))
8. Parse the input string: id + id * id using predictive parsing technique by constructing the parsing table
accordingly for the given grammar:

E->TE’ , E’->+TE’|€, T->FT’, T’->*FT’|€, F-> (E)/id


For the input string: id + id * id

You might also like