Programming Languages Third Edition. Chapter 7 Basic Semantics

Size: px
Start display at page:

Download "Programming Languages Third Edition. Chapter 7 Basic Semantics"

Transcription

1 Programming Languages Third Edition Chapter 7 Basic Semantics

2 Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol table Understand name resolution and overloading Understand allocation, lifetimes, and the environment Programming Languages, Third Edition 2

3 Objectives (cont d.) Work with variables and constants Learn how to handle aliases, dangling references, and garbage Perform an initial static semantic analysis of TinyAda Programming Languages, Third Edition 3

4 Introduction Syntax: what the language constructs look like Semantics: what the language constructs actually do Specifying semantics is more difficult than specifying syntax Several ways to specify semantics: Language reference manual Defining a translator Formal definition Programming Languages, Third Edition 4

5 Introduction (cont d.) Language reference manual: Most common way to specify semantics Provides clearer and more precise reference manuals Suffers from a lack of precision inherent in natural language descriptions May have omissions and ambiguities Programming Languages, Third Edition 5

6 Introduction (cont d.) Defining a translator: Questions about a language can be answered by experimentation Questions about program behavior cannot be answered in advance Bugs and machine dependencies in the translator may become part of the language semantics, possibly unintentionally May not be portable to all machines May not be generally available Programming Languages, Third Edition 6

7 Introduction (cont d.) Formal definition: Formal mathematical methods: precise, but are also complex and abstract Requires study to understand Denotational semantics: probably the best formal method for the description of the translation and execution of programs Describes semantics using a series of functions This course will use a hybrid of informal description with the simplified functions used in denotational descriptions Programming Languages, Third Edition 7

8 Attributes, Binding, and Semantic Functions Names (or identifiers): a fundamental abstraction mechanism used to denote language entities or constructs Fundamental step in describing semantics is to describe naming conventions for identifiers Most languages also include concepts of location and value Value: any storable quantities Location: place where value can be stored; usually a relative location Programming Languages, Third Edition 8

9 Attributes, Binding, and Semantic Functions (cont d.) Attributes: properties that determine the meaning of the name to which they are associated Example in C: Attributes for variables and constants include data type and value Example in C: Attributes include function, number, names and data type of parameters, return value data type, body of code to be executed Programming Languages, Third Edition 9

10 Attributes, Binding, and Semantic Functions (cont d.) Assignment statements associate attributes to names Example: Associates attribute value 2 to variable x Example in C++: Allocates memory (associates location to y) Associates value Programming Languages, Third Edition 10

11 Attributes, Binding, and Semantic Functions (cont d.) Binding: process of associating an attribute with a name Binding time: the time when an attribute is computed and bound to a name Two categories of binding: Static binding: occurs prior to execution Dynamic binding: occurs during execution Static attribute: an attribute that is bound statically Dynamic attribute: an attribute that is bound dynamically Programming Languages, Third Edition 11

12 Attributes, Binding, and Semantic Functions (cont d.) Languages differ substantially in which attributes are bound statically or dynamically Functional languages tend to have more dynamic binding than imperative languages Static attributes can be bound during translation, during linking, or during loading of the program Dynamic attributes can be bound at different times during execution, such as entry or exit from a procedure or from the program Programming Languages, Third Edition 12

13 Attributes, Binding, and Semantic Functions (cont d.) Some attributes are bound prior to translation time Predefined identifiers: specified by the language definition Values true/false bound to data type Boolean maxint specified by language definition and implementation All binding times except execution time are static binding Programming Languages, Third Edition 13

14 Attributes, Binding, and Semantic Functions (cont d.) A translator creates a data structure to maintain bindings Can be thought of as a function that expresses the binding of attributes to names Symbol table: a function from names to attributes Programming Languages, Third Edition 14

15 Attributes, Binding, and Semantic Functions (cont d.) Parsing phase of translation includes three types of analysis: Lexical analysis: determines whether a string of characters represents a token Syntax analysis: determines whether a sequence of tokens represents a phrase in the context-free grammar Static semantic analysis: establishes attributes of names in declarations and ensures that the use of these names conforms to their declared attributes During execution, attributes are also maintained Programming Languages, Third Edition 15

16 Attributes, Binding, and Semantic Functions (cont d.) Programming Languages, Third Edition 16

