Compiler Design Assignment Compiler Design
Compiler Design Assignment Compiler Design
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)
• 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.
• 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.
The information should be stored in such a manner that one should be able to retrieve the following
capabilities:
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.
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.
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: