CS 403/503: Programming Languages

CS 403/503: Programming Languages

BNF for <expression> <expression> → identifier | number | CS 403 -<expression> | (<expression>) | <expression><operator><expression> Organization of Programming Languages <operator> → + | - | * | / Class 3 - August 30, 2001 Topics For Today Parse Tree Review of BNF (Chapter 2.1) Derivations and parse trees (Chapter 2.1) Binding time (Chapter 3.1) Object lifetime and storage slope * x + intercept management (Chapter 3.2) BNF Concept Review Another Parse Tree Terminal symbols: Actual items that are part of the language (0,1,+,-,*,/,etc.) Non-Terminal symbols: <expr>, <op>, etc. Rule/production: A single line of BNF Alternatives: Expressed with | Also: slope * x + intercept *: 0 or more occurrences +:1 or more occurrences 1 Binding Lifetimes • Binding lifetime: The period of time Def: A binding is an association, such between the creation and destruction of a as between an attribute and an entity, name-to-object binding • Object lifetime: The period of time or between an operation and a between the creation and destruction of symbol. an object • These don’t necessarily coincide Def: Binding time is the time at which a • EX. Reference parameters binding takes place. Possible binding times Object Lifetimes… 1. Language design time--e.g., bind operator …correspond to one of three principal symbols to operations 2. Language implementation time--e.g., bind fl. pt. storage allocation mechanisms: type to a representation Static objects: Object lifetime = program 3. Compile time--e.g., bind a variable to a type in C execution. Object bound to one storage or Java location from load time on. 4. Load time--e.g., bind a FORTRAN 77 variable to a memory cell (or a C static variable) Stack objects: Object lifetime = subroutine 5. Runtime--e.g., bind a nonstatic local variable to a execution. memory cell Heap objects: Objects lifetime = up to the programmer (arbitrary) Binding Times Static Objects Def: A binding is static if it occurs before run time Bound to memory cells before execution begins and remains unchanged throughout program and remains bound to the same memory cell execution. throughout execution. • Design time, compile time and load time bindings are all • EX. All FORTRAN 77 variables, C static variables static. Advantage: Efficiency (direct addressing), Def: A binding is dynamic if it occurs during Values retained from one execution of execution or can change during execution of the a subprogram to the next program. • Run time bindings are dynamic Disadvantage: Lack of flexibility (no recursion) 2 Stack Objects Stack Storage Storage bindings are created for variables when their declaration statements are elaborated. • Typically on entrance to subprograms • C, Pascal, Ada, C++, Java, etc. Advantage: allows recursion; conserves storage Disadvantages: - Overhead of allocation and deallocation - Subprograms cannot be history sensitive - Inefficient references (indirect addressing) Heap Objects Heap Storage Allocated and deallocated at arbitrary times during program execution Allocation and deallocation can be explicit or implicit Referenced only through pointers or references EX. Dynamic objects in C++ (via new and delete) all objects in Java In this case, the heap area has become fragmented Advantage: provides for dynamic storage and the allocation request cannot be satisfied. management Disadvantage: inefficient and unreliable Static Storage 3.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us