{"id":206,"date":"2018-07-20T06:37:48","date_gmt":"2018-07-20T06:37:48","guid":{"rendered":"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=206"},"modified":"2018-07-20T06:43:54","modified_gmt":"2018-07-20T06:43:54","slug":"arrays-and-boolean-expressions","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/chapter\/arrays-and-boolean-expressions\/","title":{"rendered":"Arrays and Boolean Expressions"},"content":{"raw":"<div>\r\n<p style=\"text-align: justify\">In this module we will learn to write semantic rules for arrays to generate three address code. We will also take a first look at the semantic rules for generating three-address code for Boolean expressions.<\/p>\r\n&nbsp;\r\n\r\n<strong>24.1 Semantic rules for Arrays<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Arrays operation is part of any programming language. Arrays are typically used whenever a sequence of contiguous memory locations is required statically. Multi-dimension information is typically stored in arrays and hence accessing such multi-dimension array in a faster way becomes essential. This necessitates defining semantic rules for the arrays to generate three address code which will in-turn help faster access of an element in a multi-dimensional array. The following is the grammar for declaring arrays in Pascal. Let us consider this grammar to write semantic rules that generates three-address code for the arrays.<\/p>\r\n&nbsp;\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S \u00e0 L : = E \u2013 Assignment of expressions to include arrays. L is the variable to declare arrays.\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 E \u00e0 E + E | (E) \u2013 This is a simple expression where the operator is addition or parenthesis that defines precedence of an expression\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 E \u00e0 L \u2013 The RHS of the first production could also be an array variable and this production helps define a multi-dimensional array\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 L \u00e0 Elist] \u2013 This production closes an array dimension\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 L \u00e0 id \u2013 The expression RHS \/ LHS can be a single variable as in this or could be an array variable.\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 Elist \u00e0 Elist, E \u2013 This production is used to create multi-dimension arrays\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Elist \u00e0 id [ E \u2013 This is the beginning of the array variable declaration where \u2018id\u2019 is the name of the array.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The array variable L has two attributes: place and offset. The attribute \u201cplace\u201d is a pointer to temporary variable or any address while \u201coffset\u201d is to move through the array index. We have discussed the row-major and column- major ways of accessing the arrays in the previous module. Based on that, an n-dimension array can be generalized using the recursive expression defined as follows:<\/p>\r\n&nbsp;\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 em = em-1\u00a0 + im\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 e1 = i1\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">em refers to the mth dimension computation of address given the (m-1)th dimension. This is computed by knowing the address of the first dimension. After understanding the address computation to access the elements of a multi-dimensional array, the addresses are computing by defining the following functions. These functions are used to define the semantic rules to generate three-address code that will help access the array element:<\/p>\r\n\r\n<ul>\r\n \t<li>Elist.ndim \u2013 This is used to record the number of dimensions in the Elist<\/li>\r\n \t<li>limit(array, j) \u2013 This function returns the number of elements nj in the jth dimension of the array<\/li>\r\n \t<li>Elist.place \u2013 This is used to temporarily hold a value from index expression<\/li>\r\n<\/ul>\r\nExample 24.1 Let us see how to generate three-address code to access an array element. Consider the example with a two-dimension array\r\n\r\n&nbsp;\r\n\r\nA : array [1..2,1..3] of integer;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Thus array A is a 2 x 3 array having two rows and three columns. Assume that this array is accessed in row- major manner. The following is what we would expect as the output given the request to access an element <strong>A[i,j].<\/strong><\/p>\r\n&nbsp;\r\n\r\nt1 := i * 3 - columns of a row would be incremented before going to the next row and this is stored in a temporary variable.\r\n\r\nt1 := t1 + j \u2013 accesses the jth\u00a0 column after completing i rows\r\n\r\nt2 := c- base address is the address of the first element of the array\r\n\r\n&nbsp;\r\n\r\nt3 := t1 * 4 \u2013 size of integer is 4 bytes which is the offset necessary from the base address\r\n\r\n&nbsp;\r\n\r\nt4 := t2[t3] \u2013 base address t2 is offset by t3\r\n<ul>\r\n \t<li>\u2026 := t4 \u2013 t4 has the address to fetch the array element<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">The above three-address code is based on the following set of equations as already discussed in Module 23.<\/p>\r\n&nbsp;\r\n\r\n<em>Address = base<\/em><strong>A<\/strong> + ((<em>i<\/em>1 -<em> low<\/em>1) *<em> n<\/em>2 +<em> i<\/em>2 -<em> low<\/em>2)<em> * w<\/em>\r\n<ul>\r\n \t<li>= ((<em>i<\/em>1 * <em>n<\/em>2) <em>+ i<\/em>2) * <em>w<\/em> + <em>c<\/em><\/li>\r\n<\/ul>\r\n<strong><em>where <\/em><\/strong><em>c = base<\/em><strong>A<\/strong> <em>- <\/em>((<em>low<\/em>1 <em>* n<\/em>2) + <em>low<\/em>2) * <em>w<\/em>\r\n\r\n<strong><em>with <\/em><\/strong><em>low<\/em>1 <em>= <\/em>1; <em>low<\/em>2 <em>= <\/em>1; <em>n<\/em>2 <em>= <\/em>3; <em>w = <\/em>4\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The semantic rules for generating three-address code for arrays is given in Table 24.1. The array variable \u2018L\u2019 has two attributes: offset and place. \u2018offset\u2019 refers to the shift that is necessary from the base address to compute the address of an element and \u2018place\u2019 refers to the temporary variable which will be used to offset.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-208 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119.png\" alt=\"\" width=\"660\" height=\"884\" \/>\r\n\r\n<img class=\"size-full wp-image-210 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120.png\" alt=\"\" width=\"673\" height=\"917\" \/>\r\n\r\nThe content is fetched from t3 by offsetting from the base address which is available at t2, which results in the following\r\n\r\n&nbsp;\r\n<ul>\r\n \t<li style=\"text-align: justify\">t4 := t2 [t3]\u00a0 \u00a0This value is the RHS of the input and this is finally assigned to the LHS variable \u2018x\u2019 as follows:<\/li>\r\n \t<li style=\"text-align: justify\">x := t4\u00a0 Thus, using the semantic rules, any \u2018n\u2019 dimension array could be accessed by computing the corresponding address.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0In addition to the semantic rules for arrays, type conversions are also part of them. These type conversions are similar to the ones discussed in the previous modules. As an example, consider the production<\/p>\r\n&nbsp;\r\n<ul>\r\n \t<li>E \u00e0 E1 + E2\u00a0 The corresponding semantic rule to set the type of the LHS variable E is given below<\/li>\r\n<\/ul>\r\n{E.type = if E1.type = int &amp; E2.type = int then int; else real}\r\n\r\n&nbsp;\r\n\r\nE.place = newtemp ();\r\n\r\n&nbsp;\r\n\r\nIf E1.type = int and E2.type = int emit (E.place \u2018:=\u2018 E1.place \u2018int +\u2019 E2.place)\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The first statement assigns the type to E and the subsequent statements are used to generate three-address code which is exactly similar to the rules discussed in the previous modules.<\/p>\r\n&nbsp;\r\n\r\n<strong>24.2 Boolean expressions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Logical values need to be computed to control the flow of statements. An expression is evaluated using relational operators, \u201c&lt;, &gt;, &lt;=, &gt;=, ==, !=\u201d. A particular branch instruction might take multiple branches and this is controlled by computing a logical value using the Boolean operators, \u201cand\u201d, \u201cor\u201d and \u201cnot\u201d.<\/p>\r\n<img class=\"size-full wp-image-211 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121.png\" alt=\"\" width=\"654\" height=\"539\" \/>\r\n\r\n&nbsp;\r\n\r\nConsider the following expression involving relational and Boolean operators:\r\n\r\n&nbsp;\r\n\r\na &lt; b or c &lt; d and e &lt; f\r\n\r\nThis could be derived as follows:\r\n\r\n&nbsp;\r\n\r\nE =&gt; E1 or E2 =&gt; E1 or E4 and E3 =&gt; a &lt; b or c &lt; d and e &lt; f.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Thus the string is derived by giving priority to \u201cand\u201d before executing \u201cor\u201d. Thus E4 and E3 need to be computed before computing E1 or E2. However, this is not handled in the semantic rules discussed earlier. The expression is evaluated and the corresponding \u2018goto\u2019 will take care of branching according to the \u2018true\u2019 or the \u2018false\u2019 of the expression.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-212 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122.png\" alt=\"\" width=\"649\" height=\"669\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>24.3 Short circuit code<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Boolean expression could generate three-address code without generating full code. The expression need not be evaluated in full. For example, if there are two expressions E1 and E2, and if it is connected using the \u2018or\u2019 operator, then if E1 is true then E2 need not be evaluated and thus no code need to be generated. A more detailed explanation of this will be discussed in the next module.<\/p>\r\n&nbsp;\r\n\r\n<strong>Summary:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This module discussed the three-address code for arrays and the semantic rules that are used to generate the three-address code for multi-dimensional arrays. In this module, the semantic rules that are used for generating three-address code for Boolean expressions involving Boolean and Relational operators are also discussed. Subsequent modules will discuss a better way of generating three-address code for Boolean expressions<\/p>","rendered":"<div>\n<p style=\"text-align: justify\">In this module we will learn to write semantic rules for arrays to generate three address code. We will also take a first look at the semantic rules for generating three-address code for Boolean expressions.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>24.1 Semantic rules for Arrays<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Arrays operation is part of any programming language. Arrays are typically used whenever a sequence of contiguous memory locations is required statically. Multi-dimension information is typically stored in arrays and hence accessing such multi-dimension array in a faster way becomes essential. This necessitates defining semantic rules for the arrays to generate three address code which will in-turn help faster access of an element in a multi-dimensional array. The following is the grammar for declaring arrays in Pascal. Let us consider this grammar to write semantic rules that generates three-address code for the arrays.<\/p>\n<p>&nbsp;<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S \u00e0 L : = E \u2013 Assignment of expressions to include arrays. L is the variable to declare arrays.<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 E \u00e0 E + E | (E) \u2013 This is a simple expression where the operator is addition or parenthesis that defines precedence of an expression<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 E \u00e0 L \u2013 The RHS of the first production could also be an array variable and this production helps define a multi-dimensional array<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 L \u00e0 Elist] \u2013 This production closes an array dimension<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 L \u00e0 id \u2013 The expression RHS \/ LHS can be a single variable as in this or could be an array variable.<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 Elist \u00e0 Elist, E \u2013 This production is used to create multi-dimension arrays<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Elist \u00e0 id [ E \u2013 This is the beginning of the array variable declaration where \u2018id\u2019 is the name of the array.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The array variable L has two attributes: place and offset. The attribute \u201cplace\u201d is a pointer to temporary variable or any address while \u201coffset\u201d is to move through the array index. We have discussed the row-major and column- major ways of accessing the arrays in the previous module. Based on that, an n-dimension array can be generalized using the recursive expression defined as follows:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 em = em-1\u00a0 + im<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0 e1 = i1<\/p>\n<\/div>\n<p style=\"text-align: justify\">em refers to the mth dimension computation of address given the (m-1)th dimension. This is computed by knowing the address of the first dimension. After understanding the address computation to access the elements of a multi-dimensional array, the addresses are computing by defining the following functions. These functions are used to define the semantic rules to generate three-address code that will help access the array element:<\/p>\n<ul>\n<li>Elist.ndim \u2013 This is used to record the number of dimensions in the Elist<\/li>\n<li>limit(array, j) \u2013 This function returns the number of elements nj in the jth dimension of the array<\/li>\n<li>Elist.place \u2013 This is used to temporarily hold a value from index expression<\/li>\n<\/ul>\n<p>Example 24.1 Let us see how to generate three-address code to access an array element. Consider the example with a two-dimension array<\/p>\n<p>&nbsp;<\/p>\n<p>A : array [1..2,1..3] of integer;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Thus array A is a 2 x 3 array having two rows and three columns. Assume that this array is accessed in row- major manner. The following is what we would expect as the output given the request to access an element <strong>A[i,j].<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>t1 := i * 3 &#8211; columns of a row would be incremented before going to the next row and this is stored in a temporary variable.<\/p>\n<p>t1 := t1 + j \u2013 accesses the jth\u00a0 column after completing i rows<\/p>\n<p>t2 := c- base address is the address of the first element of the array<\/p>\n<p>&nbsp;<\/p>\n<p>t3 := t1 * 4 \u2013 size of integer is 4 bytes which is the offset necessary from the base address<\/p>\n<p>&nbsp;<\/p>\n<p>t4 := t2[t3] \u2013 base address t2 is offset by t3<\/p>\n<ul>\n<li>\u2026 := t4 \u2013 t4 has the address to fetch the array element<\/li>\n<\/ul>\n<p style=\"text-align: justify\">The above three-address code is based on the following set of equations as already discussed in Module 23.<\/p>\n<p>&nbsp;<\/p>\n<p><em>Address = base<\/em><strong>A<\/strong> + ((<em>i<\/em>1 &#8211;<em> low<\/em>1) *<em> n<\/em>2 +<em> i<\/em>2 &#8211;<em> low<\/em>2)<em> * w<\/em><\/p>\n<ul>\n<li>= ((<em>i<\/em>1 * <em>n<\/em>2) <em>+ i<\/em>2) * <em>w<\/em> + <em>c<\/em><\/li>\n<\/ul>\n<p><strong><em>where <\/em><\/strong><em>c = base<\/em><strong>A<\/strong> <em>&#8211; <\/em>((<em>low<\/em>1 <em>* n<\/em>2) + <em>low<\/em>2) * <em>w<\/em><\/p>\n<p><strong><em>with <\/em><\/strong><em>low<\/em>1 <em>= <\/em>1; <em>low<\/em>2 <em>= <\/em>1; <em>n<\/em>2 <em>= <\/em>3; <em>w = <\/em>4<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The semantic rules for generating three-address code for arrays is given in Table 24.1. The array variable \u2018L\u2019 has two attributes: offset and place. \u2018offset\u2019 refers to the shift that is necessary from the base address to compute the address of an element and \u2018place\u2019 refers to the temporary variable which will be used to offset.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-208 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119.png\" alt=\"\" width=\"660\" height=\"884\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119.png 660w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119-224x300.png 224w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119-65x87.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119-225x301.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-119-350x469.png 350w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-210 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120.png\" alt=\"\" width=\"673\" height=\"917\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120.png 673w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120-220x300.png 220w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120-65x89.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120-225x307.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-120-350x477.png 350w\" sizes=\"auto, (max-width: 673px) 100vw, 673px\" \/><\/p>\n<p>The content is fetched from t3 by offsetting from the base address which is available at t2, which results in the following<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"text-align: justify\">t4 := t2 [t3]\u00a0 \u00a0This value is the RHS of the input and this is finally assigned to the LHS variable \u2018x\u2019 as follows:<\/li>\n<li style=\"text-align: justify\">x := t4\u00a0 Thus, using the semantic rules, any \u2018n\u2019 dimension array could be accessed by computing the corresponding address.<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0In addition to the semantic rules for arrays, type conversions are also part of them. These type conversions are similar to the ones discussed in the previous modules. As an example, consider the production<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>E \u00e0 E1 + E2\u00a0 The corresponding semantic rule to set the type of the LHS variable E is given below<\/li>\n<\/ul>\n<p>{E.type = if E1.type = int &amp; E2.type = int then int; else real}<\/p>\n<p>&nbsp;<\/p>\n<p>E.place = newtemp ();<\/p>\n<p>&nbsp;<\/p>\n<p>If E1.type = int and E2.type = int emit (E.place \u2018:=\u2018 E1.place \u2018int +\u2019 E2.place)<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The first statement assigns the type to E and the subsequent statements are used to generate three-address code which is exactly similar to the rules discussed in the previous modules.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>24.2 Boolean expressions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Logical values need to be computed to control the flow of statements. An expression is evaluated using relational operators, \u201c&lt;, &gt;, &lt;=, &gt;=, ==, !=\u201d. A particular branch instruction might take multiple branches and this is controlled by computing a logical value using the Boolean operators, \u201cand\u201d, \u201cor\u201d and \u201cnot\u201d.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-211 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121.png\" alt=\"\" width=\"654\" height=\"539\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121.png 654w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121-300x247.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121-65x54.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121-225x185.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-121-350x288.png 350w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Consider the following expression involving relational and Boolean operators:<\/p>\n<p>&nbsp;<\/p>\n<p>a &lt; b or c &lt; d and e &lt; f<\/p>\n<p>This could be derived as follows:<\/p>\n<p>&nbsp;<\/p>\n<p>E =&gt; E1 or E2 =&gt; E1 or E4 and E3 =&gt; a &lt; b or c &lt; d and e &lt; f.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Thus the string is derived by giving priority to \u201cand\u201d before executing \u201cor\u201d. Thus E4 and E3 need to be computed before computing E1 or E2. However, this is not handled in the semantic rules discussed earlier. The expression is evaluated and the corresponding \u2018goto\u2019 will take care of branching according to the \u2018true\u2019 or the \u2018false\u2019 of the expression.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-212 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122.png\" alt=\"\" width=\"649\" height=\"669\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122.png 649w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122-291x300.png 291w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122-65x67.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122-225x232.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-122-350x361.png 350w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>24.3 Short circuit code<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Boolean expression could generate three-address code without generating full code. The expression need not be evaluated in full. For example, if there are two expressions E1 and E2, and if it is connected using the \u2018or\u2019 operator, then if E1 is true then E2 need not be evaluated and thus no code need to be generated. A more detailed explanation of this will be discussed in the next module.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This module discussed the three-address code for arrays and the semantic rules that are used to generate the three-address code for multi-dimensional arrays. In this module, the semantic rules that are used for generating three-address code for Boolean expressions involving Boolean and Relational operators are also discussed. Subsequent modules will discuss a better way of generating three-address code for Boolean expressions<\/p>\n","protected":false},"author":4,"menu_order":24,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-rajeswari-sridhar"],"pb_section_license":""},"chapter-type":[],"contributor":[59],"license":[],"class_list":["post-206","chapter","type-chapter","status-publish","hentry","contributor-dr-rajeswari-sridhar"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":3,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/206\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/206\/revisions\/213"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/206\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/media?parent=206"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapter-type?post=206"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/contributor?post=206"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/license?post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}