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

CS3005D Compiler Design

Quiz 1 - Evaluation Plan

1. Give a C language program fragment which will cause a lexical error during
lexical analysis. Justify your answer. (1 mark)
The use of any character (such as @, $ etc.) which is not defined by the C language
specifications will lead to a lexical error. Any code fragment containing such symbols is
an acceptable answer. Answers without proper justification will receive only 0.5 marks.

2. Give the sequence of tokens that will be identified by a C language lexical


analyzer for the following input. (2 marks)
a==1plus2
Four tokens will be generated by the lexical analyzer.

(a) ⟨IDEN T IF IER, pointer to symbol table entry f or a⟩


(b) ⟨RELOP, ==⟩
(c) ⟨IN T CON ST, 1⟩
(d) ⟨IDEN T IF IER, pointer to symbol table entry f or plus2⟩

Answers correctly identifying BOTH tokens (a) and (b) will be awarded 1 mark. Similarly,
answers correctly identifying BOTH tokens (c) and (d) will be awarded 1 mark.

3. An identifier in a language is specified as follows:

• First character is always a letter


• Remaining characters may be letters, digits or underscores
• Not more than 7 characters in length

Is it possible to recognize the above mentioned identifier using a transition


diagram? (Yes/No)
Yes
If yes, give the transition diagram for the same. If no, justify your answer. (2
marks)
There can be multiple transition diagrams possible. One possible solution is given. Here,
the symbols l, d and u represent letter, digit and underscore respectively.

l l,d,u l,d,u l,d,u l,d,u l,d,u l,d,u


start 0 1 2 3 4 5 6 7
otherother
other
otherotherother
8
*
Partial credit of 1 mark will be awarded if the answer correctly captures identifiers with
EXACTLY 7 characters.

You might also like