-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcompiler-design-experiments.txt
81 lines (65 loc) · 3.33 KB
/
compiler-design-experiments.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
1. Write a C program that reads the following string:
“Md. Tareq Zaman, Part-3, 2011"
a) Count the number of words, letters, digits and other characters.
b) Separates letters, digits and other characters.
2. Write a program that reads the following string;
"Munmun is a student of Computer Science & Engineering"
a) Count how many vowels and Consonants are there?
b) Find out which vowels and consonants exist in the above string.
c) Divide the given string into two separate strings, where one string only contains the words starting with a vowel, and another contains the words starting with a consonant.
3. Write a program that abbreviates the following code:
CSE-3141 as Computer Science & Engineering, 3rd year, 1st semester, Compiler Design, Theory.
4. Build a lexical analyzer implementing the following regular expressions:
Integer variable =(i-nlN)(a-zA-Z0-9)*
Shomiint Number =7FS)(1-9)(0-9)1(1-9)(0-9)(0-9)1(1-9)(0-9)(0-9)(0-9)
Longlnt Number =(1-9)(0-9)(0-9)(0-9)(0-9)+
Invalid Input or Undefined = Otherwise
5. Build a lexical analyzer implementing the following regular expressions;
Float variable = (a-hA-Ho-zO-Z)(a-zA-Z0-9)*
Float Number = 0.(0-9)(0-9)|(1-9)(0-9)*.(0-9)(0-9)
Double Number = 0.(0-9)(0-9)(0-9)+|(1-9)(0-9)*.(0-9)(0-9)(0-9)+
Invalid Input or Undefined = Otherwise
6. Build a lexical analyzer implementing the following regular expressions:
Character variable =ch_(a-zA-Z0-9)(a-zA-Z0-9)*
Binary variable = bn_(a-zA-Z0-9)(a-zA-Z0-9)*
Binary Number =0(0|1)(0|1)*
Invalid Input or Undefined = Otherwise
7. Write a program to recognize C++
i) Keyword ii) Identifier iii) Operator iv) Constant
8. Write a program which converts a word of a C++ program to its equivalent token.
Input: 646.45 Output: Float Input: do
Output: Keyword
Input: 554
Output: Integer
Input: abc
Output: Identifier
Input: +
Output: Arithmetic Operator
9. Write a program that will check an English sentence given in the present indefinite form to justify whether it is syntactically valid or invalid according to the following Chomsky Normal Form:
S → SUB PRED
SUB → PN|P
PRED → VIV N
PN → Sagor | Selim | Salma | Nipu
P → he| she |1/ we | you | they
N → book | cow | dog | home | grass |rice |mango
V → read | eat | take | run | write
10. Write a program to implement a shift-reducing parsing.
11. Write a program to generate a syntax tree for the sentence a+b*c with the following grammar:
E → E+E|E-E|E*E|E/E|(E)lalblc
12. Write a program that checks the validity of C++ expression derived by the following grammar:
E → EAE|(E)|ID
A → +|-|*|/
ID → any valid identifier | any valid integer
Input: Enter a string: 2+3*5
Output: VALID
Input: Enter a string: 2+*3*5
Output: INVALID
13. Write a program to generate FIRST and FOLLOW sets using a given CFG.
14. Write a program to generate a FOLLOW set and parsing table using the following LL(1) grammar and FIRST set:
15. Write a program to generate a parse tree of the predictive parser using the following parsing.
16. Write a program that converts the C++ expression to an intermediate code of Post-fix notation form.
Input: (A-B)*(D/E)
Output: AB-DE*
17. Write a program that converts the C++ statement to an intermediate code of Post-fix notation form.
Input: Enter infix statement: if a then if c-d then atc else a*c else a+b
Output: Postfix: acd-ac +ac*?ab+?