402 views
1 1 vote

Consider the intermediate code given below:
 

(1) i = 0
(2) sum = 0
(3) t1 = i * 4
(4) sum = sum + t1
(5) i = i + 1
(6) if i < 10 goto (3)
(7) return sum

The number of nodes and edges in the control-flow graph constructed for the above code, respectively, are:

  1. $4$ AND $5$
     
  2. $4$ AND $4$
     
  3. $5$ AND $5$
     
  4. $5$ AND $6$

2 Answers

0 0 votes

Identify Leaders:

  • Statement $(1)$ is a leader (start).
     
  • Statement $(3)$ is a leader (target of a jump).
     
  • Statement $(7)$ is a leader (statement following a jump).
     

Basic Blocks (BB):

  • $\mathbf{B1}: (1)-(2)$
     
  • $\mathbf{B2}: (3)-(6)$
     
  • $\mathbf{B3}: (7)$
     

Nodes: $3$ Basic Blocks $+ 1$ Start $+ 1$ End $= \mathbf{5}$ NODES
 

Edges: * Start → $\mathbf{B1}(1)$

  • $\mathrm{B1} \rightarrow \mathrm{B2}(1)$
     
  • $\mathrm{B2} \rightarrow \mathrm{B2} ~($loop back$) ~(1)$
     
  • $\mathrm{B2} \rightarrow \mathrm{B3} ~($exit loop$) ~(1)$
     
  • $\mathrm{B3} \rightarrow$ End $(1)$
     
  • Total $= \textbf{5}$ EDGES
Answer:
Position:
Show:

Related questions

2 2 votes
2 2 answers
294
294 views
GO Classes asked Jan 5
294 views
Consider the intermediate code given below:(1) x = 10 (2) if x 0 goto (5) (3) x = x + 1 (4) goto (6) (5) x = x - 1 (6) y = xThe number of nodes and edges in the control-...
3 3 votes
2 2 answers
345
345 views
GO Classes asked Jan 5
345 views
Consider the following snippet of a specialized programming language:printf("Result: %d\n", x+++ y); // Process result /* Update count count = count * 2; */the number...
2 2 votes
4 4 answers
448
448 views
GO Classes asked Jan 5
448 views
Consider the following grammar:$(1) ~S \rightarrow a A b$$(2) ~A \rightarrow a A b$$(3) ~A \rightarrow c$ The number of reduction steps taken by a bottom-up parser while ...
3 3 votes
3 3 answers
376
376 views
GO Classes asked Jan 5
376 views
A canonical set of items in an $\operatorname{LR}(0)$ parser is given below:$(1) ~E \rightarrow T .+E$$(2) ~F \rightarrow T$.$(3) ~T \rightarrow i d$On input symbol $+$, ...