Tag: CS-501

Ambiguity of S→SS|a|b

AnswerThe word aaa has two distinct leftmost derivations: S⇒SS⇒SSS⇒aSS⇒aaS⇒aaa (left grouping), and S⇒SS⇒aS⇒aSS⇒aaS⇒aaa (right grouping). Their trees group (aa)a and a(aa). Therefore…

Read more →

CFG generating integers

AnswerAssume decimal integers with optional sign and no leading zeros except zero. Use S→N|+N|-N; N→0|DT; D→1|2|3|4|5|6|7|8|9; T→ET|ε; E→0|D. This generates signed and…

Read more →