Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Compiler Design Sessional (Sec.

Y)
– G. Sarker

1. Write a Lexical Analyser with C language which only

performs lexical analysis of a subset of C language. The


subset language

uses the following keywords, identifiers, operators,


relational operators

and punctuation symbols:

a) keywords:

if, else, else if, switch, case, goto, while, do, for,
break, continue.

b) identifiers:

letter(letter|digit) * delimiter

c) arithmetic operators:

+, --, *, /, %

d) relational operators:

<, <=, >, >=, ==, !=


e) &&, ||, !

f) Assignment operators:

g) Increment and decrement operators:

++ , -- --

h) punctuation symbols:

“{“ , “}” “,” “;”

The output should be a stream of tokens with their type


mentioned. An unrecognizable token should be identified with
its position and error messages should be reported. Also
construct the symbol table to be displayed.

2. Implement a shift reduce parser whose input is a context


free grammar and the input sentence(s) and the output is the
sequence of productions to be used to reduce to the start
symbol.

3. Implement one Operator Precedence Parser assuming


conventional precedence of operators for the construction of
precedence table. Your parser would be able to convert input
grammar to operator grammar if required and if it is possible
to perform the conversion.

4. Implement one LL(1) parser with and without error


handling capacity. The grammar for the parser is fixed and the
input is/are the sentence(s) to be parsed and the output is
the sequence of productions used.

5. Implement one LR(0) parser without and with error


detection capacity. The input to the parser is the input
sentence to be parsed.(i) The grammar is for LR(0) parser is
fixed.(ii) The grammar for the LR(0) parser is another input
along with the input text.

6. Implement one Optimizer which would be able to perform:

i) folding

ii) constant propagation

iii) elimination of common sub expression

without and with the consideration of basic blocks.

_____________________________________________________________

You might also like