Presentation is loading. Please wait.

Presentation is loading. Please wait.

©2004 Joel Jones 1 CS 403: Programming Languages Lecture 4 Fall 2004 Department of Computer Science University of Alabama Joel Jones.

Similar presentations


Presentation on theme: "©2004 Joel Jones 1 CS 403: Programming Languages Lecture 4 Fall 2004 Department of Computer Science University of Alabama Joel Jones."— Presentation transcript:

1 ©2004 Joel Jones 1 CS 403: Programming Languages Lecture 4 Fall 2004 Department of Computer Science University of Alabama Joel Jones

2 Lecture 4©2004 Joel Jones 2 Outline Symbol Tables Activation Records GDB Reading & Questions for Next Class

3 Lecture 4©2004 Joel Jones 3 Symbol Tables (Cont.) A hash table can be added to the previous data structure to accelerate the search. Elements with the same name are linked from top to bottom. Search start at the entry of the hash table and proceeds through the linked list until the end of the list is reached (old_id) or until the link list refers to an element below scope_marker(LL - 1) (new_id)

4 Lecture 4©2004 Joel Jones 4 Symbol Tables (Cont.) This approach does not work in some cases. Consider the with statement of Pascal and Modula 2. Date = RECORD day: [1..31]; mo: month; yr: CARDINAL END d1: Date; WITH d1 DO day:=10; mo:=Sep; yr:=1981 END is equivalent to d1.day:=10; d1.mo:=Sep; d1.yr:=1981

5 Lecture 4©2004 Joel Jones 5 Symbol Tables

6 Lecture 4©2004 Joel Jones 6 Symbol Tables (Cont.)

7 Lecture 4©2004 Joel Jones 7 The binding of referencing environments Shallow binding: the referencing environment of a routine is not created until the subroutine is actually called. Deep binding: the program binds the environment at the time the subroutine is passed as a parameter. Deep binding is implemented by creating an explicit representation of a referencing environment and bundling it together with a reference to the subroutine. Closure

8 Lecture 4©2004 Joel Jones 8 Activation Records for Nested Routines P1() { REAL X { /* B1 */ { /* B2 */ { /* B3 */ P2(P3) } P3() { x } P2(PX) { PX() } AR P1 AR B1 AR B2 AR B3 AR P2 AR P3 PX

9 Lecture 4©2004 Joel Jones 9 GDB GDB – Gnu DeBugger Preparation Compile with gcc -g Example: gcc -g -o myProgram myprogram.c Run the program under control of gdb Example: gdb myProgram

10 Lecture 4©2004 Joel Jones 10 MP1 Complete write-up available on the class website Basic Idea: write 1 or more programs and associated GDB scripts that demonstrate object (generic, not OO) lifetimes and scopes GDB scripts should print out addresses, values of variables, etc.

11 Lecture 4©2004 Joel Jones 11 Demonstration of GDB Create program Compile it Run under gdb Print some variables Show automatically running script gdb -x gdbCmdFile myProgram

12 Lecture 4©2004 Joel Jones 12 Reading for Next Class Skim the following, paying particular attention to how to print the addresses of variables: Debugging with GDB: The GNU Source Level Debugger http://www.gnu.org/manual/gdb-5.1.1/gdb.html GDB Quick Reference Card http://www.refcards.com/download/gdb-refcard- letter.pdf


Download ppt "©2004 Joel Jones 1 CS 403: Programming Languages Lecture 4 Fall 2004 Department of Computer Science University of Alabama Joel Jones."

Similar presentations


Ads by Google