Intermediate Code
![Question 43, GATE 2017: Grammar: stmt→if expr then expr else expr; stmt | δ; expr→term relop term | term; term→id | number; id→a|b|c; number→[0–9]. δ is the empty statement and relop a relational operator. A program contains ten if terminals. Find its number of control-flow paths, counting the two branches of one if as two paths.](../../assets/questions/CS-2017-S1-Q53-1.webp)
Answer & solution
Official answer: 1024.0
Our answer: 1024
1. The stmt grammar appends one if statement followed by another stmt. Thus ten if terminals describe ten sequential binary choices, not a nesting with an unspecified shape.
2. After the first if there are two structural paths. Each subsequent if doubles the existing path count because every current path can take either its then or else branch.
3. Therefore P0=1 and Pn=2Pn−1, giving P10=210=1024. This counts syntactic control-flow graph paths, as the question’s example does; repeated or constant conditions can make some paths infeasible for actual executions.