17 Declarations, Blocks, and Scope Bindings can be implicit or explicit Example: Data type is bound explicitly; location of x is bound implicitly Entire declaration itself may be implicit in languages where simply using the variable name causes it to be declared Definition: in C and C++, a declaration that binds all potential attributes Prototype: function declaration that specifies the data type but not the code to implement it Programming Languages, Third Edition 17

18 Declarations, Blocks, and Scope (cont d.) Block: a sequence of declarations followed by a sequence of statements Compound statements: blocks in C that appear as the body of functions or anywhere an ordinary program statement could appear Local declarations: associated with a block Nonlocal declarations: associated with surrounding blocks Block-structured languages allow nesting of blocks and redeclaration of names within nested blocks Programming Languages, Third Edition 18

19 Declarations, Blocks, and Scope (cont d.) Each declared name has a lexical address containing a level number and an offset Level number starts at 0 and increases into each nested block Other sources of declarations include: A struct definition composed of local (member) declarations A class in object-oriented languages Declarations can be collected into packages (Ada), modules (ML, Haskell, Python), and namespaces (C++) Programming Languages, Third Edition 19

20 Declarations, Blocks, and Scope (cont d.) Scope of a binding: region of the program over which the binding is maintained Lexical scope: in block-structured languages, scope is limited to the block in which its associated declaration appears (and other blocks contained within it) Declaration before use rule: in C, scope of a declaration extends from the point of declaration to the end of the block in which it is located Programming Languages, Third Edition 20

21 Programming Languages, Third Edition 21

22 Programming Languages, Third Edition 22

23 Declarations, Blocks, and Scope (cont d.) Declarations in nested blocks take precedence over previous declarations A global variable is said to have a scope hole in a block containing a local declaration with the same name Use scope resolution operator :: in C++ to access the global variable Local declaration is said to shadow its global declaration Visibility: includes only regions where the bindings of a declaration apply Programming Languages, Third Edition 23

24 Declarations, Blocks, and Scope (cont d.) Programming Languages, Third Edition 24

25 Declarations, Blocks, and Scope (cont d.) Scope rules need to be constructed such that recursive (self-referential) declarations are possible when they make sense Example: functions must be allowed to be recursive, so function name must have scope beginning before the block of the function body Programming Languages, Third Edition 25

26 The Symbol Table Symbol table: Must support insertion, lookup, and deletion of names with associated attributes, representing bindings in declarations A lexically scoped, block-structured language requires a stack-like data structure to perform scope analysis: On block entry, all declarations of that block are processed and bindings added to symbol table On block exit, bindings are removed, restoring any previous bindings that may have existed Programming Languages, Third Edition 26

27 Programming Languages, Third Edition 27

28 The Symbol Table (cont d.) Programming Languages, Third Edition 28

29 The Symbol Table (cont d.) Programming Languages, Third Edition 29

30 The Symbol Table (cont d.) Programming Languages, Third Edition 30

31 The Symbol Table (cont d.) Programming Languages, Third Edition 31

32 The Symbol Table (cont d.) Programming Languages, Third Edition 32

33 The Symbol Table (cont d.) Programming Languages, Third Edition 33

34 Programming Languages, Third Edition 34

35 The Symbol Table (cont d.) The previous example assumes that declarations are processed statically (prior to execution) This is called static scoping or lexical scoping Symbol table is managed by a compiler Bindings of declarations are all static If symbol table is managed dynamically (during execution), declarations will be processed as they are encountered along an execution path This is called dynamic scoping Programming Languages, Third Edition 35

36 Programming Languages, Third Edition 36

37 Programming Languages, Third Edition 37

38 Programming Languages, Third Edition 38

39 Programming Languages, Third Edition 39

40 The Symbol Table (cont d.) Dynamic scoping will affect the semantics of the program and produce different output Output using lexical scoping: Output using dynamic scoping: Dynamic scope can be problematic, which is why few languages use it Programming Languages, Third Edition 40

41 The Symbol Table (cont d.) Problems with dynamic scoping: The declaration of a nonlocal name cannot be determined by simply reading the program: the program must be executed to know the execution path Since nonlocal variable references cannot be predicted prior to execution, neither can their data types Dynamic scoping is a possible option for highly dynamic, interpreted languages when programs are not expected to be extremely large Programming Languages, Third Edition 41

