SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms
|
|
- Dina Phillips
- 5 years ago
- Views:
Transcription
1 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 Database Technology Middleware and Connectivity Tools Web Development Tools Software Tools: Special Topics Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 2
2 Software Tools Source Procedure A Object Module A Programming Source Language Translator Procedure B Tools Systems Object Programming Linker & Module B Loader Tools Executable Binary Code Source Procedure C Object Module C Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 3 Libraries Library header Identification Objects B Calls D,printf Entry point table External Reference table Machine instructions And constants Relocation Dictionary End of module Object A Calls B,C, printf linker Library File header Identification Entry point table External Reference table Machine instructions And constants Relocation Dictionary End of module Stub Library printf Jump Table start on a page boundary.align 8 ; align on 8-byte boundary for variable length insns JUMP_read: jmp _read.align 8 JUMP_write: jmp _write Shared Library printf Stub for printf Entries define the exported & imported global symbols A B C D printf E C X D _read: code for read() _write: code for write() Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 4
3 Principles of Programming Language. Syntax 2. Semantics 3. Data Types 4. Variables Binding Type Checking Referencing Environment (Scoping) 5. Subprogramming A Modeling Tool Abstraction & Control Tool Memory Memory 2 64 Address Data CPU CPU PC Execution Unit Clock Ticks Clock 00 0 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 5 e.g., Pascal type declarations Example: EBNF type_identifier ( identifier ) An example grammar: constant <program> ::= <stmts> <stmts> ::= <stmt> <stmt> ; <stmts> <stmt> ::= <var> = <expr> <var> ::= a b c d <expr> ::= <term> + <term> <term> - <term> <term> ::= <var> const,.. constant a = b + const <program> => <stmts> => <stmt> => <var> = <expr> => a = <expr> => a = <term> + <term> => a = <var> + <term> => a = b + <term> => a = b + const Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 6
4 Phases of Compilation Source Code program: Character Stream Scanner (lexical analysis) Token Stream Parse Tree Abstract syntax tree or other intermediate form Modified intermediate form Assembly or machine language, or other target language Parser (syntax analysis) Semantic analysis and Intermediate code generation Machine-independent code improvement (optional) Target code generation Machine-Specific code improvement (optional) Computation Modified target language Symbol table Machine Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 7 Lexical Analysis & Parsing Lexical Analysis Remove extraneous chars and comments Group input characters into tokens Parsing Organizes tokens into a parse tree Ensures sequence of tokens conforms to the syntax defined by the context-free grammar (CFG) CFG defining the syntax of the language A formal system that describes a language by specifying how any legal text can be derived from a distinguished symbol called the axiom, or sentence symbol. Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 8
5 Example: Parse Tree for: Slope*x + Intercept Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 9 Example Pascal Program program GCD (input, output); var i, j : integer begin read (i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln (i) end Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 0
6 Parse Tree Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa Semantic Analysis Syntax tree The important nodes of the parse tree Annotations (e.g. pointers from id s to symbol table entries) Symbol table maps each identifier (id) to the information known about it Enforces rules not captured by the CFG Generates code for run time checks Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 2
7 Example Pascal Program program GCD (input, output); var i, j : integer begin read (i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln (i) end Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 3 Syntax tree & Symbol table id Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 4
8 Principles of Programming Language. Syntax A Modeling Tool 2. Semantics 3. Data Types 4. Variables Abstraction & Control Tool 2 64 Binding Type Checking Referencing Environment (Scoping) Memory Memory Address CPU CPU PC Clock Ticks Clock 5. Subprogramming Data Execution Unit 00 0 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 5 Data Types 2 64 Specify abstract data types Type is a set of values and operations int struct foo {int bar, baz;} Memory 00 0 Advantages Improve safety and correctness Avoid adding characters to integers Improve programming efficiency Serve as documentation Specify interfaces for separate compilation Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 6
9 Data Type Primitive Types Integer Floating point, Decimal Boolean Character, String type Composite or Structured types Array Sets Record Pointers Integer a word; char a byte Encapsulate data representation to define operations Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 7 Data Types: Issues Implementation Storage Components of the structure Descriptor for the specification of the structure Points to data object Operations Access of components Memory Storage Management deals with binding location and data object e.g., dangling pointers e.g., garbage collection Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 8
10 Data Types: Issues(Cont.) Type Checking during compilation or during execution? Static vs. Dynamic checking Strong and weak typed Relationship with respect to safety Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 9 Array Data Type Design Issues Subscripts: type and range when subscript range bound? Two kinds of array Static S-list: array (..0) of integer; Dynamic when range and storage change get (length) declare D-list : array (.. length) of integer; Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 20
11 Array: Implementation & Storage Management Static Array name domain type lower subscript upper subscript Descriptor Array name domain type Dynamic Data data type size of component Data lower subscript upper subscript data type size of component location Symbol Table Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 2 Dynamic Array Type type name [size] /*index from 0 to size-*/ var a:array [low.. high] of type /*index from low to high */ Random access Calculation is effective when one part is pre-computed the other part is computed at run time loc base + (I low) * w I: index; low: lower bound index w : width or storage of each element on the array base: location of the first element in the array Associative Arrays Associate a defined index with value Great for dictionaries Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 22
12 Dynamic Array Implementation & Storage Management Type Vector = array [.. H] of real Var A:Vector Descriptor Vector 0005 Data Base = 0005 A[I] is (I-LB) *w subrange.. 0 A[3] 0005+(3-) * H real 2 bytes Base Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 23 Character and Strings Specification Fixed length Variable length to a maximum bound Unbound length Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 24
13 Character and Strings Fixed declared length String of 4 chars If shorter than, they are padded with blanks holds the current size variable location Variable with bound declared length holds the current size holds the limit size Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 25 Record Data Type type name = record <name_> : <type_>; typedef struct {int day, month, year;} date;... struct date {int day, month, year;}; <name_n> : <type_n>; end Operations are just on the individual data var p: name; date.day = 5; p.name_ := expression type_; (&date)->year = 997; Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 26
14 Record : Implementation & Storage Management Group related items similar to Cartesian product descriptor stores offset and type for each field Descriptor Record name Data No. of comp Comp. name Comp. type Comp. location Comp. n location Symbol Table Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 27 Variant Records Implementation of union (in C) Use of a tag/discriminant field implemented by overlays Pascal and Modula 2: Ada: tag assignments & tags not mandatory mandatory tags & whole record assignments X: X: record; record; A: A: string; string; B: B: array array ( (..3)..3) of of char; char; C: C: Integer; Integer; case of D:.. 2 is case of D:.. 2 is when when -> -> E: E: integer; integer; F: F: string string ; ; when when 2 2 -> -> G: G: real; real; H: H: integer; integer; end end case; case; end end record; record; need the tag to access the variant record assignments to tag could cause problems runtime check to determine correct field access Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 28
15 Variant Record: Implementation & Storage Management descriminant Descriptor name type Data X: X: record; record; A: A: string; string; B: B: array array ( (..3)..3) of of char; char; C: C: Integer; Integer; case case of of D: D: is is when when -> -> E: E: integer; integer; F: F: string string ; ; when when 2 2 -> -> G: G: real; real; H: H: integer; integer; end end case; case; end end record; record; location value type value 2 Record descriptor Record descriptor type 2 value n type n Record descriptor Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 29 Variant Record: Implementation & Storage Management No. of comp Comp. name Comp. type Comp. location Descriptor X 4 A string X.B integer 3 char X.A length X: X: record; record; A: A: string; string; B: B: array array ( (..3)..3) of of char; char; C: C: Integer; Integer; case case of of D: D: is is when when -> -> E: E: integer; integer; F: F: string string ; ; when when 2 2 -> -> G: G: real; real; H: H: integer; integer; end end case; case; end end record; record; B array X.D E C integer integer 2 integer F G string real record D Variant 2 H integer record runtime check to determine correct field access Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 30
16 Sets Data Type Sets data type is implemented efficiently using bits i.e., operations on sets are performed using bit operations Definition var S :set of [..2] S can be any of the following: [ ], [ ], [2 ], [, 2] Operations on Sets Union as by A+ B ; { x in A or x in B} Intersection as by A * B ; { x in A and x in B} Difference as A-B ; { x in A and x is not in B} Other operation of Super set, Sub set, equal sets, not equal sets Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 3 Sets: Implementation & Storage Management Descriptor name Data Example: type S = Set..4; var X : S; X:= [] Base type Cardinality array location base value base value 2 X Integer 4 array location T F F F 2 base value n n 3 4 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 32
17 Pointers Motivation and Use abstraction of machine addresses dynamic storage allocation recursive data structures Memory Int N; Int *A; Int B[5]; Legal operations A = B; N = A [3]; N = *(A + 3); C family Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 33 Pointers Data Type: Implementation & Storage Management Pointer Type <type referenced> * <pointer name> linktype* node Legal operations p, &p, *p Memory p = 3 3 q = &p q p r = *q 3 r *p = 25 the location content of p (3) stores C family Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 34
18 Pointers Data Type Implementation & Storage Management Dynamic allocation: Problems as memory leaks from pointer assignments. p qq memory loss unable reference p := q dispose (p) leaves q dangling Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 35 Pointers: Problems & Overheads Un-initialized pointers Dangling references Pointer arithmetic Aliasing Garbage collection solves pointer problems Pointers access Only heap in Pascal, Ada, Java Any variable in C, C++, PL/I Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 36
19 References Reference is a safe pointer reference to an object no pointer arithmetic no unsafe casts usually no dangling references Memory Typical example for pointers is C Typical example for references is Java Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 37 References C++ Reference Types Constant pointers that are implicitly de-referenced Used for parameters Java Safety and readability Only references No pointer arithmetic Can only point at objects (which are all on the heap) No explicit de-allocator (garbage collection is used) means there can be no dangling references De-referencing is always implicit Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 38
20 Type Declaration How is a type specified? Explicit declaration Var v: integer; a program statement used for declaring the types of variables Implicit declaration a default mechanism for specifying types of variables the first appearance of the variable in the program FORTRAN, PL/I, and Perl provide implicit declarations Advantage: writability Disadvantage: reliability Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 39 Type Checking Type checking ensuring that the operands of an operator are of compatible types A compatible type A one that is either A type error legal for the operator, or allowed under language rules to be implicitly converted, by compiler generated code, to a legal type. This automatic conversion is called a coercion the application of an operator to an operand of an inappropriate type A strongly typed language: if type errors are always detected Advantage allows the detection of the misuses of variables that result in type errors Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 40
21 Strong Typed Languages: Pascal is not: variant records C and C++ are not: parameter type checking can be avoided; unions are not type checked Ada and Java: almost Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 4 Type Checking Static checking is done at compile time. Dynamic checking is done at runtime Advantage: Flexibility Disadvantage: Cost (late error detection) and inefficiency Static checking is preferable. A strongly typed language needs dynamic checking Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 42
22 Principles of Programming Language. Syntax A Modeling Tool 2. Semantics 3. Data Types 4. Variables Abstraction & Control Tool 2 64 Binding Type Checking Referencing Environment (Scoping) Memory Memory Address CPU CPU PC Clock Ticks Clock 5. Subprogramming Data Execution Unit 00 0 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 43 Variable A variable is an abstraction of a memory cell the physical cell or collection of cells associated with a variable 2 64 Attributes of variable Name Address Value Type Lifetime Scope Memory 00 0 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 44
23 Variable Names Maximum length FORTRAN I: maximum 6 COBOL: maximum 30 FORTRAN 90 and ANSI C: maximum 3 C++: no limit, but implementers often impose one Are names case sensitive? C, C++, Java, and Modula-2 names are case sensitive Disadvantage: Readability Are special words reserved words or keywords? Are connector characters allowed? Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 45 Names: Alias Two names x and y are aliased if they refer to the same object (memory location) How aliases can be created? Pointers, reference variables, Pascal variant records, C and C++ unions Some of the original justifications for aliases are no longer valid; e.g. memory reuse in FORTRAN replace them with dynamic allocation Access Access 2 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 46
24 2 64 Address, Value and Type Memory Address the address of the memory at which the variable is associated Value the contents of the location with which the variable is associated Type determines the range of values of variables and the set of operations that are defined for values of that type; in the case of floating point, type also determines the precision 00 0 Var v: integer Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 47 Variable Lifetime The time during which the variable is bound to a particular memory cell Two issues Allocation getting a cell from some pool of available cells De-allocation putting a cell back into the pool When does the binding take place? Static vs. Dynamic Binding time is the time at which a binding takes place Compile time Load time e.g., bind a variable to a type in C or Java e.g., bind a FORTRAN 77 variable to a memory cell (or a C static variable) Runtime e.g., bind a non-static local variable to a memory cell Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 48
25 Storage Bindings The lifetime of a variable Categories Static: Objects with absolute address throughout the program s execution Stack: Subprograms calls and returns Heap: Allocation and de allocation at arbitrary times Explicit heap-dynamic Implicit heap-dynamic Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 49 Static bound to memory cells before execution begins remains bound to the same memory cell throughout execution e.g. all FORTRAN 77 variables, C static variables Advantage Efficiency, based on direct addressing history-sensitive, subprogram support Disadvantage lack of flexibility, no support for recursion Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 50
26 Stack-dynamic Storage bindings are created for variables when their declaration statements are elaborated variables are bound to storages when execution reaches the code to which the declaration is attached. But, data types are statically bound. i.e., stack-dynamic variables are allocated from the run-time stack e.g. local variables in Pascal and C subprograms Advantage Allows recursion Conserves storage Disadvantages Overhead of allocation and de-allocation Subprograms cannot be history sensitive Inefficient references, based on indirect addressing Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 5 Stack Allocation or Stack Dynamic Sub C Temporaries SP Local Variables Sub B Sub A SP Sub B Sub C Miscellaneous Bookkeeping Return Address Temporaries Local Arguments Variables & Returns Miscellaneous Bookkeeping Return Address Arguments & Returns FP (when Sub C is running) FP (when Sub C is running) Main Program Direction of stack Growth (usually lower addresses) Sub A (Called from main program) Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 52
27 Implicit Heap-dynamic Allocation and de-allocation caused by assignment statements variables are bound to heap storage only when they are assigned values e.g., all variables in APL, flex arrays in Algol 68 LIST <- 7.3 Advantage flexibility Disadvantages High cost (dynamic type checking and interpretation) Type error detection by the compiler is difficult Expensive storage management algorithms for the fragmentation Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 53 Explicit Heap-dynamic Allocated and de-allocated by explicit directives, specified by the programmer, which take effect during execution Referenced only through pointers or references Advantage: e.g., dynamic objects in C++ (via new and delete) e.g., all objects in Java int * intnode;... intnode = new int;... delete intnode; Provides for dynamic storage management Disadvantage Inefficient // allocates an int cell // deallocates the cell to which intnode points Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 54
28 Scope The scope rules of a language determine how references to names are associated with variables The scope of a variable the range of statements over which it is visible The non-local variables of a program unit variables that are visible but not declared there Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 55 Referencing Environment (Scoping) The referencing environment of a statement is the collection of all names that are visible in the statement In a static scoped language local variables and all visible variables in all of the enclosing scopes In a dynamic scoped language local variables and all visible variables in all active subprograms A subprogram is active if its execution has begun but has not yet terminated Scope and lifetime sometimes closely related, but are different concepts! Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 56
29 Static Scope Based on program text To connect a name reference to a variable, programmer (or the compiler) must find the declaration Search process search declarations, first locally, then in increasingly larger enclosing scopes, until one is found for the given name Enclosing static scopes (to a specific scope) are called its static ancestors; the nearest static ancestor is called a static parent Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 57 Dynamic Scope Based on calling sequences of program units, not their textual layout temporal versus spatial References to variables are connected to declaration by searching back through the chain of subprogram calls that forced execution to this point Advantage: convenience Disadvantage: poor readability A B C C D D B E E A Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 58
30 Static vs. Dynamic Scope Example: MAIN - declaration of x SUB - declaration of x... call SUB2... SUB reference to x... MAIN calls SUB SUB calls SUB2 SUB2 uses x Static scoping reference to x is to MAIN's x Dynamic scoping reference to x is to SUB's x... call SUB... Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 59 Constant Name A named constant a variable that is bound to a value only when it is bound to storage Advantages: readability and modifiability The binding of values to named constants can be either static (called manifest constants) or dynamic Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 60
31 Variable Initialization Initialization the binding of a variable to a value at the time it is bound to storage it is often done on the declaration statement e.g., SUM : FLOAT := 0.0; Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 6 Principles of Programming Language. Syntax A Modeling Tool 2. Semantics 3. Data Types 4. Variables Abstraction & Control Tool 2 64 Binding Type Checking Referencing Environment (Scoping) Memory Memory Address CPU CPU PC Clock Ticks Clock 5. Subprogramming Data Execution Unit 00 0 Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa 62
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 informationChapter 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 informationChapter 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 informationProgramming 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 informationImperative 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 informationType 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 informationAnswer: 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 informationNOTE: Answer ANY FOUR of the following 6 sections:
A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)
More informationCPSC 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 information9/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 informationProf. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan
Language Processing Systems Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Semantic Analysis Compiler Architecture Front End Back End Source language Scanner (lexical analysis)
More informationData 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 informationChapter 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 informationSemantic Analysis. Compiler Architecture
Processing Systems Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Source Compiler Architecture Front End Scanner (lexical tokens Parser (syntax Parse tree Semantic Analysis
More informationProgramming 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 informationData 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 informationQuestion No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given
MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com MEGA File Solved MCQ s For Final TERM EXAMS CS508- Modern Programming Languages Question No: 1 ( Marks: 1 ) -
More informationName, 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 informationCSC 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 informationTopic 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 informationTopic 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 informationData 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 informationBinding 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 informationNames, 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 informationG 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 informationG 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 informationFundamentals of Programming Languages
Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION
More informationLecture 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 informationCS 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 informationIntroduction 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 information6. 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 informationSEMANTIC 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 informationCSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:
Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd
More informationCOP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher
COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler
More informationCompilers. 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 informationThe 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 informationConcepts 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 informationOrganization 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 informationCOP4020 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 informationShort 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 information11. 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 informationChapter 8 :: Composite Types
Chapter 8 :: Composite Types Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter08_Composite_Types_4e - Tue November 21, 2017 Records (Structures) and Variants
More informationChapter 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 informationAttributes, 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 informationCS201 - 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 informationCOSC252: Programming Languages: Basic Semantics: Data Types. Jeremy Bolton, PhD Asst Teaching Professor
COSC252: Programming Languages: Basic Semantics: Data Types Jeremy Bolton, PhD Asst Teaching Professor Copyright 2015 Pearson. All rights reserved. Common Types and Design Concerns Primitive Data Types
More informationCST-402(T): Language Processors
CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars
More informationThe 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 informationTypes. 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 informationCS 430 Spring Mike Lam, Professor. Data Types and Type Checking
CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system
More informationCompiling and Interpreting Programming. Overview of Compilers and Interpreters
Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Overview of Compilers and Interpreters Common compiler and interpreter configurations Virtual machines Integrated programming environments
More informationInformatica 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 informationCS558 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 informationCS 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 informationProgramming 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 informationSemantic 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 informationPrinciples of Programming Languages. Lecture Outline
Principles of Programming Languages CS 492 Lecture 1 Based on Notes by William Albritton 1 Lecture Outline Reasons for studying concepts of programming languages Programming domains Language evaluation
More informationAnatomy 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 informationG 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 informationProgramming 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 informationR13 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 informationProgrammiersprachen (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 informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationLecture 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 informationOrganization of Programming Languages CS3200 / 5200N. Lecture 06
Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects
More informationCS558 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 informationData Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011
Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:
More informationThe 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 informationTypes 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 informationSemantic 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 informationChapter 6. Data Types ISBN
Chapter 6 Data Types ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer
More informationExample. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :
Runtime Environment Relationship between names and data objects (of target machine) Allocation & de-allocation is managed by run time support package Each execution of a procedure is an activation of the
More informationCS 230 Programming Languages
CS 230 Programming Languages 11 / 20 / 2015 Instructor: Michael Eckmann Questions/comments? Chapter 6 Arrays Pointers Today s Topics We all know what arrays are. Design issues Legal types for subscripts
More informationData Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction
Introduction Primitive Composite Structured Abstract Introduction Introduction Data Type is a Collection of Data Objects Possible r-values for a memory cell Set of operations on those objects Descriptor
More informationNames and Abstractions: What s in a Name?
Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Names, Scopes, and Bindings Binding time Object lifetime Object storage management Static allocation Stack allocation Heap allocation
More informationSemantic 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 informationCS558 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 informationInformatica 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 informationCMSC 331 Final Exam Section 0201 December 18, 2000
CMSC 331 Final Exam Section 0201 December 18, 2000 Name: Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for
More informationCS 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 informationSt. 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 informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationNames, 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 informationCOS 140: Foundations of Computer Science
COS 140: Foundations of Computer Science Variables and Primitive Data Types Fall 2017 Introduction 3 What is a variable?......................................................... 3 Variable attributes..........................................................
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationLECTURE 18. Control Flow
LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a
More informationC Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:
C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should
More informationMemory Management and Run-Time Systems
TDDD55 Compilers and Interpreters TDDB44 Compiler Construction Memory Management and Run-Time Systems Part of the Attribute Grammar Material Presented at the Beginning of this Lecture Peter Fritzson IDA,
More informationPrinciples 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 informationStatic 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 informationChapter 3:: Names, Scopes, and Bindings
Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation
More informationNames, 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 informationThe 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 informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 18! Bootstrapping Names in programming languages Binding
More information22c:111 Programming Language Concepts. Fall Types I
22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified
More informationOutline. 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 informationLecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]
1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,
More informationNames, 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 informationUNIT-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 informationSubprograms. 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