Upload
rosa-peters
View
217
Download
2
Embed Size (px)
Citation preview
©2004 Joel Jones1
CS 403: Programming Languages
Lecture 4
Fall 2004
Department of Computer Science
University of Alabama
Joel Jones
Lecture 4 ©2004 Joel Jones2
Outline
• Symbol Tables• Activation Records• GDB• Reading & Questions for Next Class
Lecture 4 ©2004 Joel Jones3
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)
Lecture 4 ©2004 Joel Jones4
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 ENDd1: Date;
WITH d1 DO day:=10; mo:=Sep; yr:=1981ENDis equivalent to
d1.day:=10; d1.mo:=Sep; d1.yr:=1981
Lecture 4 ©2004 Joel Jones5
Symbol Tables
Lecture 4 ©2004 Joel Jones6
Symbol Tables (Cont.)
Lecture 4 ©2004 Joel Jones7
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
Lecture 4 ©2004 Joel Jones8
Activation Records for Nested RoutinesP1(){ REAL X { /* B1 */ { /* B2 */ { /* B3 */ P2(P3) }
P3() { x } } P2(PX) { PX() }
}
}
ARP1
ARB1
ARB2
ARB3
ARP2
ARP3
PX
Lecture 4 ©2004 Joel Jones9
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
Lecture 4 ©2004 Joel Jones10
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.
Lecture 4 ©2004 Joel Jones11
Demonstration of GDB
• Create program• Compile it• Run under gdb• Print some variables• Show automatically running script
• gdb -x gdbCmdFile myProgram
Lecture 4 ©2004 Joel Jones12
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