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

Translation of Assignment Statements

Translation of Assignment Statements

In the syntax directed translation, assignment statement is mainly deals with expressions. The expression can be of type real, integer, array and records.

Consider the grammar

  1. S  β†’    id := E  
  2. E    β†’  E1 + E2  
  3. E   β†’   E1 * E2  
  4. E   β†’   (E1)  
  5. E   β†’   id  

The translation scheme of above grammar is given below:

Production ruleSemantic actions
S β†’ id :=E{p = look_up(id.name);
 If p β‰  nil then
 Emit (p = E.place)
 Else
 Error;
}
E β†’ E1 + E2{E.place = newtemp();
 Emit (E.place = E1.place '+' E2.place)
}
E β†’ E1 * E2{E.place = newtemp();
 Emit (E.place = E1.place '*' E2.place)
}
E β†’ (E1){E.place = E1.place}
E β†’ id{p = look_up(id.name);
 If p β‰  nil then
 Emit (p = E.place)
 Else
 Error;
}
  • The p returns the entry for id.name in the symbol table.
  • The Emit function is used for appending the three address code to the output file. Otherwise it will report an error.
  • The newtemp() is a function used to generate new temporary variables.
  • E.place holds the value of E.

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

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

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>