GATE CSE 2017 Session 1 Q53: Number of control flow paths in a program with ten if-then-else statements
- Compiler Design
- 2 marks
- NAT
- No negative marking
Syllabus topic: Lexical analysis, parsing and syntax-directed translation
Question
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 following the above grammar containing ten if terminals. The number of control flow paths in is ______. For example, the program
if e1 then e2 else e3
has 2 control flow paths, and .
Try it: numerical answer: type the value
Show answer and explanation
Answer: 1024 (official GATE 2017 final answer key)
Concept used: The grammar only allows a sequence of if-then-else statements (no nesting, since branches are expressions), and each one independently doubles the number of paths.
First step: See that a program with ten if terminals is ten if-then-else statements one after another, each with 2 choices, and multiply.
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Lexical analysis, parsing and syntax-directed translation
Every PYQ on this topic →Share this question
Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Compiler Design PYQs
- 2026 Session 1 · Q27Classify errors in three C string declarations
- 2026 Session 1 · Q28True statements about LL(1) parsing
- 2026 Session 1 · Q42Redundant (common) subexpressions in blocks B4 and B5 of a CFG
- 2026 Session 1 · Q53Compare two SDDs for type declarations
- 2026 Session 2 · Q35Count tokens produced by a lexer for a given string
- 2026 Session 2 · Q41Shift-reduce conflicts in the LR(0) table of a grammar