Chapter5 - Chapter 5 Names Bindings and Scopes CS 350...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 5 Names, Bindings, and Scopes CS 350 Programming Language Design Indiana University – Purdue University Fort Wayne
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Chapter 5 topics Names Variables The Concept of Binding Scope Referencing Environments Named Constants
Background image of page 2
3 Names A name (= identifier) is a string of characters to identify a variable, subprogram, constant, etc. Usually a letter followed by letters, digits, and underscores Some popular styles over the years T TOD TIMEOFDAY TIME OF DAY (spaces ignored in FORTRAN) TIME_OF_DAY Time_Of_Day timeOfDay
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Names Language implementations may impose a limit on name length to simplify the symbol table Case sensitivity Does not promote readability Do you want Sum , SUM , and sum to possibly stand for different variables in the same program? Special words Example: begin , end , int Reserved words may not be a user- defined name Keywords are special only in certain
Background image of page 4
5 Variables A variable is an abstraction of a memory cell Abstract memory cell The physical bytes of memory associated with a variable Variables can be characterized by attributes . . . Name Address Value Type
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Variables Name Not all variables have a name Anonymous variables Address The number of the first byte of memory with which a variable is associated Also called l -value (for left hand side of an assignment) The same name may be associated with different variables at different addresses For example, different subprograms may have local variables with the same name A variable may have different addresses at different times during execution For example, a subprogram local variable may be allocated on the run-time stack at different addresses
Background image of page 6
7 Variables If two variable names can be used to access the same memory location, they are called aliases Aliases are harmful to readability Assignment to one name may change the value of another name Aliases can be created using pointers (reference variables), C and C++ unions, parameter passing Some of the original justifications for aliases are no longer valid For example, aliases promoted memory reuse in
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 Variables Type Determines the size of the abstract memory cell and how the program should interpret the bits in the cell Gives the range of values for a variable and the set of operations that are defined for variables of that type A type is like a class implementing an ADT Value The contents of the abstract memory cell with which the variable is associated
Background image of page 8
9 The concept of binding In general, a binding is an association, as . . . between an attribute and an entity between an operation and a symbol between a variable and its address Binding time The time at which a binding takes place
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10 Possible binding times Language design time For example, bind operator symbols to operations Language implementation time For example, bind floating point type to a representation Compile time
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 30

Chapter5 - Chapter 5 Names Bindings and Scopes CS 350...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online