March 12, 2004 1 ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)

Slides:



Advertisements
Similar presentations
Names, Bindings, Type Checking, and Scopes
Advertisements

Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 4 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case.
Names and Bindings.
Chapter 5 Names, Bindings, and Scopes
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Names, Bindings, Type Checking, and Scopes
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Names, Bindings, Type Checking, and Scopes
CS 330 Programming Languages 10 / 18 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
Names, Bindings, Type Checking, and Scopes
ISBN Lecture 05 Variable Attributes.
The Concept of Variables
Copyright © 1995 by Addison-Wesley Publishing Co. 1 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case sensitive?
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
CMSC331. Some material © 1998 by Addison Wesley Longman, Inc. 1 Chapter 5 Chapter 5 Variables: Names, Bindings, Type Checking and Scope.
Names, Bindings, and Scopes
Names, Bindings, and Scopes
Software II: Principles of Programming Languages Lecture 5 – Names, Bindings, and Scopes.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Names, Bindings, Type Checking, and Scopes
Names and Binding In procedural programming, you write instructions the manipulate the “state” of the process where the “state” is the collection of variables.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Chapter 5 © 2002 by Addison Wesley Longman, Inc Names - We discuss all user-defined names here - Design issues for names: - Maximum length? - Are.
COMP4730/2003/lec5/H.Melikian Names, Bindings,Type Checking and Scopes (Chapter 5) - Design issues: - Maximum length? - Are connector characters allowed?
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
중요 용어 설명 ( 추후 설명이 됨 ). 2 명칭과 관련된 용어의 개념  Names  Variables  The Concept of Binding  Type Checking  Strong Typing  Type Compatibility  Scope  Scope.
1 Chapter 5 Names Bindings Type Checking Scope. 2 High-Level Programming Languages Two main goals:Two main goals: –Machine independence –Ease of programming.
1 CS Programming Languages Class 07 September 14, 2000.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Names, Bindings, Type Checking, and Scopes
COME Chapter 5 Chapter 5 Variables: Names, Bindings, Type Checking and Scope.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
Chapter 5 Names, Bindings, and Scopes. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 5 Topics Introduction Names Variables The Concept.
ISBN Chapter 5 Names, Bindings, and Scopes.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
ISBN Chapter 5 Names, Bindings, and Scopes.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
ICOM 4036: PROGRAMMING LANGUAGES Lecture ? Naming and Scopes.
CS 363 Comparative Programming Languages Names, Type Checking, and Scopes.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Names and Binding In Text: Chapter 4.
ISBN Variables, Names, Scope and Lifetime ICOM 4036 Lecture 9.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Names, Scope, and Bindings Programming Languages and Paradigms.
Names, Bindings, Type Checking and Scopes. Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Chapter 5 Names, Bindings, Type Checking CSCE 343.
5.2 Names - We discuss all user-defined names here
5.2 Names - We discuss all user-defined names here
Names, Bindings, Type Checking, and Scopes
Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes.
Names, Bindings, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes.
Names, Bindings, Type Checking, and Scopes
Names, Bindings, Type Checking, and Scopes
Names and Binding In Text: Chapter 5.
Names, Bindings, and Scopes
Types and Related Issues
Presentation transcript:

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341) Lecture #6 March 12, 2004 In-Young Ko iko.AT. icu.ac.kr Information and Communications University (ICU) iko.AT. icu.ac.kr

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Announcements Check the class homepage (BBS) for the grading policy of HW#1, and the revised HW#2 description Check the class homepage (BBS) for the grading policy of HW#1, and the revised HW#2 description Form project groups Form project groups 3-4 people per a group 3-4 people per a group Report your group formation to TA by Friday March 19th Report your group formation to TA by Friday March 19th

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Review of the Previous Lecture Attribute Grammars Attribute Grammars Dynamic Semantics Dynamic Semantics Operational Semantics Operational Semantics Axiomatic Semantics Axiomatic Semantics

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Names, Variables, Bindings, and Types int counter = 100; 100 … 0x0023FF01 Memory Variable Name (Identifier): “counter”Name (Identifier): “counter” Type: intType: int Value (R-value): 100Value (R-value): 100 Address (L-value): 0x0023FF01Address (L-value): 0x0023FF01 Binding

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Design Issues for Names Maximum length? Maximum length? If too short, they cannot be connotative If too short, they cannot be connotative If too long, the symbol table needs to be large If too long, the symbol table needs to be large e.g., FORTRAN I: max 6, COBOL: max 30, Ada and Java: no limit e.g., FORTRAN I: max 6, COBOL: max 30, Ada and Java: no limit Which characters are allowed, in what order? Which characters are allowed, in what order? Letters, digits and underscore characters are usually allowed Letters, digits and underscore characters are usually allowed The first character of a name must be a letter in FORTRAN The first character of a name must be a letter in FORTRAN Are connector characters allowed? Are connector characters allowed? Space characters in FORTRAN (e.g., No Of Things), Underscores in C (e.g., no_of_things) Space characters in FORTRAN (e.g., No Of Things), Underscores in C (e.g., no_of_things) “Camel” notation: e.g, NoOfThings “Camel” notation: e.g, NoOfThings Are names case sensitive? Are names case sensitive? Are special words reserved words or keywords? Are special words reserved words or keywords? e.g., int float = 100; e.g., int float = 100; Naming convention? Naming convention? In Java, class names start with an uppercase letter, and variable and method names start with a lowercase letter In Java, class names start with an uppercase letter, and variable and method names start with a lowercase letter

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Variables A variable is an abstraction of a memory cell A variable is an abstraction of a memory cell Variables can be characterized as a sextuple of attributes: (name, address, value, type, lifetime, and scope) Variables can be characterized as a sextuple of attributes: (name, address, value, type, lifetime, and scope) Type: determines the range of values of variables and the set of operations that are defined for values of that type Type: determines the range of values of variables and the set of operations that are defined for values of that type Address (L-value): the physical memory address Address (L-value): the physical memory address Value (R-value): the contents of the memory location Value (R-value): the contents of the memory location Aliases: multiple variables that have the same memory address Aliases: multiple variables that have the same memory address e.g., pointers and reference variables in C, C++ e.g., pointers and reference variables in C, C++ Sizes of a variable Sizes of a variable Abstract memory cell size vs. physical memory size Abstract memory cell size vs. physical memory size * AW Lecture Notes

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Bindings Binding: An association, such as between an attribute and an entity, or between an operation and a symbol Binding: An association, such as between an attribute and an entity, or between an operation and a symbol Binding Times: The times at which a binding takes place Binding Times: The times at which a binding takes place Language-design-time bindings (e.g., ‘*’ – multiplication) Language-design-time bindings (e.g., ‘*’ – multiplication) Language-implementation-time bindings (e.g., int – a range of possible values) Language-implementation-time bindings (e.g., int – a range of possible values) Compile-time bindings (e.g., a variable – a data type) Compile-time bindings (e.g., a variable – a data type) Load-time bindings (e.g., a variable – a memory cell) Load-time bindings (e.g., a variable – a memory cell) Link-time bindings (e.g., a call to a library function – subprogram codes) Link-time bindings (e.g., a call to a library function – subprogram codes) Run-time bindings (e.g., a variable – a value) Run-time bindings (e.g., a variable – a value) * AW Lecture Notes

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Type Bindings Static Type Bindings: A binding occurs before run time and remains unchanged throughout program execution Static Type Bindings: A binding occurs before run time and remains unchanged throughout program execution Explicit Type Declaration: Declaring the types of variables by using a program statement (e.g., Pascal, C, Java) Explicit Type Declaration: Declaring the types of variables by using a program statement (e.g., Pascal, C, Java) Implicit Type Declaration: Specifying types of variables based on default conventions Implicit Type Declaration: Specifying types of variables based on default conventions Based on the first appearance of the variable name in the program Based on the first appearance of the variable name in the program Based on the first letter (symbol) of a variable name (e.g., FORTRAN, Perl) Based on the first letter (symbol) of a variable name (e.g., FORTRAN, Perl)  Type Declarations (memory allocation) vs. Type Definitions Dynamic Type Bindings: S pecifying/changing a data type through an assignment statement (e.g., JavaScript Dynamic Type Bindings: S pecifying/changing a data type through an assignment statement (e.g., JavaScript ) e.g., list = [2, 4.33, 6, 8]; list = 17.3; Type Inference: Types are inferred from the type of constants (e.g., ML, Miranda, and Haskell) Type Inference: Types are inferred from the type of constants (e.g., ML, Miranda, and Haskell) e.g., fun circumf(r) = * r * r;

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Binding Lifetimes Static: Storage bindings remain throughout execution Static: Storage bindings remain throughout execution e.g. all FORTRAN 77 variables, Java static variables Advantages: efficiency (direct addressing); history-sensitive subprogram support Advantages: efficiency (direct addressing); history-sensitive subprogram support Disadvantage: lack of flexibility (no recursion) Disadvantage: lack of flexibility (no recursion) Stack-Dynamic: Storage bindings are created when their declaration statements are elaborated Stack-Dynamic: Storage bindings are created when their declaration statements are elaborated e.g. local variables in C subprograms and Java methods e.g. local variables in C subprograms and Java methods Advantage: allows recursion; conserves storage Advantage: allows recursion; conserves storage Disadvantages: overhead of allocation and deallocation; subprograms cannot be history sensitive; slower accesses (indirect addressing) Disadvantages: overhead of allocation and deallocation; subprograms cannot be history sensitive; slower accesses (indirect addressing) * AW Lecture Notes

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Binding Lifetimes (cont’d) Explicit Heap-Dynamic: Storages are allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution Explicit Heap-Dynamic: Storages are allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution e.g. dynamic objects in C++ (via new and delete) all objects in Java (new int[100]) all objects in Java (new int[100]) Advantage: provides for dynamic storage management Advantage: provides for dynamic storage management Disadvantage: inefficient and unreliable Disadvantage: inefficient and unreliable Implicit Heap-Dynamic: Storages are allocation and deallocation caused by assignment statements Implicit Heap-Dynamic: Storages are allocation and deallocation caused by assignment statements e.g. all variables in APL; all strings and arrays in Perl and JavaScript Advantage: flexibility Advantage: flexibility Disadvantages: inefficient, because all attributes are dynamic; loss of error detection by the compiler Disadvantages: inefficient, because all attributes are dynamic; loss of error detection by the compiler * AW Lecture Notes

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Type Checking Type Checking: the activity of ensuring that the operands of an operator are of compatible types Type Checking: the activity of ensuring that the operands of an operator are of compatible types Compatible Type: a type that is either legal for an operator, or is allowed under language rules to be implicitly converted to a legal type (coercion) Compatible Type: a type that is either legal for an operator, or is allowed under language rules to be implicitly converted to a legal type (coercion) Type Error: the application of an operator to an operand of an inappropriate type Type Error: the application of an operator to an operand of an inappropriate type A programming language is strongly typed if type errors are always detected A programming language is strongly typed if type errors are always detected * AW Lecture Notes

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Type Compatibility Name Type Compatibility: two variables have compatible types if they are in either the same declaration or in declarations that use the same type name Name Type Compatibility: two variables have compatible types if they are in either the same declaration or in declarations that use the same type name Easy to implement but highly restrictive Easy to implement but highly restrictive Subranges of integer types are not compatible with integer types Subranges of integer types are not compatible with integer types e.g.,type Indextype is ; count: Integer; index: Indextype; Formal parameters must be the same type as their corresponding actual parameters (Pascal) Formal parameters must be the same type as their corresponding actual parameters (Pascal) Structure Type Compatibility: two variables have compatible types if their types have identical structures Structure Type Compatibility: two variables have compatible types if their types have identical structures More flexible, but harder to implement More flexible, but harder to implement

March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Type Compatibility (cont’d) Derived Type: a new type that is based on some previously defined type Derived Type: a new type that is based on some previously defined type Derive types inherit all the properties of their parent types Derive types inherit all the properties of their parent types Derived types allow types with the same structure to be different Derived types allow types with the same structure to be different e.g., type celsius is new Float; type fahrenheit is new Float; type fahrenheit is new Float; Subtype: a range-constrained version of an existing type Subtype: a range-constrained version of an existing type A subtype is compatible with its parent type A subtype is compatible with its parent type e.g., subtype Small_type is Integer range 0..99; Anonymous Type: Unnamed type Anonymous Type: Unnamed type Anonymous types are all unique, even in Anonymous types are all unique, even in e.g., C, D : array (1..10) of Integer;