edited by
20,176 views
57 votes
57 votes

Consider the following grammar:

  • stmt $\rightarrow$ if expr then expr else expr; stmt | $Ò$
  • expr $\rightarrow$ term relop term | term
  • term $\rightarrow$ id | number
  • id $\rightarrow$ a | b | c
  • number $\rightarrow [0-9]$ 

where relop is a relational operator $($e.g., $< , >,\ldots),$ $Ò$ refers to the empty statement, and if, then, else are terminals. 
Consider a program $P$ following the above grammar containing ten if terminals. The number of control flow paths in $P$ is________ . For example. the program 
if $e_1$ then $e_2$ else $e_3$ 
has $2$ control flow paths. $e_1 \rightarrow e_2$ and $e_1 \rightarrow e_3$. 

edited by

11 Answers

8 votes
8 votes

people considering 2.2....=210  but tha happens when each 2 possiblity depends on the prevois possibility(counting rule---like topological sorting)

here for the Non-terminal expr no NESTING is done..

it will be like this..

for 3 if statement 

        every if statement is independent of previous one

so 20 should be the answer 

5 votes
5 votes

This might help.

 

3 votes
3 votes

Its a very late answer.

But still I am giving it, so that any others may be able to learn from this.

I too Initially thought answer is 20 & then understood how answer is 1024

2 votes
2 votes

For each statement there are Two Control Paths as given in the Question.

So, there will be two choices for the Same. 

IF e1 THEN e2 ELSE e3. (Paths:Either e2 or e3)

For total of 10 Statements it would be 2*2*2*2*...*2 (10 Times)

So, answer should Be 210.

Answer:

Related questions

20 votes
20 votes
7 answers
2
Arjun asked Feb 14, 2017
6,684 views
Consider the following grammar:$P\rightarrow xQRS$$Q\rightarrow yz\mid z$$R\rightarrow w\mid \varepsilon$$S\rightarrow y$What is FOLLOW($Q$)?$\left \{ R \right \}$ ...