42 The Symbol Table (cont d.) Runtime environment is simpler with dynamic scoping in an interpreter APL, Snobol, Perl, and early dialects of Lisp were dynamically scoped Scheme and Common Lisp use static scoping There is additional complexity for symbol tables struct declaration must contain further declarations of the data fields within it Those fields must be accessible using dot member notation whenever the struct variable is in scope Programming Languages, Third Edition 42

43 The Symbol Table (cont d.) Two implications for struct variables: A struct declaration actually contains a local symbol table itself as an attribute This local symbol table cannot be deleted until the struct variable itself is deleted from the global symbol table of the program Programming Languages, Third Edition 43

44 Programming Languages, Third Edition 44

45 Programming Languages, Third Edition 45

46 The Symbol Table (cont d.) Any scoping structure that can be referenced directly must also have its own symbol table Examples: Named scopes in Ada Classes, structs, and namespaces in C++ Classes and packages in Java Typically, there will be a table for each scope in a stack of symbol tables When a reference to a name occurs, a search begins in the current table and continues to the next table if not found, and so on Programming Languages, Third Edition 46

47 Programming Languages, Third Edition 47

48 Programming Languages, Third Edition 48

49 Name Resolution and Overloading Addition operator + actually indicates at least two different operations: integer addition and floatingpoint addition + operator is said to be overloaded Translator must look at the data type of each operand to determine which operation is indicated Overload resolution: process of choosing a unique function among many with the same name Lookup operation of a symbol table must search on name plus number and data type of parameters Programming Languages, Third Edition 49

50 Name Resolution and Overloading (cont d.) Programming Languages, Third Edition 50

51 Name Resolution and Overloading (cont d.) Consider these function calls: Symbol table can determine the appropriate function based on number and type of parameters Calling context: the information contained in each call But this ambiguous call depends on the language rules (if any) for converting between data types: Programming Languages, Third Edition 51

52 Name Resolution and Overloading (cont d.) Adding these definitions makes the function calls legal in C++ and Ada but is unnecessary in Java Automatic conversions as they exist in C++ and Java significantly complicate overload resolution Programming Languages, Third Edition 52

53 Name Resolution and Overloading (cont d.) Additional information in a calling context may be used for overload resolution: Ada allows the return type and names of parameters to be used for overhead resolution C++ and Java ignore the return type Both Ada and C++ (but not Java) allow built-in operators to be overloaded When overloading a built-in operator, we must accept its syntactic properties Example: cannot change the associativity or precedence of the + operator Programming Languages, Third Edition 53

54 Name Resolution and Overloading (cont d.) Note that there is no semantic difference between operators and functions, only syntactic difference Operators are written in infix form Function calls are always written in prefix form Names can also be overloaded Some languages use different symbol tables for each of the major kinds of definitions to allow the same name for a type, a function, and a variable Example: Java Programming Languages, Third Edition 54

55 Name Resolution and Overloading (cont d.) Programming Languages, Third Edition 55

56 Allocation, Lifetimes, and the Environment Environment: maintains the bindings of names to locations May be constructed statically (at load time), dynamically (at execution time), or with a mixture of both Not all names in a program are bound to locations Examples: names of constants and data types may represent purely compile-time quantities Declarations are also used in environment construction Indicate what allocation code must be generated Programming Languages, Third Edition 56

57 Allocation, Lifetimes, and the Environment (cont d.) Typically, in a block-structured language: Global variables are allocated statically Local variables are allocated dynamically when the block is entered When a block is entered, memory for variables declared in that block is allocated When a block is exited, this memory is deallocated Programming Languages, Third Edition 57

58 Programming Languages, Third Edition 58

59 Allocation, Lifetimes, and the Environment (cont d.) Programming Languages, Third Edition 59

60 Allocation, Lifetimes, and the Environment (cont d.) Programming Languages, Third Edition 60

61 Allocation, Lifetimes, and the Environment (cont d.) Programming Languages, Third Edition 61

62 Allocation, Lifetimes, and the Environment (cont d.) Programming Languages, Third Edition 62

63 Allocation, Lifetimes, and the Environment (cont d.) Memory for local variables within a function will not be allocated until the function is called Activation: a call to a function Activation record: the corresponding region of allocated memory In a block-structured language with lexical scope, the same name can be associated with different locations, but only one of these can be accessed at any one time Lifetime (or extent) of an object is the duration of its allocation in the environment Programming Languages, Third Edition 63

