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

Similar documents
Programming Languages Third Edition. Chapter 7 Basic Semantics

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

CSE 307: Principles of Programming Languages

Chapter 5. Names, Bindings, and Scopes

Names, Scopes, and Bindings II. Hwansoo Han

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

The role of semantic analysis in a compiler

Chapter 5 Names, Binding, Type Checking and Scopes

Lecture 16: Static Semantics Overview 1

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

CSCE 314 Programming Languages. Type System

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

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages Third Edition

Concepts Introduced in Chapter 7

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

CSCI312 Principles of Programming Languages!

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

Programmiersprachen (Programming Languages)

CS558 Programming Languages

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

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

Informatica 3 Syntax and Semantics

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

4 Bindings and Scope. Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow

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

CS 314 Principles of Programming Languages

LECTURE 14. Names, Scopes, and Bindings: Scopes

CS 415 Midterm Exam Spring 2002

Scope. Chapter Ten Modern Programming Languages 1

6. Discuss how producer-consumer problem and Dining philosophers problem are solved using concurrency in ADA. [16]

Names, Bindings, Scopes

G Programming Languages - Fall 2012

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

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages. Lecture 13

MIDTERM EXAMINATION - CS130 - Spring 2005

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

INSTITUTE OF AERONAUTICAL ENGINEERING

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

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

MIDTERM EXAM (Solutions)

CSE 307: Principles of Programming Languages

Type Bindings. Static Type Binding

CSC 533: Organization of Programming Languages. Spring 2005

Review of the C Programming Language

Semantics. Names. Binding Time

CS 242. Fundamentals. Reading: See last slide

Chapter 5 Names, Bindings, Type Checking, and Scopes

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

Syntax Errors; Static Semantics

The Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Concepts of Programming Languages

CS 415 Midterm Exam Spring SOLUTION

Semantic Analysis. Lecture 9. February 7, 2018

HANDLING NONLOCAL REFERENCES

CMSC 330: Organization of Programming Languages

Functional Programming. Pure Functional Programming

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

Programming Languages

A Tour of Language Implementation

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Imperative Programming

10. Abstract Data Types

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

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

1 Terminology. 2 Environments and Static Scoping. P. N. Hilfinger. Fall Static Analysis: Scope and Types

CS558 Programming Languages

Introduction. A. Bellaachia Page: 1

Subroutines. Subroutine. Subroutine design. Control abstraction. If a subroutine does not fit on the screen, it is too long

G Programming Languages - Fall 2012

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Special Topics: Programming Languages

Informatica 3 Marcello Restelli

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Scope. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CST-402(T): Language Processors

6. Names, Scopes, and Bindings

1 Lexical Considerations

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

S.No Question Blooms Level Course Outcome UNIT I. Programming Language Syntax and semantics

Compiler construction

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

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Acknowledgement. CS Compiler Design. Semantic Processing. Alternatives for semantic processing. Intro to Semantic Analysis. V.

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

Binding and Variables

Operational Semantics. One-Slide Summary. Lecture Outline

Programming Languages 2nd edition Tucker and Noonan"

CS558 Programming Languages. Winter 2013 Lecture 3

Com S 541. Programming Languages I

MIDTERM EXAMINATION - CS130 - Spring 2003

Weeks 6&7: Procedures and Parameter Passing

Transcription:

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

Ways to Specify Semantics Standards Documents (Language Definition) Language Reference Manual e.g. Harbison and Steele Translator Formal Definition denotational semantics W-grammars (Algol 68) attribute grammars axiomatic semantics Hoare logic Dijkstra s weakest precondition calculus operational semantics 2

Names A name or identifier is an abstraction of a memory location. Names denote constants, variables, labels, procedure or function names, and formal parameters. A step in describing semantics is describing conventions that determine the meaing of each name in a program. Design issues for names: maximum length, character set, case sensitivity, reserved vs. keywords, hardware representation Attributes The meaning of a name is determined by attributes such as type, value, location, scope, lifetime, and initialization 3

Bindings The association of a name with an attribute is a binding. These associations are called semantic functions. in compiled languages, static attributes can be handled directly by the compiler by using Symbol Tables: ST: Names -> Static Attributes in compiled languages, dynamic attributes are handled during execution by code generated by the compiler. These attributes include locations and values: Environment: Names -> Locations Memory: Names -> Values in interpreted languages, the interpreter handles everything directly: Environment: Names -> Attributes 4

Binding Times static binding is done before run time and is unchanged during run time dynamic binding is done during run time or changes during run time language design bind * to multiplication language implementation bind type integer to a hardware representation compile time bind variable to a data type link/load time bind function call to code run time bind variable to address 5

Declarations Declarations bind attributes to names int x; statically binds type integer to name x int x = 0; also binds value 0 to name x may only bind some attributes function prototype double f(int x); specifies type of f but not code recursive definition struct x; is an incomplete type used to resolve recursive definitions may be implicit e.g. Fortran, APL, Snobol, Lisp A definition in C/C++ binds all potential attributes 6

Declarations are associated syntactically and semantically with language constructs. Standard construct is a block, schematically represented as begin-marker decl-seq stmt-seq end-marker Declarations associated with a block are local to the block. Others are non-local C declarations appear in compound statements and function bodies C declarations can also appear as globals Declarations may also appear in structured data types and classes. In pure object-oriented languages, all declarations except a class must be inside a class 7

Declarations can be collected into larger groups Ada packages and tasks Java packages ML, Haskell modules C++ namespaces 8

Scope The scope of a binding is the region of the program over which the binding is maintained. Declarations create bindings. The scope of a declaration is the range of statements in which the bindings established by the declaration are maintained. The scope of a declaration includes the program unit in which the declaration is made, but may also include other parts. 9

Static, Block, or Lexical Scoping introduced in Algol 60 scope can be determined statically, that is, prior to execution programs are typically constructed in nested blocks each block creates its own scope to determine the declaration associated with a variable reference, search outward through enclosing blocks Dynamic Scoping Lisp (old versions), APL, SNOBOL scope is determined dynamically, that is, during execution to determine the declaration associated with a variable reference, search upward through call stack 10

Visibility The visibility of a declaration is the region of a program where bindings apply Scope holes are regons where bindings exist but are hidden by other bindings Scope and accessibility of declarations can be modified by scope resolution operators (Java, C++) dot notation (Ada visibility by selection) keyword modifiers (C - extern) 11

Symbol Table binds names to static attributes supports insertion, lookup and deletion represents bindings given in declarations lexical scope supported by stack operations symbol table is processed by compiler, top to bottom through text dynamic scope symbol table is processed at runtime as blocks or functions are executed see section 5.3 in text for examples 12