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

Size: px
Start display at page:

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

Transcription

1 Chapter 5 Basic Semantics Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, and the Environment Variables and Constants

2 Introduction Syntactic Specification: BNF, Syntax Diagram, etc. Semantic Specification Reference Manual natural language is used hard to be precise but easy to read Language Translator the execution of a program is mandatory to know the semantics machine dependant Formal Definition precise but hard to read (see Chapter 13) We will take the reference manual approach Programming Languages 2

3 Attributes Attributes The properties of language entities, typically identifiers For other language entities, say operator symbols, the attributes of which are often predetermined. Examples of Attributes the location of a variable: the place holder the value of an expression: the storable quantity the types of identifiers: determine the operations applicable the code of a procedure: the operation of the procedure the size of a certain type: determines the value range Programming Languages 3

4 Binding Binding The process of associating an attribute to a name Declarations (including definitions) bind the attributes to identifiers Example of Binding // C++ example int x, *y; x = 2; y = new int(3); x y Type: integer Value: 2 Type: integer pointer Value: 3 Programming Languages 4

5 Binding Time The time when a binding occurs Large Categories of Binding Times Static binding: the binding occurs prior to the execution Dynamic binding: the binding occurs during the execution Further Refined Binding Time Categories Language definition time Language implementation time Program translation time Link time Load time Execution time (run time) Programming Languages 5

6 Binding Time Examples The value of an expression execution time if it contains variables translation time if it is a constant expression The type of an identifier translation time in a compilation system (say, Java) execution time in an interpreter (say, LISP) The maximum number of digits of an integer language definition time for some languages (say, Java) language implementation time for others (say, C) The location of a variable load time for static variables (static in C) execution time for dynamic variables (auto in C) Programming Languages 6

7 Symbol Table and Environment Symbol Table The data structure (of a language translator) which maintains the binding information Mathematically, a function SymbolTable: Names Attributes In a Compilation System The attributes are maintained by multiple functions SymbolTable: Names (Some) StaticAttributes Environment: Names Locations Memory: Locations Values In an Interpretation System The symbol table and the environment are combined Environment: Names Attributes (including Locations and Values) Programming Languages 7

8 Declarations A principal method for establishing bindings implicit binding: implicitly assumed by a declaration explicit binding: explicitly specified by a declaration example) In the following C declaration, int x; the type binding is an explicit binding the location binding is an implicit binding Implicit Declaration The naming convention may determine the binding example) FORTRAN: the variable whose name starts with I, J, K, L, M, or N is implicitly an integer BASIC: the trailing % of variable means an integer, $ means a string Programming Languages 8

9 Different Terms for Declarations Some languages differentiate definitions from declarations Definition: a declaration that binds all potential attributes Declaration: a declaration that binds only a part of attributes C language example a function declaration (prototype) binds only the type (the interface) of the function an external variable declaration does not bind the location attributes an incomplete type specification (type declaration) may be used to resolve mutually recursive type definitions Programming Languages 9

10 Examples of C Declarations int x = 0; Explicitly specifies data type and initial value. Implicitly specifies scope (explained later) and location in memory. int f(double); Explicitly specifies type (double int) Implicitly specifies nothing else: needs another declaration specifying code The former is called a definition in C, the latter is simply a declaration. Programming Languages 10

11 Block and Locality Block a standard language construct which may contain declarations unit of allocations Locality of the Declarations or the References Local: the declaration and the reference for a name are in the same block Non-Local: the declaration of a name is not in the block which contains the reference for the name Note that we need some rules to locate corresponding declarations for non-local references. Programming Languages 11

12 Block-Structured Block-Structured Program The program is consisted of blocks, which may be nested Most Algol descendants exploit this structure Kinds of Blocks procedural block: Pascal non-procedural block: Ada, C -- Ada example (* Pascal example *) declare x: integer; begin end program ex; var x: integer begin end Programming Languages 12

13 Other entities containing declarations Structured Data Type a type declaration which contains declarations examples: struct in C, class in C++, Java, Smalltalk Module or Package a collection of declarations the collection itself is not a declaration examples) Ada: package and task Java: package ML and Haskell: module C++: namespace Programming Languages 13

