Log In
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 1.4k views

2 Answers

37 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}

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

Related questions

11 votes
1 answer
Write syntax directed definitions (semantic rules) for the following grammar to add the type of each identifier to its entry in the symbol table during semantic analysis. Rewriting the grammar is not permitted and semantic rules are to be added to the ends of productions only. $D \rightarrow TL;$ $T \rightarrow \text{int}$ $T \rightarrow \text{real}$ $L \rightarrow L,id$ $L \rightarrow id$
asked Sep 13, 2014 in Compiler Design Kathleen 1.4k views
13 votes
1 answer
Mention the pass number for each of the following activities that occur in a two pass assembler: object code generation literals added to literal table listing printed address resolution of local symbols
asked Sep 13, 2014 in Compiler Design Kathleen 2.3k views
5 votes
1 answer
Write short answers to the following: (i). Which of the following macros can put a macro assembler into an infinite loop? .MACRO MI,X .IF EQ,X M1 X+1 .ENDC .IF NE,X .WORD X .ENDC .ENDM .MACRO M2,X .IF EQ,X M2 X .ENDC .IF NE,X .WORD X+1 .ENDC .ENDM Give an example call that does so.
asked Sep 13, 2014 in Compiler Design Kathleen 708 views