names names identifiers variables subroutines constants

Similar documents
CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CSE 307: Principles of Programming Languages

Programming Languages

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

CST-402(T): Language Processors

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

LECTURE 3. Compiler Phases

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Concepts of Programming Languages

G Programming Languages - Fall 2012

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

The role of semantic analysis in a compiler

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CS 415 Midterm Exam Spring 2002

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

CSE 307: Principles of Programming Languages

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Working of the Compilers

Chapter 3:: Names, Scopes, and Bindings

CS 415 Midterm Exam Spring SOLUTION

CSC 533: Organization of Programming Languages. Spring 2005

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

G Programming Languages - Fall 2012

Chapter 3:: Names, Scopes, and Bindings (cont.)

Chapter 3:: Names, Scopes, and Bindings (cont.)

1 Lexical Considerations

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Compiler Design (40-414)

A Simple Syntax-Directed Translator

Programming Languages Third Edition

Programming Languages 2nd edition Tucker and Noonan"

COMPILER DESIGN LECTURE NOTES

EI326 ENGINEERING PRACTICE & TECHNICAL INNOVATION (III-G) Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

CS 314 Principles of Programming Languages

Informatica 3 Syntax and Semantics

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Compiler Theory. (Semantic Analysis and Run-Time Environments)

ST. XAVIER S COLLEGE

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Semantic Analysis. Compiler Architecture

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

A simple syntax-directed

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Programmiersprachen (Programming Languages)

Principles of Compiler Design

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

10/18/18. Outline. Semantic Analysis. Two types of semantic rules. Syntax vs. Semantics. Static Semantics. Static Semantics.

CS 314 Principles of Programming Languages

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Lexical Considerations

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

CS 415 Midterm Exam Fall 2003

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

History of Compilers The term

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

CS426 Compiler Construction Fall 2006

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking


for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

Chapter 2 :: Programming Language Syntax

Typescript on LLVM Language Reference Manual

Chapter 5. Names, Bindings, and Scopes

Time : 1 Hour Max Marks : 30

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Lectures Basics in Procedural Programming: Machinery

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

COMPILER DESIGN. For COMPUTER SCIENCE

10. Abstract Data Types

CS 360 Programming Languages Interpreters

Binding and Variables

Formats of Translated Programs

Today's Topics. CISC 458 Winter J.R. Cordy

Lecture 4: The Declarative Sequential Kernel Language. September 5th 2011

Motivation was to facilitate development of systems software, especially OS development.

Undergraduate Compilers in a Day

CS 4201 Compilers 2014/2015 Handout: Lab 1

Programming Languages, Summary CSC419; Odelia Schwartz

INSTITUTE OF AERONAUTICAL ENGINEERING

Part (04) Introduction to Programming

Lexical Considerations

Principles of Programming Languages. Lecture Outline

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Properties of an identifier (and the object it represents) may be set at

Why are there so many programming languages?

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

Application Specific Signal Processors S

Compilers CS S-05 Semantic Analysis

The compilation process is driven by the syntactic structure of the program as discovered by the parser

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Transcription:

names (source: Louden, "Programming Languages, Principles and Practices", 2nd Edition, Ch. 5, pp. 125-134)!p. 126: "A fundamental abstraction mechanism in a programming language is the use of names, or identifiers, to denote language entities or constructs."!"in most languages, variables,... [subroutines], and constants can have names assigned by the programmer."!"a fundamental step in describing the semantics of a language is to describe the conventions that determine the meaning of each name used in a program."

location and value!other important concepts to understand, related to but separate from names: location and value " value: any storable quantity " location: a place where a value can be stored

a name's meaning! p. 127: "The meaning of a name is determined by the properties, or attributes, associated with the name."! what attributes? These can vary by kind of name and by programming language, but some examples include: " data type " value " location

