πŸŽ“ 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

Statements that alter the flow of control

Statements that alter the flow of control

The goto statement alters the flow of control. If we implement goto statements then we need to define a LABEL for a statement. A production can be added for this purpose:

  1. S β†’     LABEL : S  
  2.     LABEL β†’     id  

In this production system, semantic action is attached to record the LABEL and its value in the symbol table.

Following grammar used to incorporate structure flow-of-control constructs:

  1. S β†’  if E then S  
  2.      S  β†’   if E then S else S  
  3.      S β†’    while E do S  
  4.      S β†’    begin L end  
  5.      Sβ†’     A  
  6.      Lβ†’    L ; S  
  7.      L β†’   S  

Here, S is a statement, L is a statement-list, A is an assignment statement and E is a Boolean-valued expression.

Translation scheme for statement that alters flow of control

  • We introduce the marker non-terminal M as in case of grammar for Boolean expression.
  • This M is put before statement in both if then else. In case of while-do, we need to put M before E as we need to come back to it after executing S.
  • In case of if-then-else, if we evaluate E to be true, first S will be executed.
  • After this we should ensure that instead of second S, the code after the if-then else will be executed. Then we place another non-terminal marker N after first S.

The grammar is as follows:

  1. S β†’   if E then M S  
  2.      S β†’    if E then M S else M S  
  3.      S β†’    while M E do M S  
  4.      S β†’    begin L end  
  5.      S β†’    A  
  6.      Lβ†’    L ; M S  
  7.      L β†’   S  
  8.      M β†’    βˆˆ  
  9.      N β†’    βˆˆ  

The translation scheme for this grammar is as follows:

Production ruleSemantic actions
S β†’ if E then M S1BACKPATCH (E.TRUE, M.QUAD)
S.NEXT = MERGE (E.FALSE, S1.NEXT)
S β†’ if E then M1 S1 else
M2 S2
BACKPATCH (E.TRUE, M1.QUAD)
BACKPATCH (E.FALSE, M2.QUAD)
S.NEXT = MERGE (S1.NEXT, N.NEXT, S2.NEXT)
S β†’ while M1 E do M2 S1BACKPATCH (S1,NEXT, M1.QUAD)
BACKPATCH (E.TRUE, M2.QUAD)
S.NEXT = E.FALSE
GEN (goto M1.QUAD)
S β†’ begin L endS.NEXT = L.NEXT
S β†’ AS.NEXT = MAKELIST ()
L β†’ L ; M SBACKPATHCH (L1.NEXT, M.QUAD)
L.NEXT = S.NEXT
L β†’ SL.NEXT = S.NEXT
M β†’ ∈M.QUAD = NEXTQUAD
Nβ†’ ∈N.NEXT = MAKELIST (NEXTQUAD)
GEN (goto_)

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

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

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>