The Gateway to Computer Science Excellence
+19 votes
Write $3$ address intermediate code (quadruples) for the following boolean expression in the sequence as it would be generated by a compiler. Partial evaluation of boolean expressions is not permitted. Assume the usual rules of precedence of the operators.$$(a+b) > (c+d) \text{ or } a > c \text{ and }b < d$$
in Compiler Design by Veteran (105k points) | 823 views

2 Answers

+33 votes
Best answer

Each instruction in quadruples presentation is divided into four fields: operator, arg1, arg2, and result. The above example is represented below in quadruples format:

$(a+b)>(c+d)$ OR $a>c$ AND $b<d$

$(t1>t2)$ OR $a>c$ AND $b<d$

$t3$ OR $t4$ AND $t5$

$t3$ OR $t6$

$t1= a+b$

$t2= c+d$

$t3= t1>t2$

$t4= a>c$

$t5= b<d$

$t6= t4$ AND $t5$

$t7 =t3$ OR $t6$

\begin{array}{|l|l|l|l|} \hline \text{Op} & \text{arg1} & \text{arg2} & \text{Result} \\\hline \text {+} &  \text{a} &  \text{b} &  \text{t1} \\\hline \text {+} &  \text{c} &  \text{d} &  \text{t2}  \\\hline  \text {>} &  \text{t1} &  \text{t2} &  \text{t3} \\\hline \text {.>} &  \text{a} &  \text{c} &  \text{t4} \\\hline \text {<} &  \text{b} &  \text{d} &  \text{t5} \\\hline \text {AND} &  \text{t4} &  \text{t5} &  \text{t6} \\\hline \text {OR} &  \text{t3} &  \text{t6} &  \text{t7} \\\hline   \end{array}

by Boss (45.4k points)
edited by
+3 votes
quadruples consists of the 4-section they are operator, operand1, operand2, result

operator                 operand1           operand2                    result

+                               a                     b                              t1

+                               c                      d                             t2

>                               t1                     t2                            t3

>                                a                     c                             t4

<                               b                      d                             t5

and                            t4                    t5                             t6

or                              t3                     t6                            t7
by (443 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,321 answers
105,141 users