1/122
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Language Reference Manual
Most common way to specify semantics. The expanding use of English descriptions suffer from the lack of precision and may have omissions and ambiguities
Defining Translator
Questions about a language can be answered by expirement. But cannot be answered in advance. Bugs and machine dependencies in the translator become parts of the language semantics. May not be portable to all machines
Formal definition
Formal, mathematical methods are precise, but are also complex and abstract, and require study to understand.
Denotational semantics
Semantics using a series of functions
names or identifiers
The most fundamental abstraction
Data type attribute and the value attribute
The variable name is assocaited with
Function, Numbers, Names, and Data Types. The body of code
Function name is associated with
Binding
The process of associated an attribute to a name
Static Binding
Occurs before execution (parsing, semantic analysis, linking, or loading) Compilers perform most this way
Dynamic Binding
Occurs during execution. Interpreters perform most bindings dynamically
Static attribute
Statically bound attributes
Dynamic attribute
Dynamically bound attributes
int x
The data type integer is bound to x statically
x = 2
The value 2 is bound to x dynamically
y = new int
A memory space is bound to *y dynamically and A memory address is bound to y dynamically
Language definition time
Predefined identifieres (bool, char, int, float)
Language implementation time
maxint, string::npos
Translation time (compile-time)
Data types of variable or constant names
Link time
Link a program with libraries
Load time
The location of global variables
Execution time (run-time)
Assign values to variables
implicitly or explicitly
Binding can be determined by a declaration either
explicitly bound
int x binding: x
implicitly bound
int x binding: location
Definitions
Declarations that specify all potential attributes. Function definitions
Simple declarations
Partially specifify attributes
Incomplete type
ifstream inFile. Other attributes are not provided in teh same program. The complete attributes can only be found at link time
Blocks
Consist of a sequence of declarations followed by a sequence of statements and surrounded by syntactic markers
Declarations
syntactically and semantically related to blocks
Local Declarations
Declared within blocks
Global (nonlocal) declarations
Declared outside any block
Scope of a Binding
The region of a program where the binding is maintained
Scope of a declaration
From the point right after the eclaration to the end of the block
Scope Holes
The declarations in inner blocks take precedence over declarations in outer blocks
Visibility of a Declaration
The regions of a program where the bindings of a declaration apply
may not be
The scope of a declaration _____ to the visibility of a declaration
Access hidden declarations
C++ (::) Ada (.)
Symbol Table
A function expressing the binding of attributes to names
add or delete bindings
Change with the proceeding of translation and execution to ________
Names ——————> Attributes
Graphical representation of a symbol table
Identifyer Dictionary
Support insertion, lookup, and deletion of bindings in declarations
On entry into a block
Process all declarations, add corresponding bindings to the symbol table
On exit from a block
Remove corresponding bindings from the symbol table
Static (lexical) scoping
Process declarations before execution
Dynamic Scoping
Process declarations as they are encountered along an execution path
Problems with Dynamic Scoping
The reference on nonlocal variables and datatype of nonlocal variables cannot be predicted before execution
Why use dynamic scoping
For highly dynamic interpreted languages, used in an interpreter
Local Symbol Table
Must contain a local symbol table as an attribute
Symbol Table for Struct Declaration
Must contain further declarations of its data fields. The declarations of data fields are accessible whenever the struct variable is in scope
Overloading
Use the same name to refer to different things in a program
The addition operator (+)
Integer addition and floating-point addition
Disambiguate overloading
C++ and Ada allow the overloading of both function names and operators. Java only allows the overloading of function names
Calling context
numbers and types of parameters
Ambiguous calling context
Depend on the language rules for converting a value from one type to another
Automatic Conversion
Ada and C++ no ____ is allowed
not lose information
In Java all conversions that do _____ are allowed
Complicate
Automatic conversions make overloading resolution ___
Return type and parameter names
Besides the number and types of the parameter values, Ada allowed for ___ to be used
ignore the
C++ and Java ___ the return type
built-in operators
Ada and C++ (not Java) allow ___ to be overloaded
Keep synatctic properties
Associativity and precedence
Operators and functions
No semantic difference. There is a syntactic difference
Name overloading
Reuse the same name for completely different things
Name Overloading not permitted
In most languages, can be extremely confusing and little benefits are gained
Limiting names and different symbol tables
Name overloading can be handy
Registers
A small, high-speed storage location within a CPU
Code Space
Instructions written in a programming language
Global Space
The area where variables and functions can be accessed from anywhere within a program
Stack
LIFO (Last-In, First-Out) structure used for managing local variables and function calls
Heap
a more flexible region for storing dynamically allocated memory
Allocation
Storage classes of variables
Static allocation
For global variables
Automatic allocation
For local variabls
Dynamic allocation
For heap allocation
Environment
Maintain the bindings of names to locations.
Statically (at load time) or dynamically (at execution time)
The environment may be constructed
FORTRAN
Use a completely static environment; all allocations are bound statically
LISP
Use a completly dynamic environment; all allocations are bound during execution
C, C++, Ada, and other Algol-style languages
In the middle; some allocation is performed statically while other allocation is performed dynamically
On entry into block
Bind locations to local variabls in a stack-based fashion.
Upside-down stack
Memory space
On exit from a block
Remove bindings of locations from variabls
Compile time quantities
Constant names and data types may be purely ___ in a compiled language
Statically
Global variables are allocated
Automatically
Local variables are allocated ____ when a block is being executed
Lifetime (extent) of an allocation
The duration of an allocation in the environment
Beyond
Can extend ___ the region where it may be accessed
Pointers
An object whose stored value is a reference to another object (Use dynamic allocation)
Dynamic Allocation in C++
Use the new operator for allocation; use the delete operator for deallocation
Dynamic Allocation in C
Use the malloc function for allocation; use the free function for deallocation
All functional languages
Require the heap to be completely automatic. With no allocation or deallocation under the programmer’s control
Allocation
Java allow ___, but not deallocation, to be udner the programmer control. Has no dereference operator
Specify a Storage Class
Some languages allow programmers to specify the kind of allocation within a declaration
Variables
Objects whoes stored value can change during execution
Box-and-circle diagram
To represent only the environment-related attributes. Name, location, and value only
R-value (right-hand side value)
The value stored in the location of a variable
L-value (left-hand side value)
The location of a variable
In ML
variables are explicitly specified as locations or references to values
Implicitly
In C/C++ specify locations and values __ Automatic dereferencing of l-values or r-values, such as the statement x = y;
Explicitly
In C/C++ specify location and values; use the address of the operator to get the l-value, use the deference operator to get the r-value