64 Allocation, Lifetimes, and the Environment (cont d.) Lifetime of an object can extend beyond the region of a program in which it can be accessed Lifetime extends through a scope hole Pointer: an object whose stored value is a reference to another object C allows the initialization of pointers that do not point to an allocated object: Objects must be manually allocated by use of an allocation routine Variable can be dereferenced using the unary * operator Programming Languages, Third Edition 64

65 Allocation, Lifetimes, and the Environment (cont d.) C++ simplifies dynamic allocation with operators new and delete: These are used as unary operators, not functions Heap: area in memory from which locations can be allocated in response to calls to new Dynamic allocation: allocation on the heap Programming Languages, Third Edition 65

66 Programming Languages, Third Edition 66

67 Allocation, Lifetimes, and the Environment (cont d.) Many languages require that heap deallocation be managed automatically Heap allocation/deallocation and explicit pointer manipulation are inherently unsafe operations Can introduce seriously faulty runtime behavior that may even compromise the operating system Storage class: the type of allocation Static (for global variables) Automatic (for local variables) Dynamic (for heap allocation) Programming Languages, Third Edition 67

68 Variables and Constants Although references to variables and constants look the same in many languages, their roles and semantics are very different We will look at the basic semantics of both Programming Languages, Third Edition 68

69 Variables Variable: an object whose stored value can change during execution Is completely specified by its attributes (name, location, value, data type, size of memory storage) Box and circle diagram: focuses on name and location Programming Languages, Third Edition 69

70 Variables (cont d.) Assignment statement: principle way in which a variable changes its value Example: Semantics: expression e is evaluated to a value, then copied into the location of x If e is a variable named y: Programming Languages, Third Edition 70

71 Variables (cont d.) Variable on right side of assignment statement stands for a value (r-value); variable on left side stands for a location (l-value) Address of operator (&) in C: turns a reference into a pointer to fetch the address of a variable Assignment by sharing: the location is copied instead of the value Assignment by cloning: allocates new location, copies value, and binds to the new location Both are sometimes called pointer semantics or reference semantics Programming Languages, Third Edition 71

72 Variables (cont d.) Programming Languages, Third Edition 72

73 Variables (cont d.) Storage semantics or value semantics refer to standard assignment Standard implementation of assignment by sharing uses pointers and implicit dereferencing Programming Languages, Third Edition 73

74 Variables (cont d.) Programming Languages, Third Edition 74

75 Constants Constant: an entity with a fixed value for the duration of its existence in a program Like a variable, but has no location attribute Sometimes say that a constant has value semantics Literal: a representation of characters or digits Compile-time constant: its value can be computed during compilation Static constant: its value can be computed at load time Programming Languages, Third Edition 75

76 Constants (cont d.) Manifest constant: a name for a literal Dynamic constant: its value must be computed during execution Function definitions in virtually all languages are definitions of constants whose values are functions This differs from a function variable in C, which must be defined as a pointer Programming Languages, Third Edition 76

77 a and b are compile-time constants a is a manifest constant c is a static (loadtime constant) d is a dynamic constant Constants (cont d.) Programming Languages, Third Edition 77

78 Aliases, Dangling References, and Garbage There are several problems with naming and dynamic allocation conventions of programming languages, especially C, C++, and Ada As a programmer, you can learn to avoid those problematic situations As a language designer, you can build solutions into your language Programming Languages, Third Edition 78

79 Aliases Alias: occurs when the same object is bound to two different names at the same time Can occur during procedure call, through the use of pointer variables, or through assignment by sharing Programming Languages, Third Edition 79

80 Aliases (cont d.) Programming Languages, Third Edition 80

81 Aliases (cont d.) Programming Languages, Third Edition 81

82 Aliases (cont d.) Programming Languages, Third Edition 82

83 Aliases (cont d.) Aliases can potentially cause harmful side effects Side effect: any change in a variable s value that persists beyond the execution of the statement Not all side effects are harmful; an assignment statement is intended to cause one Side effects that change variables whose names do not directly appear in the statement are potentially harmful Cannot be determined from the written code Aliasing due to pointer assignment is difficult to control Programming Languages, Third Edition 83

84 Aliases (cont d.) Assignment by sharing implicitly uses pointers Java has a mechanism for explicitly cloning an object so that aliases are not created by assignment Programming Languages, Third Edition 84

85 Dangling References Dangling reference: a location that has been deallocated from the environment but can still be accessed by a program Occurs when a pointer points to a deallocated object Programming Languages, Third Edition 85