14 Scope Scope of a Binding the region of the program over which the binding is maintained Scope of a Name (abuse of the term scope ) the same name may declared multiply these different declarations of the same name should be differentiated Scope and Block Declaration before Use Rule: The scope is typically extends to the end of the block which contains the declaration In some constructs, the scope may extend backwards to the beginning of the block (classes in Java and C++, top-level declarations in Scheme) Programming Languages 14

15 Scope Rules Lexical Scope (Static Scope) Rule the scope of a binding is the inside of the block which contains the corresponding declaration the standard scope rule of most block-structured languages Dynamic Scope Rule the scope of a binding is determined according to the execution path the symbol table (or the environment) should be managed dynamically Programming Languages 15

16 Lexical Scope Example (C) int x; void p(void) { char y;... } /* p */ y In C, the declaration before use rule apply. void q(void) { double z;... } /* q */ z p x main() { int w[10];... } w main q Programming Languages 16

17 Scope Holes What is a scope hole? a local declaration of a name can mask a prior declaration of the same name in this case, the masked declaration has a scope hole over the corresponding block Visibility and Scope Visibility: the region where the declared name is visible (excluding scope holes) Scope: the region where the binding exists (including scope holes) Programming Languages 17

18 Scope Resolution Operator // C++ example int x; void p(void) { char x; x = 'a'; // local x ::x = 42; // global x... } /* p */ main() { x = 2; // global x... } The global integer variable x has a scope hole in the body of p. In C, the global x cannot be referenced in p. In C++, the global x can be referenced in p using a scope resolution operator ::. Ada also has a scope resolution operator.. Programming Languages 18

19 File Scope in C File Scope In C, a global name can be turned into a file scope name by attaching the keyword static. A file scope name can only be referenced in that file. Example File 1 extern int x;... x... File 2 int x;... x... File 3 static int x;... x... Programming Languages 19

20 Recursive Declaration Recursive functions are generally well-defined int factorial(int n) {... factorial(n 1)... } How about recursive variables? int x = x + 1; Not allowed in Ada or Java Allowed in C/C++ for local variables but meaningless Dealing with mutual recursions in the context of declaration before use rule. forward declarations in Pascal prototype declarations in C/C++ Programming Languages 20

21 Java Scope Example public class Scope { public static void f() { System.out.println(x); } public static void main(string[] args) } { int x = 3; f(); } public static int x = 2; In Java classes, the declaration before use rule does not apply. In a class declaration, the scope of a declaration is the entire class. Note the underlined declaration. The result may differ according to the scope rules. The above code prints 2. (Java adopts lexical scope rule) Under dynamic scope rule, the code would print 3. Programming Languages 21

22 Dynamic Scope Evaluated Disadvantages of the Dynamic Scope The scope of a declaration cannot be determined statically. (Hand-simulation is needed to find the applicable declaration.) The types of identifiers cannot be determined statically. (A static type-checking is impossible) Historical Note Originally used in Lisp. Scheme could still use it, but doesn't. Some languages still use it: VBScript, Javascript, Perl (older versions). Lisp inventor (McCarthy) now calls it a bug. Programming Languages 22

23 Symbol Table Maintenance In a lexically scoped languages, The symbol table is maintained like a stack. The symbol table is maintained statically, i.e. regardless to the execution path. In a dynamically scoped languages, All the bindings of the outermost names are constructed. The bindings are maintained according to the execution path. Programming Languages 23

24 Symbol Table under Lexical Scope int x; char y; void p(void) { double x;... { /* block b */ int y[10];... }... } void q(void) { int y;... } x y p q main double int char local global to main p int[10] char local global to bq void function void function int function int int global global char global main() { char x;... } Programming Languages 24

25 Symbol Table under Dynamic Scope #include <stdio.h> int x = 1; char y = 'a'; void p(void) { double x = 2.5; printf("%c\n",y) { /* block b */ int y[10]; } } void q(void) { int y = 42; printf("%d\n",x); p(); } main() { char x = 'b'; q(); return 0; } x y p q main Output double=2.5 char='b' int=1 local global local to to main p int=42 char='a' local global to q void function void function int function 98 * char int=1 global char='a' global ASCII value of 'b' ASCII 42 = 'b' Programming Languages 25

26 Nested Symbol Table Scoping Structures Some language constructs are allowed to have their own name spaces Examples Pascal: functions, procedures C++: classes, functions, structures, namespaces Java: classes, methods, packages Stacks of Symbol Tables When a language has scoping structures, it may be convenient to construct stacks of symbol tables Programming Languages 26

