Compiler Design and Construction - Old Questions
Question Answer Details
3. What are regular definitions? Given the following CFG,
Write the regular definitions for
the terminals used. Also, construct the transition diagram for id and num.
Answer
AI Generated Answer
AI is thinking...
Official Answer
If Σ is an alphabet of basic symbols, then a regular definition is a sequence of definition of the form
d1 → r1
d2 → r2
.....
dn → rn
where, di is a distinct name and ri is a regular expression over symbols in Σ ∪ {d1, d2, ...., di-1}
Now,
Regular definitions for the terminals used in given grammar are:
digit → [0-9]
num → digit+(. digit+)?(E[+|-]? digit+)?
letter → [A-Za-z]
id → letter ( letter | digit )*
if → if
then → then
else → else
relop → < | > | <= | >= | = | <>
Transition diagram for id:
Here 9, 10 & 11 are the name of states.
Transition diagram for num: