in Compiler Design retagged by
780 views
0 votes
0 votes
Consider the following grammar

$S \rightarrow SS/Sa/aS/a$

Construct Parse Tree for $w=aaaa$ as many as possible? How many parse trees are possible?
in Compiler Design retagged by
780 views

1 comment

reshown by
20 ?
0
0

1 Answer

0 votes
0 votes

Let f(n) be the number of ways to generate an. We have,

f(n) = $2*f(n-1)$  <-- due to the rule  S -> aS|Sa
       + $\sum_{i=1}^{n-1} f(i)*f(n-i)$ < --- due to the rule S -> SS

So, $f(n) = 2f(n-1)+\sum_{k=1}^{n-1} f(k)*f(n-k)$ with f(1) = 1

$\therefore f(2)=2f(1)+f(1)^2 = 3 \\ f(3) = 2f(2)+f(1)*f(2)+f(2)*f(1) = 12 \\ f(4) = 2f(3)+f(1)*f(3)+f(2)^2+f(3)*f(1) = 57$

edited by

1 comment

f(n) = 2∗f(n−1)  <-- due to the rule  S -> aS|Sa
       + ∑n−1i=1f(i)∗f(ni) < --- due to the rule S -> SS
 

How you came up with this part? Explain your thought process a little bit.

1
1