27 Nested Symbol Table Example public class Scope { public static void f() { System.out.println(x); } public static void main(string[] args) { int x = 3; f(); } public static int x = 2; } name name Scope bindings public class symtab f main x bindings Under lexical scope, the symbol table of the left code can be the following. public static void method symtab public static void method symtab public static int name name args bindings String[] parameter Programming Languages 27 x (empty) bindings int local

28 Overloading What is overloading? reusing names for different entities of a kind within the same scope entity 1 /name 1, entity 2 /name 2 (entity 1, entity 2 )/name the name is overloaded in the above case operator overloading, function overloading Overload Resolution choosing the appropriate entity for the given usage of the overloaded name the calling context (the information contained in a call) is generally used for overload resolution Programming Languages 28

29 Overloading Example In most languages, the operator + is overloaded integer addition (say, ADDI) floating point number addition (say, ADDF) Disambiguating Clue: data types of operands How about mixed-type expression? C/C++ adopts promotion (implicit type conversion). Ada treats the above expression error. Programming Languages 29

30 Function Overloading int max(int x, int y) // max #1 { return x > y? x : y; } double max(double x, double y) // max #2 { return x > y? x : y; } int max(int x, int y, int z) // max #3 { return x > y? (x > z? x : z) : (y > z? y : z); } Name resolution max(2,3) calls max #1 max(2.1,3.2) calls max #2 max(1,3,2) calls max #3 Programming Languages 30