86 Dangling References (cont d.) Can also result from automatic deallocation of local variables on exit from a block, with the C address of operator Programming Languages, Third Edition 86

87 Dangling References (cont d.) Java does not allow dangling references at all because: There are no explicit pointers There is no address of operator There are no memory deallocation operators such as free or delete Programming Languages, Third Edition 87

88 Garbage Garbage: memory that has been allocated in the environment but is now inaccessible to the program Can occur in C by failing to call free before reassigning a pointer variable A program that is internally correct but produces garbage may run out of memory Programming Languages, Third Edition 88

89 Garbage (cont d.) A program with dangling references may: Produce incorrect results Corrupt other programs in memory Cause runtime errors that are hard to locate For this reason, it is useful to remove the need to deallocate memory explicitly from the programmer Garbage collection: process of automatically reclaiming garbage Language design is a key factor in the kind of runtime environment necessary for correct execution of programs Programming Languages, Third Edition 89

90 Case Study: Initial Static Semantic Analysis of TinyAda Chapter 6 introduced a syntax analyzer for TinyAda A simple parsing shell that pulled tokens from a scanner until a syntax error was detected Here, we extend the parsing shell to perform some semantic analysis Focus will be on tools for scope analysis and for restricting the use of identifiers Must focus on two attributes of an identifier: Name Role it plays (constant, variable, type, or procedure) Programming Languages, Third Edition 90

91 Scope Analysis TinyAda is lexically scoped, with these scope rules: All identifiers must be declared before use At most, one declaration for a given identifier in a single block A new block starts with formal parameter specifications of a procedure and extends to the reserved word end Visibility of a declared identifier extends into nested blocks unless it is redeclared in that block Identifiers are not case sensitive Programming Languages, Third Edition 91

92 Scope Analysis (cont d.) TinyAda has five built-in (predefined) identifiers: Data type names integer, char, boolean Boolean constants true and false These identifiers must be visible in a top-level scope before a source program is parsed Static nesting level of this scope is 0 Scope at nesting level 1 contains the procedure s formal parameters (if any) and any identifiers introduced in the procedures basic declarations Names in nested procedures follow this pattern Programming Languages, Third Edition 92

93 Scope Analysis (cont d.) TinyAda s parser uses a stack of symbol tables When each new scope is entered, a new table is pushed onto the stack When a scope is exited, the table at the top of the stack is popped off the stack Two classes are defined to support scope analysis: SymbolEntry: holds information about an identifier SymbolTable: manages the stack of scopes Programming Languages, Third Edition 93

94 Scope Analysis (cont d.) Programming Languages, Third Edition 94

95 Identifier Role Analysis An identifier names an entity, such as a variable, a constant, or an entire data type This attribute of an identifier is called its role An identifier s role imposes certain restrictions on its use Examples: Only a variable or parameter identifier can appear on the left side of an assignment statement Only a type identifier can appear as the element type of an array Programming Languages, Third Edition 95

96 Identifier Role Analysis (cont d.) Identifier acquires its role in its declaration Role is saved in the symbol table for future use Role analysis uses the symbol table to share contextual information about identifiers among otherwise independent parsing methods Programming Languages, Third Edition 96

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

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

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

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

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, 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

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

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

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

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

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

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

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

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

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline 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

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

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages! Scope Xu Liu ! 4.1 Syntactic Issues! 4.2 Variables! 4.3 Scope! 4.4 Symbol Table! 4.5 Resolving References! 4.6 Dynamic Scoping! 4.7 Visibility! 4.8 Overloading!

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

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

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

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

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

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

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far 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 Statically vs. Dynamically typed languages

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

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

Compiler Theory. (Semantic Analysis and Run-Time Environments) Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

More information

CS 3360 Design and Implementation of Programming Languages. Exam 1

CS 3360 Design and Implementation of Programming Languages. Exam 1 1 Spring 2016 (Monday, March 21) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 18 questions and pages numbered 1 through 6. Reminders This test is closed-notes and

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

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

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e CS-3160 Concepts of Programming Languages Spring 2015 EXAM #1 (Chapters 1-6) Name: SCORES MC: /75 PROB #1: /15 PROB #2: /10 TOTAL: /100 Multiple Choice Responses Each multiple choice question in the separate

More information

Chapter 7. Expressions and Assignment Statements

Chapter 7. Expressions and Assignment Statements Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

