0% found this document useful (0 votes)
36 views

Compiler Design-Assignment-1

Compiler Design
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Compiler Design-Assignment-1

Compiler Design
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Computer Science & Engineering

Compiler Design (TCS-601), B. Tech., CSE, 6th Semester, Sec-D,E,P,Q,R,S


Assignment #01/ Date of issue: 28-March-2024 / Submission Due- 10-April-2024
Instructions:
 ANSWER NEATLY AND LEGIBLY on A4 sheets if available.
 Sketch diagrams wherever relevant. Explain your notations explicitly and clearly.
 An incomplete assignment is NOT acceptable for submission.
 Once you submit your assignment, you will be expected to answer all the questions there
INDEPENDENTLY.
 Page number your answer sheets sequentially.
 On the top of your fist sheet, write your Name, Year, Section, Roll Number, Due Date and
Date of Submission.

Q1. Consider the given grammars.


(i) (ii) (iii) (iv)
S → ABCD S → ABCDh S → aABb S → aBDh
A → a/epsilon A→a A → c/epsilon B → cC
B → b/epsilon B→b B → d/epsilon C → bC/epsilon
C→c C→c D → EF
D → d/epsilon D → d/epsilon E → g/epsilon
F → f/epsilon
For the above grammars, Compute FIRST() and FOLLOW() set.

Q2. Consider the following grammar

(1) (2) (3) (4) (5)


S → dA/aB S → A/a S → (L)/a E → E+T/T S →AaAb/BbBa
A → bA/c A→a L → L,S/S T→d A → epsilon
B → bB/c B → epsilon
(6) (7) (8) (9)
E → T+E/T E → E+T/T S → AS/b S → Aa/bAC/dC/bda
T→d T → T*F/F A → SA/a A→d
F → id
To verify, whether the above grammars are:
1- LL(1) or not
2- LR(0) or not
3- SLR(1) or not
4- CLR(1) or not
5- LALR(1) or not
Q3. Consider the following grammar:

E → E + E| E * E | id

Construct the parse tree for the above grammar using LMD for the given string id + id + id + id * id

Q4. Explain tokens with their types. Identify the types of tokens in the following code segment.

int a=10, b=20;


int c=a+b;

Q5. Construct a DFA over the input alphabet Σ= {a, b} for the following:

(i) Each string starts with “a” and ends with “b”.
(ii) Set of all even length strings.
(iii) Set of all odd length strings.
(iv) String length is exactly 2.
(v) String length is at least 2.
(vi) String length is at most 2.
(vii) Each string ends with “bb”
(viii) Set of all length strings including zero length.

Q6. Define Operator precedence parser with suitable example.


Q7. Consider the following grammar
A → A + B|B
B → B * C| C
C → (A) | id
To check whether the above grammar is left recursive or not? If yes then remove the left recursion
from the grammar productions.
Q8. What do you understand by Grammar? Define context free grammar with the help of suitable
example.
Q9. What do you understand by cousins of Compiler? Explain each with appropriate example.
Q10. Explain input buffering. Differentiate between one buffer and two buffer scheme with suitable
example.
Q11. Consider the following grammar.
S → aSa|bSb|e
Construct the derivation/ parse tree for the given string “abbebba”
Q12. Define ambiguity in the grammar. Explain left recursive and non-deterministic grammar with
suitable example.
Q13. Explain the following:
(i) Lexeme
(ii) Pattern
(iii) Regular Expression
(iv) LEX
(v) Symbol Table
(vi) Error Handler
(vii) Interpreter
(viii) Top down and Bottom up parsing
(ix) Left most derivation
(x) Right most derivation
Q14. Consider the given grammar.
S → aSbS|bSaS|epsilon
To verify whether the given string “abababab” is derivable from the grammar or not?
Q15. . Consider the given grammar.
S → aS|Sa|a
For the given string “aa” to check whether the given grammar is ambiguous or not?

:::::::::::::::::::::::::::::::::::::Submission Date: 10/April/2024:::::::::::::::::::::::::::::::::::::::::::::

Note- The respective class CR will submit the assignment to me with the list of students who submit
the assignment. Kindly refer the below format for the same.
S. No Class Roll No Student Name Date of Submission
1 1 A 10-April-24
2 2 B
3 3 C

You might also like