πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

Boolean expressions

Boolean expressions

Boolean expressions have two primary purposes. They are used for computing the logical values. They are also used as conditional expression using if-then-else or while-do.

Consider the grammar

  1. E  β†’  E OR E  
  2. E  β†’  E AND E  
  3. E  β†’  NOT E   
  4. E  β†’  (E)  
  5. E β†’  id relop id  
  6. E  β†’  TRUE  
  7. E  β†’  FALSE  

The relop is denoted by <, >, <, >.

The AND and OR are left associated. NOT has the higher precedence then AND and lastly OR.

Production ruleSemantic actions
E β†’ E1 OR E2{E.place = newtemp();
Emit (E.place ':=' E1.place 'OR' E2.place)
}
E β†’ E1 + E2{E.place = newtemp();
Emit (E.place ':=' E1.place 'AND' E2.place)
}
E β†’ NOT E1{E.place = newtemp();
 Emit (E.place ':=' 'NOT' E1.place)
}
E β†’ (E1){E.place = E1.place}
E β†’ id relop id2{E.place = newtemp();
 Emit ('if' id1.place relop.op id2.place 'goto'
 nextstar + 3);
 EMIT (E.place ':=' '0')
 EMIT ('goto' nextstat + 2)
 EMIT (E.place ':=' '1')
}
E β†’ TRUE{E.place := newtemp();
 Emit (E.place ':=' '1')
}
E β†’ FALSE{E.place := newtemp();
 Emit (E.place ':=' '0')
}

The EMIT function is used to generate the three address code and the newtemp( ) function is used to generate the temporary variables.

The E β†’ id relop id2 contains the next_state and it gives the index of next three address statements in the output sequence.

Here is the example which generates the three address code using the above translation scheme:

  1. p>q AND r<s OR u>r  

  2.      100: if p>q goto 103  
  3.      101: t1:=0  
  4.      102: goto 104  
  5.      103: t1:=1  
  6.      104: if r<s goto 107  
  7.      105: t2:=0  
  8.      106: goto 108  
  9.      107: t2:=1  
  10.      108: if u>v goto 111  
  11.      109: t3:=0  
  12.      110: goto 112  
  13.      111: t3:= 1  
  14.      112: t4:= t1 AND t2  
  15.      113: t5:= t4 OR t3  

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>