More information

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

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis? Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator

More information

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

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

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

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

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

Software II: Principles of Programming Languages. Why Expressions?

Software II: Principles of Programming Languages. Why Expressions? Software II: Principles of Programming Languages Lecture 7 Expressions and Assignment Statements Why Expressions? Expressions are the fundamental means of specifying computations in a programming language

More information

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1 CSE 401 Compilers Static Semantics Hal Perkins Winter 2009 2/3/2009 2002-09 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Symbol tables General ideas for now; details later for MiniJava project

More information

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7. Expressions and Assignment Statements ISBN Chapter 7 Expressions and Assignment Statements ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

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

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

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

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

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

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

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

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

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

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

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

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

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

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

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

HANDLING NONLOCAL REFERENCES

HANDLING NONLOCAL REFERENCES SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.

More information

Chapter 9 Subprograms

Chapter 9 Subprograms Chapter 9 Subprograms We now explore the design of subprograms, including parameter-passing methods, local referencing environment, overloaded subprograms, generic subprograms, and the aliasing and problematic

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

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

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages COMP322 Fall 2012/2013 1-1 Textbook ISBN 0-321-49362-1 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages

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

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

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

The Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis The Compiler So Far Overview of Semantic Analysis Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Lexical analysis Detects inputs with illegal tokens Parsing Detects inputs with ill-formed

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

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

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

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 1 - Introduction Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014

More information

UNIT 3

UNIT 3 UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment

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

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

Chapter 3:: Names, Scopes, and Bindings (cont.) Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Review What is a regular expression? What is a context-free grammar? What is BNF? What is a derivation?

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

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

Chapter 3:: Names, Scopes, and Bindings (cont.) Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Review What is a regular expression? What is a context-free grammar? What is BNF? What is a derivation?

More information

Types II. Hwansoo Han

Types II. Hwansoo Han Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping

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

LECTURE 17. Expressions and Assignment

LECTURE 17. Expressions and Assignment LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)

More information

UNIT-4 (COMPILER DESIGN)

UNIT-4 (COMPILER DESIGN) UNIT-4 (COMPILER DESIGN) An important part of any compiler is the construction and maintenance of a dictionary containing names and their associated values, such type of dictionary is called a symbol table.

More information

Chapter 7 Expressions and Assignment statements

Chapter 7 Expressions and Assignment statements Chapter 7 Expressions and Assignment statements 1 7.1 Introduction Expressions are the fundamental means of specifying computations in a programming language Semantics of expressions are discussed in this

More information

Lexical Considerations

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

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

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

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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

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

IEEE LANGUAGE REFERENCE MANUAL Std P1076a /D3

IEEE LANGUAGE REFERENCE MANUAL Std P1076a /D3 LANGUAGE REFERENCE MANUAL Std P1076a-1999 2000/D3 Clause 10 Scope and visibility The rules defining the scope of declarations and the rules defining which identifiers are visible at various points in the

More information

Informatica 3 Marcello Restelli

Informatica 3 Marcello Restelli Informatica 3 Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Operational Semantics We describe the semantics of a programming language by means of an abstract semantic

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

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

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen COP4020 Programming Languages Names, Scopes, and Bindings Prof. Robert van Engelen Overview Abstractions and names Binding time Object lifetime Object storage management Static allocation Stack allocation

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

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

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

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

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

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

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

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

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions

More information

Weeks 6&7: Procedures and Parameter Passing

Weeks 6&7: Procedures and Parameter Passing CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45

More information

0. Overview of this standard Design entities and configurations... 5

0. Overview of this standard Design entities and configurations... 5 Contents 0. Overview of this standard... 1 0.1 Intent and scope of this standard... 1 0.2 Structure and terminology of this standard... 1 0.2.1 Syntactic description... 2 0.2.2 Semantic description...

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

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

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule Scope CSC 4181 Compiler Construction Scope and Symbol Table A scope is a textual region of the program in which a (name-to-object) binding is active. There are two types of scope: Static scope Dynamic

More information

Name, Scope, and Binding. Outline [1]

Name, Scope, and Binding. Outline [1] Name, Scope, and Binding In Text: Chapter 3 Outline [1] Variable Binding Storage bindings and lifetime Type bindings Type Checking Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur 2

More information

Semantic actions for declarations and expressions. Monday, September 28, 15

Semantic actions for declarations and expressions. Monday, September 28, 15 Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information