Class Note for CS 403 at UA-Programming Languages (31)
Class Note for CS 403 at UA-Programming Languages (31)
Popular in Course
Popular in Department
This 3 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Alabama - Tuscaloosa taught by a professor in Fall. Since its upload, it has received 13 views.
Reviews for Class Note for CS 403 at UA-Programming Languages (31)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
Lecture 3 Thursday 11702 Today Review critical BNF concepts from last time Binding Static stack and heap storage Reading Assignments For Next Class Chapter 3 Assignments Assignment 1 due Tuesday 12202 smznnz cs 402 Nates P 1 Binding Def A binding is an association such as between an attribute and an entity or between an operation and a symbol Def Binding time is the time at which a binding takes place smznnz cs AUZClassNatzs P e 4 BNF Review BNF defines what strings are syntactically correct vs incorrect Some basic notation Terminal symbols Actual items that are part of the language 01 etc NonTerminal symbols ltexprgt ltopgt etc Ruleproduction A single line of BNF Alternatives Expressed with 0 or more occurrences 1 or more occurrences smznnz cs 402 Nates P 2 Possible binding times 1 Language design time eg bind operator symbols to operations 2 Language implementation time eg bind pt type to a representation 3 Compile time eg bind a variable to a type in C or Java 4 Load time eg bind a FORTRAN 77 variable to a memory cell or a C statlc variable 5 Runtime eg bind a nonstatic local variable to a memory cell smznnz cs AUZClassNatzs P e 5 Parse Trees A way to apply rules in series from beginning to end in tree form Not useful when the rules contain s and s as well as the and that we discussed not using Sometimes parse trees are constructed so that rules at the bottom often containing and are omitted smznnz cs 402 Nates P 2 Binding Times Def A binding is static if it occurs before run time and remains unchanged throughout program execution Design tirne compile time and load time bindings are all static Def A binding is dynamic if it occurs during execution or can change during execution ofthe program Run time bindings are dynamic smznnz cs AUZClassNatzs P e 5 Lifetimes Static Variables in C Binding lifetime The period of time between the void fooint x creation and destruction of a nametoobject binding static int y 0 0 first time only Yi Object lifetime The period of time between the cout ltlt y ltlt endl creation and destruction of an object These don t necessarily coincide d EX Reference parameters vol mamm foo10 smznnzcsmzchssmies pm sznnzcsmzchssmus p m Object Lifetimes Stack Objects correspond to one of three principal storage Storage bindings are created for variables when their declaration statements are elaborated allocation meChanlsmS Typicallyon entranceto subprogram Static objects Object lifetime program 39 C Pasca Ada C JM Em execution Object bound to one storage location Advantage allows recursion conserves storage from load time on 39 Disadvantages Stack objects Object lifetime subroutine Overhead m allocation and deallocation Subprograms cannot be history sensitive exeCUtlon lnefflclentreferencesindiremaddresslng Heap objects Objects lifetime up to the programmer arbitrary smznnz cs 402st P 28 smznnz cs 402st P e n Static Objects Stack Objects in C void barinty intz l cout ltlt 2 ltlt endl Bound to memory cells before execution begins and remains bound to the same memory cell throughout execution Ex AllFORTRAN 77 variablesc statlc variables Advantage Ef ciency direct addressing VOld fooint X l Values retained from one execution of at 7 0 a subprogram to the next cout ltlt y ltlt end Disadvantage Lack of exibility no recursion Vold mall l fool 0 ban20 l smznnz cs 402st P 29 smznnz cs 402st P e 12 Heap Objects Stack Storage Allocated and deallocated at arbitrary times during program execution SubmlumcD Tempmanes Allocation and deallocatlon can be eXpIICIt or e l g implicit moles Suhmuunz C Miwu mus bmvkkecpmg Referenced only through pomters or references Mum Wequot Sumonine B Mimi nbmutinsc 39 39 39 Midi525 mi Mm ts rumunquot EX Dynamic objects In C Vla new and delete SW all objects in Java 1223 Advantage provides for dynamic storage management Disadvantage inefficient and unreliable Spnn 2002 cs 403 Class Notes page 13 Sprm 2002 cs 403 classNotes page 15 Heap Objects in C Heap Storage void mainvoid int X X new int X 10 COUt ltlt X ltlt endl Allocationrcquest In this case the heap area has become fragmented and the allocation request cannot be satisfied Spnn 2002 cs 403 Class Notes page 14 Sprm 2002 cs 403 Class Notes page 17 Static Stack and Heap Storage Used in swine Storage Single C Program void barint y int 2 1 int w Tempoxanes w new int Tempotarie kw 3 memm cout ltlt 2 ltlt ltlt w ltlt endl Lou Local mm W moses vunablex void foont x lellanoous l hookkecplng Int y 0 Mtsml znwux Miscellaneous bookkeeping bookkeeping Statquot 39quott z 0 Ram mom y z kumuedmess Return mates cout ltlt y ltlt ltlt 2 ltlt endl Argumenls mgumems Axgumcms Mums and mums and mum void main0 smut Subroutinr 2 sumquote a f 1 0 bar20 Spnn 2002 cs 403 Class Notes page 15 Sprm 2002 cs 403 Class Notes page 13
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'