31 Overload Resolution Issues Implicit conversions may cause ambiguous calls max(2.1, 3) C++: too many candidates (max #1 or max #2) Ada: no candidates Java: implicit conversions are used only for the cases of no information loss Whether the return type is included in the calling context or not C++, Java: not included Ada: included Programming Languages 31

32 Function Overloading in Ada procedure overload is function max(x: integer; y: integer) -- max #1 return integer is begin... end max; function max(x: integer; y: integer) -- max #2 return float is begin... end max; a: integer; b: float; begin -- max_test a := max(2,3); -- call to max # 1 b := max(2,3); -- call to max # 2 end overload; In Ada, the return type is included in the calling context. Programming Languages 32

33 Operator Overloading in C++ #include <iostream> using namespace std; typedef struct { int i; double d; } IntDouble; bool operator < (IntDouble x, IntDouble y) { return x.i < y.i && x.d < y.d; } IntDouble operator + (IntDouble x, IntDouble y) { IntDouble z; z.i = x.i + y.i; z.d = x.d + y.d; return z; } int main() { IntDouble x = {1,2.1}, y = {5,3.4}; if (x < y) x = x + y; else y = x + y; cout << x.i << " " << x.d << endl; return 0; } Programming Languages 33

34 Operator Overloading in Ada procedure opover is type IntDouble is record i: Integer; d: Float; end record; function "<" (x,y: IntDouble) return Boolean is... function "+" (x,y: IntDouble) return IntDouble is... x, y: IntDouble; begin x := (1,2.1); y := (5,3.4); if (x < y) then x := x + y; else y := x + y; end if; put(x.i); put(" "); put(x.d); new_line; end opover; Programming Languages 34

35 Notes on Operator Overloading The syntactic properties (associativity and precedence) of the operators are not changed by operator overloading. Special notations are used for prefix form of the operators. x + y prefix form in Ada: "+"(x, y) prefix form in C++: operator + (x, y) Programming Languages 35

36 Other Kinds of Reuse of Names Reusing names for different kinds of entities Separate name space for each kind is needed. These kinds of reusing is not an overloading. C example typedef struct A A; struct A { int data; A * next; }; structure tag name type name Java example class A { A A(A A) { A: for(;;) } } Which is which? class name method name parameter name label name { if (A.A(A) == A) break A; } return A; Programming Languages 36

37 Environment Environment Construction Time static environment: FORTRAN dynamic environment: LISP mixture: most Algol-style languages Variable Allocation Time in a Algol-style Language global variables static allocation allocated in load time local variables mostly dynamic allocation allocated in the declaration elaboration time (i.e. when the control flow passing the declaration) Programming Languages 37

38 Typical Environment Components of Typical Algol-style Languages static area for static allocation stack for LIFO-style dynamic allocation heap for on-demand dynamic allocation Programming Languages 38

39 Activation Record Activation an invocation of a subprogram the subprogram environment should be constructed for each activation Activation Record the region of memory allocated for an activation subprogram environment + bookkeeping information Run-Time Stack block enters and exits are LIFO-style procedure calls and returns are LIFO-style activation records are stored in the run-time stack Programming Languages 39

40 Run-Time Stack Manipulation A: { int x; char y; point 1 B: { double x; int a; } /* end B */ C: { char y; int b; D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Programming Languages 40

41 Run-Time Stack Manipulation A: { int x; char y; B: { double x; int a; point 2 } /* end B */ C: { char y; int b; D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Programming Languages 41

42 Run-Time Stack Manipulation A: { int x; char y; B: { double x; int a; } /* end B */ C: { char y; point 3 int b; D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Programming Languages 42

43 Run-Time Stack Manipulation A: { int x; char y; B: { double x; int a; } /* end B */ C: { char y; int b; point 4 D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Programming Languages 43

44 Run-Time Stack Manipulation A: { int x; char y; B: { double x; int a; } /* end B */ C: { char y; int b; D: { int x; double y; point 5 } /* end D */ } /* end C */ } /* end A */ Programming Languages 44

45 Heap Manipulation Heap (Free Store) the memory pool for the objects allocated manually Heap Deallocation manual deallocation: special functions or operators are used for deallocation (free in C, delete in C++) automatic deallocation: garbage collector is used (more safe but somewhat slow, Java) Ada Approach Ada does not provide delete operation but allows a userdefined deallocation (Unchecked_Deallocation) Programming Languages 45

46 Pointer and Dereferencing Pointer an object whose value is a reference to an object Dereferencing referencing an object via a pointer value In order to manipulate the heap objects, pointers are mandatory (either implicitly or explicitly) /* C example */ int *x; // pointer declaration x = (int*)malloc(sizeof(int)); // memory allocation *x = 5; // dereferencing free(x); // deallocation Programming Languages 46

47 Lifetime Storable Object a chunk of memory cells an area of storage that is allocated in the environment The Lifetime (or Extent) of an Object the duration of its allocation in the environment Lifetime vs. Scope the lifetime and the scope of variables are closely related but not identical (cf. local static variables in C/C++) according to the scope: local, global according to the lifetime: static, dynamic Programming Languages 47

48 Local Static Variable Example (C) int p(void) { static int p_count = 0; /* initialized only once - not each call! */ p_count += 1; return p_count; The variable p_count counts the } number of calls of the function p. Accordingly, p is history sensitive. main() Guess the output! { int i; for (i = 0; i < 10; i++) { if (p() % 3) printf("%d\n",p()); } return 0; } Programming Languages 48

49 Variables and Constants Variable an object whose value may change during execution Constants an object whose value does not change for its lifetime Literals a language entity whose value is explicit from its name a kind of constants but may never be allocated Programming Languages 49

50 Diagrams for Variables Schematic Representation Box-Circle Diagram Programming Languages 50

51 L-value and R-value L-value and R-value of a Variable l-value (LHS value): the location r-value (RHS value): the value stored Language Examples ML has only references and the r-value is explicit. x :=!x + 1!x means r-value of x. C has address-of operator (&) and dereferencing operator (*) but the distinction of l-values and r-values is normally implicit. Programming Languages 51

52 Assignment General Syntax infix notation variable assingmentopertor expression Semantics storage semantics assignment by value-copying pointer semantics assignment by sharing (shallow copying) assignment by cloning (deep copying) Programming Languages 52

53 Assignment by Value-Copying The value of the variable is copied. x = y Programming Languages 53

54 Assignment by Sharing The location of the variable is copied. x = y Programming Languages 54

55 Assignment by Cloning The location and the value of the variable is duplicated. x = y Programming Languages 55

56 Java Example Java supports all the kinds of assignment semantics assignment of object variables: assignment by sharing assignment of simple data: assignment by value-copying object cloning is supported by the method clone. A closer view of object assignment in Java x = y Programming Languages 56

57 Constant Semantics Schematic Diagram for Constants Constant has Value Semantics Once the value binding is constructed, the value cannot be changed The location of a constant cannot be referred to. Programming Languages 57

58 Classification of Constants Literals and Named Constants literals: names denote the exact value named constants: names for the meaning of the value Classification of Named Constants static constants (manifest constants) compile-time static constants (may never be allocated) load-time static constants dynamic constants Programming Languages 58

59 Constant Example (Java) Compile-time constant in Java: static final int zero = 0; Load-time constant in Java: static final Date now = new Date(); Dynamic constant in Java: any non-static final assigned in a constructor. Java vs. C Java takes a very general view of constants, since it is not very worried about getting rid of them during compilation. C takes a much stricter view of constants, essentially forcing them to be capable of elimination during compilation. Programming Languages 59

60 Constant Initialization C vs. C++ In C, the initial value of a static constant (or a static variable) should be computed from literals only In C++, the above restriction is removed #include <stdio.h> #include <time.h> const int a = 2; const int b = 27+2*2; /* legal in C */ const int c = (int) time(0); /* illegal C code! */ int b = 27+a*a; /* also illegal in C */ Programming Languages 60

61 How about functions? Function Constants The function names in most languages are constants. Function Variables may be implemented by pointers Function Literals (anonymous functions) Most functional languages support anonymous functions. /* function pointer in C */ int gcd( int u, int v) { if (v == 0) return u; else return gcd(v, u % v); } int (*fv)(int,int) = gcd; main() { printf("%d\n", fv(15,10)); return 0; } Anonymous function in ML (fn(x:int) => x * x) 2; evaluates val it = 4 : int Programming Languages 61

62 Aliases Aliases two or more different names for the same object at the same time bad for readability (may cause potentially harmful side effects; see the next slide) Side Effect any change persists beyond the execution of a statement Potentially Harmful Side Effect the side effect cannot be determined from the written statement the previous code should also be read Programming Languages 62

63 An Example of Harmful Aliases main() { int *x, *y; x = (int *) malloc(sizeof(int)); *x = 1; y = x; /* *x and *y now aliases */ *y = 2; printf("%d\n",*x); return 0; } Programming Languages 63

64 What makes aliases? What makes aliases? pointer assignment call-by-reference parameters assignment by sharing explicit-mechanism for aliasing: EQUIVALENCE and COMMON in FORTRAN variant records Why explicit-mechanism for aliasing in FORTRAN? in order to save memory the memory was a valuable resource at that time Programming Languages 64

65 Dangling References Dangling References locations accessible but deallocated the locations are deallocated too early dangerous! What makes dangling references? pointer assignment and explicit deallocation pointer assignment and implicit deallocation by block exit by function exit Programming Languages 65

66 An Example of Dangling References main() { int *x, *y; x = (int *) malloc(sizeof(int)); *x = 1; y = x; /* *x and *y now aliases */ free(x); /* *y now a dangling reference */ printf("%d\n",*y); /* illegal reference */ return 0; } Programming Languages 66

67 Garbage Garbage (Dangling Objects) inaccessible memory locations that are allocated the locations are deallocated too late a waste of memory but not harmful What makes garbage? explicit allocation and the access point is lost due to assignment deallocation of the access point Programming Languages 67

68 An Example of Garbage main() { int *x; x = (int *) malloc(sizeof(int)); x = 1; /* OOPS! */... return 0; } Programming Languages 68

69 Garbage Collection A language subsystem that automatically reclaims garbage. Most functional language implementations and some object-oriented language implementations are using garbage collectors. (See Section 8.5) Programming Languages 69

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

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

Chapter 5. Names, Bindings, and Scopes

Chapter 5. Names, Bindings, and Scopes Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

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

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility Informal Semantics of Data semantic specification names (identifiers) attributes binding declarations scope rules visibility 1 Ways to Specify Semantics Standards Documents (Language Definition) Language

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

TYPES, VALUES AND DECLARATIONS

TYPES, VALUES AND DECLARATIONS COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

Names, Bindings, Scopes

Names, Bindings, Scopes Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not

More information

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2 Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers Chapter 6: Data Types 2 5-1 Data Types Two components: Set of objects in the type (domain

More information

Imperative Programming

Imperative Programming Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von

More information

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

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility Quiz Review Q1. What is the advantage of binding things as early as possible? Is there any advantage to delaying binding? Answer: Early binding generally leads to greater efficiency (compilation approach)

More information

Lecture 4 Memory Management

Lecture 4 Memory Management Lecture 4 Memory Management Dr. Wilson Rivera ICOM 4036: Programming Languages Electrical and Computer Engineering Department University of Puerto Rico Some slides adapted from Sebesta s textbook Lecture

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables

More information

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-00 014 Subject: PPL Class : CSE III 1 P a g e DEPARTMENT COMPUTER SCIENCE AND ENGINEERING S No QUESTION Blooms Course taxonomy level Outcomes UNIT-I

More information

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

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture Topics Chapter 5 Variables Imperative Paradigm Variables Names Address Types Assignment Binding Lifetime Scope Constants 2 Imperative Paradigm The most widely used and well-developed programming paradigm.

More information

Names, Scopes, and Bindings II. Hwansoo Han

Names, Scopes, and Bindings II. Hwansoo Han Names, Scopes, and Bindings II Hwansoo Han Scope Rules A scope is textual region where bindings are active A program section of maximal size Bindings become active at the entry No bindings change in the

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Variables and Constants R. Sekar 1 / 22 Topics 2 / 22 Variables and Constants Variables are stored in memory, whereas constants need not be. Value of variables

More information

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008. Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008. Outline. Dynamic Allocation. Variables and Constants. Aliases and Problems. Garbage. Introduction. On Wednesday, we were talking

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:

More information

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

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer. The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

Data Types In Text: Ch C apter 6 1

Data Types In Text: Ch C apter 6 1 Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 2 Data Types Two components: Set of objects in the type (domain of values) Set of applicable

More information

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CPSC 3740 Programming Languages University of Lethbridge. Data Types Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

More information

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

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5 Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur

More information

Type Bindings. Static Type Binding

Type Bindings. Static Type Binding Type Bindings Two key issues in binding (or associating) a type to an identifier: How is type binding specified? When does the type binding take place? N. Meng, S. Arthur 1 Static Type Binding An explicit

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Binding and Variables

Binding and Variables Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia

More information

6. Names, Scopes, and Bindings

6. Names, Scopes, and Bindings Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference

More information

Names, Scope, and Bindings

Names, Scope, and Bindings Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Fall 2003 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,

More information

Implementing Subprograms

Implementing Subprograms Implementing Subprograms 1 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms Blocks Implementing

More information

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection Storage 1 Variables and updating Outline Copy vs. Ref semantics Lifetime Local and global variables Heap variables Persistent variables Dangling References Garbage collection 2 Variables and Updating Variable:

More information

Data Types (cont.) Subset. subtype in Ada. Powerset. set of in Pascal. implementations. CSE 3302 Programming Languages 10/1/2007

Data Types (cont.) Subset. subtype in Ada. Powerset. set of in Pascal. implementations. CSE 3302 Programming Languages 10/1/2007 CSE 3302 Programming Languages Data Types (cont.) Chengkai Li Fall 2007 Subset U = { v v satisfies certain conditions and v V} Ada subtype Example 1 type Digit_Type is range 0..9; subtype IntDigit_Type

More information

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character

More information

Names, Scope, and Bindings

Names, Scope, and Bindings Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Fall 2007 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

More information

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

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

More information

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Topic IV. Block-structured procedural languages Algol and Pascal. References: References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

More information

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

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 57 CSE 307: Principles of Programming Languages Course Review R. Sekar Course Topics Introduction and History Syntax Values and types Names, Scopes and Bindings Variables and Constants Expressions

More information

Semantics (cont.) Symbol Table. Static Scope. Static Scope. Static Scope. CSE 3302 Programming Languages. Static vs. Dynamic Scope

Semantics (cont.) Symbol Table. Static Scope. Static Scope. Static Scope. CSE 3302 Programming Languages. Static vs. Dynamic Scope -2-1 CSE 3302 Programming Languages Semantics (cont.) Smbol Table Smbol Table: maintain bindings. Can be viewed as functions that map names to their attributes. Names SmbolTable Attributes Chengkai Li,

More information

CS558 Programming Languages. Winter 2013 Lecture 3

CS558 Programming Languages. Winter 2013 Lecture 3 CS558 Programming Languages Winter 2013 Lecture 3 1 NAMES AND BINDING One essential part of being a high-level language is having convenient names for things: variables constants types functions etc. classes

More information

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

Programmiersprachen (Programming Languages)

Programmiersprachen (Programming Languages) 2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

More information

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character

More information

Names, Scope, and Bindings

Names, Scope, and Bindings Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Spring 2007 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,

More information

Concepts Introduced in Chapter 7

Concepts Introduced in Chapter 7 Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

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

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 18: Code Generation V (Implementation of Dynamic Data Structures) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/

More information

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics PIC 10A Pointers, Arrays, and Dynamic Memory Allocation Ernest Ryu UCLA Mathematics Pointers A variable is stored somewhere in memory. The address-of operator & returns the memory address of the variable.

More information

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:

More information

CSCE 314 Programming Languages. Type System

CSCE 314 Programming Languages. Type System CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be

More information

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts Topics Chapter 6 Structured Data Types Vectors Arrays Slices Associative Arrays Records Unions Lists Sets 2 Structured Data Types Virtually all languages have included some mechanisms for creating complex

More information

MIDTERM EXAMINATION - CS130 - Spring 2005

MIDTERM EXAMINATION - CS130 - Spring 2005 MIDTERM EAMINATION - CS130 - Spring 2005 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 231 + 25 extra credit This exam counts for 25%

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage Storage 1 Variables and Updating Outline Composite Variables Total and selective updating Array variables Storables Lifetime Local and global variables Heap variables Persistent variables Garbage collection

More information

Types and Type Inference

Types and Type Inference CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of

More information

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu 1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1 Subprograms Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly

More information

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

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

Programming Languages & Paradigms PROP HT Course Council. Subprograms. Meeting on friday! Subprograms, abstractions, encapsulation, ADT

Programming Languages & Paradigms PROP HT Course Council. Subprograms. Meeting on friday! Subprograms, abstractions, encapsulation, ADT Programming Languages & Paradigms PROP HT 2011 Lecture 4 Subprograms, abstractions, encapsulation, ADT Beatrice Åkerblom beatrice@dsv.su.se Course Council Meeting on friday! Talk to them and tell them

More information

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and

More information

Implementing Subprograms

Implementing Subprograms 1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

Control Flow February 9, Lecture 7

Control Flow February 9, Lecture 7 Chapter 6 Control Flow February 9, Lecture 7 Expressions A simple object Literal constant Named variable Constant Or a function applied to arguments For built-in functions we use the term operator (like

More information

Types. What is a type?

Types. What is a type? Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations

More information

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

Scope. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill Scope Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Referencing Environment

More information

References and pointers

References and pointers References and pointers Pointers are variables whose value is a reference, i.e. an address of a store location. Early languages (Fortran, COBOL, Algol 60) had no pointers; added to Fortran 90. In Pascal,

More information

CSE 3302 Programming Languages Lecture 5: Control

CSE 3302 Programming Languages Lecture 5: Control CSE 3302 Programming Languages Lecture 5: Control (based on the slides by Chengkai Li) Leonidas Fegaras University of Texas at Arlington CSE 3302 L5 Fall 2009 1 Control Control: what gets executed, when,

More information

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

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

Types and Type Inference

Types and Type Inference Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion

More information

Symbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is

More information

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad -500 043 INFORMATION TECHNOLOGY TUTORIAL QUESTION BANK Name : PRINCIPLES OF PROGRAMMING LANGUAGES Code : A40511 Class : II B. Tech

More information

Compiler construction

Compiler construction Compiler construction Martin Steffen March 13, 2017 Contents 1 Abstract 1 1.1 Symbol tables. 1 1.1.1 Introduction 1 1.1.2 Symbol table design and interface.. 2 1.1.3 Implementing symbol tables 3 1.1.4

More information

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 13: Types and Type-Checking 19 Feb 07 Semantic Analysis Last time: Semantic errors related to scopes Symbol tables Name resolution This lecture:

More information

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

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

More information

Chapter 7 Control I Expressions and Statements

Chapter 7 Control I Expressions and Statements Chapter 7 Control I Expressions and Statements Expressions Conditional Statements and Guards Loops and Variation on WHILE The GOTO Controversy Exception Handling Values and Effects Important Concepts in

More information

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

CS321 Languages and Compiler Design I Winter 2012 Lecture 13 STATIC SEMANTICS Static Semantics are those aspects of a program s meaning that can be studied at at compile time (i.e., without running the program). Contrasts with Dynamic Semantics, which describe how

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

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

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Scope and Lifetime Type Checking Referencing Environments Named Constants Names Used for variables, subprograms

More information