845 views
2 2 votes

How to get the second string,i.e., 6*2/1-2*3 from the given grammar?

1 Answer

0 0 votes
More away from the Start symbol, Higher the precedence.

Here, $B\rightarrow C/b_{1}$ is 2 levels down from Start symbol

and $a\rightarrow A_{1} - B$ is 1 level away from start symbol, which clears that ' / ' has higher precedence than ' - ' and ' * '.

$So, / > - > *$

$a_{1} = 8/4 * 2 - 6*4; \\ = ( (8/4)*(2-6)*4);$

But as per first grammer, Multiplacation prints addition of two numbers. Therefore

$a_{1} = (2 + (-4) + 4) = 2;$

and, similarly $a_{2} = 6*2/1-2*3; \\ (6*((2/1)-2)*3); i.e. (6 +0 + 3) = 9$

Now, $a_{1} - a_{2} = 2 - 9 \\  = -7$
Position:
Show:

Related questions

9 9 votes
2 2 answers
1.5k
1.5k views
gatecse asked Feb 23
1,492 views
​​​​​​Consider the following two syntax-directed definitions $\text{SDD1}$ and $\text{SDD2}$ for type declarations. SDD1Grammar (G1)Semantic Rules$D \rightarrow T\ V$$D.t...
2 2 votes
1 answers 1 answer
730
730 views
Wren Oswin asked Oct 23, 2025
730 views
Consider the following SDT:S - T RR - {printf("*")} + T {printf("*")} R {printf("+")}T - num {printf("*")}R - ε {printf("+")}How many * will be printed before the first +...
0 0 votes
2 2 answers
345
345 views
Shubham Sharma 2 asked Sep 10, 2025
345 views
Match the $\textbf{LIST-I}$ with $\textbf{LIST-II}$$\begin{array}{|l|l|l|l|} \hline & \textbf{ LIST-I } & & \textbf{ LIST-II } \\ \hline \text{A.} & \text{Conflict Resol...