Lecture 5 Notes

This is a context argument so will

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: ©¡$¡ £ ¤ £ ©¡$¡ £ © ¢$ ¡ ¡ ¢ ¢ £ !£$ #¢ ¡ ¢¡ £#¢$#© )£%¢ ¢ © ¡¢$ ¡ ¢$ #©# ¨  ¡ ¥ ¦¡ ¤ ¡$ ¢£ ¢ ¡ I¢¢$ £ © ¡ $ ¡ £ £ is translated to £¤ ¢ ¢ £¤ ¢ ¡ ¤ £¥ ¢¦¡ ¢ ¥¡ §¥ £ ¢ §£ ¥ ¨¢ ¢ $# %© §¥ ¨¢ ¥ £ $# %© For example, the program We now implement the lexical-address analysis we sketched above. We write a procedure that takes a program and removes all the identifiers from the declarations, and replaces every variable reference by its lexical depth.  ¡ ¤ ¥ 9¡ ¢ ¥¢ £¦R¥ ¡ ¢ $ © ¡ ¡ ¢$ ¡ 4.2.2 Implementing Lexical Addressing 4.2.3 The Translator We are writing a translator, so we need to know the source language and the target language. The target language will have things like and that were not in the source language, and it will lose the things in the source language that these constructs replace, like and . ¤ ¡ ¡   ¢ ¢¡ £# )¢ ¤ £# !¢ ¡ #©# ¨ £#¢$ © !£%# ¢ ¤   # #  © ¡ ¢¡ ¤ £#¢$# )£%© Add to the SLLGEN grammar: § ¤ £#¢ !£¡  ¢¡¡ ¥ § § ¨¡ # )!©  #© #   ¡ ¢ ¢¡ # ¡ ¤ ¡#¡£# ¢ ¤¢© £¡ ¢ ¨ § ¥ £ # § ¥ ¡ # ¤ # ¡ ¢¡¡ ¤ ¤¡ § £#)¢ £¢¦¡ ¢ ¢¡ © ¥ # ¤ ¤ ¡¢¡ # ¡ £# ©£ ¥¦¡ # £ R¥ ¡ ¡ ¤ ¡# ¢ ¢¡ © $ ¦%# § ¢ ¡ ¢ ¢¡ ¢¡¡ R¥ R¥ £ # £ !£%© #¢$# ¢ # ¡ ¤ © ¢£ ¥ ¤ £ # £ # #   © # ¡ ¢ £¥ ¤ #   £ # ¢ We use names starting with for these new constructs because that is normally the comment character in our language. Our translator will reject any program that has one of these new nameless constructs ( , , or ), and our interpreter will reject any program that has one of the old nameful constructs ( , , or ) that are supposed to be replaced. ¤ £#¢£¥ !©¢¦¡ ¤ ¡ ¢ ¢¡ #©# ¨ ¤ £ !£%© #¢$# ¡ ¢ ¢¡ # © #   ¤ 17 £# !¢ ¤ £ !¢ # £ ¦¡ ¥ ¤ ¡ ¡  ...
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