You are on page 1of 5

PARUL UNIVERSITY

FACULTY OF ENGINEERING &


TECHNOLOGY PIET/PIT
PRINCIPLES OF COMPILER (203105351)
Semester: 6th – CSE/IT/ICT
UNIT 1 & 2
Assignment -1

1. Draw structure of Compiler. Also explain Analysis Phase in brief.

Ans. The structure of compiler is as shown below

Analysis Phase:
Known as the front-end of the compiler, the analysis phase of the compiler reads the source
program, divides it into core parts and then checks for lexical, grammar and syntax errors.The
analysis phase generates an intermediate representation of the source program and symbol
table, which should be fed to the Synthesis phase as input.

190305105729 Page 1
2.Find the Regular Expression corresponding to given statement, subset of {l,d}* where l= letter
and d=digit.
1. The Language of all identifiers
2. The Language of all string constant in any programming language.
Ans. 1)(l+d)*
2)(d)*

3. How do the parser and scanner communicate? Explain with the block diagram
communication betweenthem.

Ans.

 The Lexical analyzer is the first phase of compiler.

 It’s main task is to read the input character and produce as output a sequence of tokens that
the parser uses for syntax analysis.

 The block diagram of communication between scanner and parser is given below

 Upon receiving a “get next token” command from parser, the lexical analyzer reads the
input characters until it can identify the next token.
4. Draw Transition diagram of unsigned integer and Keywords (for, while andif).

Ans. Transition diagram for unsigned integer.

Transition diagram for Keywords


5. Define: Ambiguous Grammar and problem due to left recursion to parse the string from
that grammar.

Ans.A grammar G is ambiguous if there is at least one string in L(G) having two or more distinct
derivation tree.

A grammar cannot be immediately left-recursive, but it still can be left-recursive.

By just eliminating the immediate left-recursion, we may not get a grammar which is not left-recursive.

S  Aa | b

A  Sc | d This grammar is not immediately left-recursive but it is still left-

recursive. S Aa Sca or

A Sc Aac causes to a left-recursion

So, we have to eliminate all left-recursions from our grammar.


6. Removal of left Recursion from the grammar
given below. S→Aa/Ab/c

Ans. No left recursion is present

You might also like