Lecture 5 Notes

is replaced by a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ¢ ¢¡ ¤ # © #   £#¢$# !¦%© ¤ £# !¢ ¡   To calculate the lexical address of any variable reference, we need to know the scopes in which it is enclosed. This is a context argument. ¡¥ ¡ ¢ ¢¡ # ¡ £# )¢ ¡ ¥ ¦ ¥ ¢ ¢ $ %© ¡ ¡¢$ ¡ So will take two arguments: an expression and a static environment. The static environment will be a list of identifiers, representing the scopes within which the current expression lies. The variable declared in the innermost scope will be the first element of the list. ¤ For example, when we translate the last line of the example above, the static environment should be §£ ¨¤¥ £ So looking up an identifier in the static environment means finding its position in the static environment, which gives a lexical address: looking up will give 2, looking up will give 1, and looking up will give 0. £ ¥ Entering a new scope will mean adding a new element to the static environment. We introduce a procedure to do this.  ¢¡# ¡ ¢  ¡# $ # £ [Puzzle: how would this change if we had multiple arguments or multiple declarations?] 18 §§§§§ )!!!!§ £ § !§ £ § 19  ¢¡# ¡ ¡ £  ¡ £¤¡ # E£ ¥ ¥¢ £¦R¥ ¢ ¡ ¡ ¢ ' ¡# ¡ ¢ §  !§ ¢¡# ¡ #¨  ¡  © ¡ ¡ ¢$ ¡ $ © ¢ § ©¢  £#© ! ¤ § ¦¢  ¢¡# ¡  ¥ ¡  ¢¡# ¡ ¥ %© ¤ I¤  ¢ §¦ # ¡ # © §¦ ¡ %£ (£ § ¦# !  ¡¥ ¨I© P!I©¤  ¥ ¡ ¦¢¡ # ¡ © ¥ # ¥¡ § ¢¡# ¡ ¢!© © !  ¡©  ¥ RI£ § £  ¡# ¡  © ¤¤ ¢ ¡# ¡ ¢ ¥ ©  # # ¡  ¢¡# ¡ ¡ ¢  §§  )!§ ¢¡# ¡ £ ¡ RI£ ¥ § ¢¡# ¡ ¢  £ ©  ¢¡# ¡ ¢ ¡# !# # #  $£ ¡   %¥ ¡ ¡ ¢ §§ !!§ ¥ )$ § ¡  ¢ ¢ §  ©  ¢¡# ¡ ¢ § ¦¢  ¢¡# ¡ ¤ ¡  # N §©¥ !P%¥  ¢ apply-senv extend-senv ¥ ¦$ ¡ ¢ ¡ # ¡ # ¢ empty-senv ¢ senv lexaddr © ( Since the static environment is just a list of identifiers, these proce...
View Full Document

This document was uploaded on 03/17/2014 for the course CSG 111 at Northeastern.

Ask a homework question - tutors are online