examples of name attributes: example 1! C language example: const int MAGIC = 5;! associates with the name MAGIC the following attributes: " a data type attribute of 'integer constant' " a value attribute of 5 " (note: in C, the 'constant' attribute is part of the data type -- in other languages, this might not be the case...) " (...another example of different languages including different aspects as part of the data type: early Pascal considered an array's size to be part of its type)

examples of name attributes: example 2! another C language example: int quantity;! associates with the name quantity the following attributes: " an attribute 'variable' " a data type attribute of 'integer'

examples of name attributes: example 3! yet another C language example: double functy(int value) { return (value * 2.0)/7.0; }! associates with the name functy the following attributes: " an attribute 'function' " the number, names, and data types of its parameters (here, one parameter with name value and data type 'integer') " the body of code to be executed when functy is called (here, the return statement with its computation)

examples of name attributes: examples 4, 5! Are declarations the only language constructs that can associate attributes to names? NO;! for example: (still in C) x = 2; " this assignment statement associates the new attribute 'value 2' to the variable x int* y; y = new int; " y is a pointer variable " the assignment statement allocates memory for an integer variable -- it associates a location attribute to it -- as well as associates a new value attribute to y

binding! p. 128: "The process of associating an attribute to a name is called binding."! "An attribute can be classified according to the time during the translation/execution process when it is computed and bound to a name. "...called the binding time of the attribute."! two broad categories of binding times: " static binding: "occurs prior to execution" " dynamic binding: "occurs during execution"! static attribute: able to be bound statically;! dynamic attribute: must be bound dynamically;

binding! p. 128: "The process of associating an attribute to a name is called binding."! "An attribute can be classified according to the time during the translation/execution process when it is computed and bound to a name. "...called the binding time of the attribute."! two broad categories of binding times: " static binding: "occurs prior to execution" " dynamic binding: "occurs during execution"! static attribute: able to be bound statically;! dynamic attribute: must be bound dynamically;

which attributes are which?! p. 128: "Languages differ SUBSTANTIALLY in which attributes are bound statically and which are bound dynamically"! binding times may depend on the kind of translator being used, too;! for example: " languages that support the functional programming model often have more dynamic binding " interpreters perform most bindings dynamically " compilers perform more bindings statically

which attributes are which? part 2! "To make the discussion of attributes and binding independent of such translator issues, " we usually refer to the binding time of the attribute as the earliest time that the language rules permit the attribute to be bound."

which attributes are which? examples const int MAGIC = 2;! the value 2 is bound statically to the name MAGIC int val;! the data type 'integer' is bound statically to the name val val = 2;! binds the value 2 to val dynamically when the assignment statement is executed /* C++ */ y = new int;! dynamically binds a storage location to *y and assigns that location as the value of y

ASIDE: stages of execution (source: MacLennan, Ch. 2, pp. 43-44)...when a compiler is your translator...! the stages for early FORTRAN (still frequently used): 1. Compilation 2. Linking 3. Loading 4. Execution! compilation: translates individual statements into relocatable object code! linking: incorporates references to external, already-compiled subprograms (e.g. libraries)! loading: places (or loads) the program into memory -- converting it from relocatable to absolute format

ASIDE: phases of compilation (sources: MacLennan, Ch. 2, pp. 43-44, Scott, Ch.1, pp. 27-28 and 33-34)! the phases of compilation for early FORTRAN (still frequently used): 1. Lexical and syntax analysis 2. Optimization 3. Code synthesis! lexical analysis (scanning): read characters and group them into tokens! syntax analysis (parsing): organizes tokens into a parse tree (based on, often, a CFG)! optimization: transforming the result so far to make it more efficient! code synthesis: put together the parts of the object code instructions in relocatable format

subcategories of static binding (source: Louden, Ch. 5, pp. 128-129) A static attribute may be bound...!...when the language is defined (language definition time)!...when the language is implemented (language implementation time)!...during parsing (translation time or compile time)!...during the linking of the program with libraries (link time)!...during the loading of the program for execution (load time)

subcategories of static binding - examples, part 1 (source: Louden, Ch. 5, pp. 128-129)!...of language definition time binding: " predefined identifiers that have their meaning (and thus their attributes) specified by the language definition -- such as when the two type boolean values are specified as true and false!...of language implementation time binding: " when the range of the integer type is determined by the implementation;!...of compile time binding: " in const int n = 2; can't all of that be bound at compile time?

subcategories of static binding - examples, part 2 (source: Louden, Ch. 5, pp. 128-129)!...of link time binding: " "...the body of an externally-defined function will not be bound until link time"!...of load time binding: " "...and the location of a global variable is bound at load time, since its location does not change during the execution of the program."

dynamic binding - examples (source: Louden, Ch. 5, pp. 128-129)! methods called in Java or virtual calls in C++! types of Prolog or Scheme variables! bindings of values to variables...! 8-)

tradeoffs: earlier vs. later binding times (source: Louden, Ch. 5, pp. 128-129, and Scott, Ch. 3, p. 113)! binding times definitely impact the design and implementation of programming languages;! IN GENERAL, early binding times are associated with more efficiency! IN GENERAL, later binding times are associated with more flexibility

scope of a binding " (Louden, p. 134) the scope of a binding is "the region of the program over which the binding is maintained" " static scoping: (Scott, p. 123) follows the structure of the code as it appears in written form;! with this, don't have to consider the flow of control at run time to determine a name's scope; " dynamic scoping: (Scott, p. 139) "the bindings between names and objects depend on the flow of control at run time, and in particular on the order in which subroutines are called."! the 'current' binding for a given name is the one encountered most recently during execution, and not yet destroyed by returning from its scope"