“The computer was born to solve problems that did not exist before.”

Random Posts

Monday, November 22, 2021

Procedures call

Procedures call

Procedure is an important and frequently used programming construct for a compiler. It is used to generate good code for procedure calls and returns.

Calling sequence:

The translation for a call includes a sequence of actions taken on entry and exit from each procedure. Following actions take place in a calling sequence:

  • When a procedure call occurs then space is allocated for activation record.
  • Evaluate the argument of the called procedure.
  • Establish the environment pointers to enable the called procedure to access data in enclosing blocks.
  • Save the state of the calling procedure so that it can resume execution after the call.
  • Also save the return address. It is the address of the location to which the called routine must transfer after it is finished.
  • Finally generate a jump to the beginning of the code for the called procedure.

Let us consider a grammar for a simple procedure call statement

  1. S →    call id(Elist)  
  2.    Elist →   Elist, E  
  3.    Elist →  E  

A suitable transition scheme for procedure call would be:

Production RuleSemantic Action
S → call id(Elist)for each item p on QUEUE do
  GEN (param p)
    GEN (call id.PLACE)
Elist → Elist, Eappend E.PLACE to the end of QUEUE
Elist → Einitialize QUEUE to contain only
   E.PLACE

Queue is used to store the list of parameters in the procedure call.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages

SoraTemplates

Best Free and Premium Blogger Templates Provider.

Buy This Template