GateAI
Intermediate Code Generation

GATE CSE 2017 Set 1 · Q43

NAT2 marksEasy

Time

Consider the following grammar:stmt -> if expr then expr else expr; stmt | ò expr -> term relop term | term term -> id | number id -> a | b | c number -> [0-9]where relop is a relational operator (e.g., <, >, ...), ò refers to the empty statement, and if, then, else are terminals. Consider a program PP following the above grammar containing ten if terminals. The number of control flow paths in PP is __________. For example, the program if e_1 then e_2 else e_3 has 2 control flow paths, e1→e2e_1 \rightarrow e_2 and e1→e3e_1 \rightarrow e_3.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 1024 (±0)

Intermediate Code Generation

According to the grammar:

stmt→if expr then expr else expr; stmt∣oˋ\text{stmt} \rightarrow \text{if expr then expr else expr; stmt} \mid \text{ò}

A program PP with 1010 if terminals consists of 1010 sequential if-then-else statements executed one after the other.

For each statement:

if e1 then e2 else e3\text{if } e_1 \text{ then } e_2 \text{ else } e_3

there are 22 independent control flow paths (either the then branch e1→e2e_1 \rightarrow e_2 or the else branch e1→e3e_1 \rightarrow e_3).

Since these 1010 statements are sequential, the total number of control flow paths in the program is the product of the number of paths in each statement:

Total paths=210=1024\text{Total paths} = 2^{10} = 1024

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Intermediate Code Generation previous year question is Q43 of the GATE CSE 2017 Set 1 paper. Find more GATE CSE PYQs on Intermediate Code Generation in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Intermediate Code Generation PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Intermediate Code Generation in GATE CSE

Intermediate Code Generation has 14 GATE CSE PYQs across 12 papers from 2011 to 2025. 3 of them are 2-mark NAT questions like this one, and GATE CSE 2017 Set 1 has 3.

How GATE tests Intermediate Code Generation

More from GATE CSE 2017 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 1 · Q43 · NAT

Consider the following grammar: stmt -> if expr then expr else expr; stmt | ò expr -> term relop term | term term -> id | number id -> a | b | c number -> [0-9] where relop is a relational operator (e.g., <, >, ...), ò 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 e1 then e2 else e3 has 2 control flow paths, e1 → e2 and e1 → e3.

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.