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

Slides:



Advertisements
Similar presentations
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Advertisements

CS 202 Computer Science II Lab Fall 2009 September 24.
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
CS 536 Spring Run-time organization Lecture 19.
ISBN Chapter 10 Implementing Subprograms.
ISBN Chapter 10 Implementing Subprograms.
Tutorial 6 & 7 Symbol Table
Semantics of Calls and Returns
1 CSCI 360 Survey Of Programming Languages 9 – Implementing Subprograms Spring, 2008 Doug L Hoffman, PhD.
Overview Parameter passing modes.
Chapter 10 Implementing Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Semantics of Call and Return The subprogram call and return.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Subroutines and Control Abstraction Aaron Bloomfield CS 415 Fall 2005.
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 9 Def: The subprogram call and return operations of a language are together called its subprogram.
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
CS 403: Programming Languages Lecture 6 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Scope Rules (Section 3.3) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael Scott.
1 Symbol Table and Subroutine Closures (Sections 3.3 & 3.4) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos.
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Scope Rules Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 11.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
CS 614: Theory and Construction of Compilers Lecture 7 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
CS 153: Concepts of Compiler Design September 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
A.Alzubair Hassan Abdullah Dept. Computer Sciences Kassala University A.Alzubair Hassan Abdullah Dept. Computer Sciences Kassala University NESTED SUBPROGRAMS.
CS 153: Concepts of Compiler Design October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 614: Theory and Construction of Compilers Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS 321 Programming Languages and Compilers Names, Scopes, and Bindings.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
1 Chapter 10 © 2002 by Addison Wesley Longman, Inc The General Semantics of Calls and Returns - Def: The subprogram call and return operations of.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
CS 603: Programming Language Organization Lecture 9 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
ISBN Chapter 10 Implementing Subprograms.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
ISBN Chapter 10 Implementing Subprograms.
CS 153: Concepts of Compiler Design September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
©2004 Joel Jones 1 CS 403: Programming Languages Lecture 3 Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Implementing Subprograms
Chapter 10 : Implementing Subprograms
Implementing Subprograms Chapter 10
Implementing Subprograms
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
Implementing Subprograms
CS 153: Concepts of Compiler Design October 3 Class Meeting
Run-time organization
Implementing Subprograms
Implementing Subprograms
Names, Binding, and Scope
CMPE 152: Compiler Design October 4 Class Meeting
Names and Binding In Text: Chapter 5.
Lecture 6: Names (Revised based on the Tucker’s slides) 5/27/2019
Implementing Subprograms
Types and Related Issues
Implementing Subprograms
Chapter 10 Def: The subprogram call and return operations of
Presentation transcript:

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

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

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)

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

Lecture 4©2004 Joel Jones 5 Symbol Tables

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

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

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

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

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.

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

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 GDB Quick Reference Card letter.pdf