Compiler Construction I
|
|
- Jared Russell
- 6 years ago
- Views:
Transcription
1 TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe / 30
2 Topic: Semantic Analysis 2 / 30
3 Semantic Analysis Chapter 1: Type Checking 3 / 30
4 Goal of Type Checking In most mainstream (imperative / object oriented / functional) programming languages, variables and functions have a fixed type. for example:, void*, struct { x; y; }. Types are useful to manage memory to avoid certain run-time errors In imperative and object-oriented programming languages a declaration has to specify a type. The compiler then checks for a type correct use of the declared entity. 4 / 30
5 Type Expressions Types are given using type-expressions. The set of type expressions T contains: 1 base types:, char, float, void,... 2 type constructors that can be applied to other types example for type constructors in C: records: struct { t 1 a 1 ;... t k a k ; } poer: t * arrays: t [] the size of an array can be specified the variable to be declared is written between t and [n] functions: t (t 1,..., t k ) the variable to be declared is written between t and (t 1,..., t k) in ML function types are written as: t 1... t k t 5 / 30
6 Type Definitions in C A type definition is a synonym for a type expression. In C they are roduced using the typedef keyword. Type definitions are useful as abbreviation: typedef struct { x; y; } po_t; to construct recursive types: Possible declaration in C: struct list { info; struct list* next; } struct list* head; more readable: typedef struct list list_t; struct list { info; list_t* next; } list_t* head; 6 / 30
7 Type Checking Problem: Given: a set of type declarations Γ = {t 1 x 1 ;... t m x m ; } Check: Can an expression e be given the type t? Example: struct list { info; struct list* next; }; f(struct list* l) { return 1; }; struct { struct list* c;}* b; * a[11]; Consider the expression: *a[f(b->c)]+2; 7 / 30
8 Type Checking using the Syntax Tree Check the expression *a[f(b->c)]+2: + 2 [ ] a ( ) f. c Idea: traverse the syntax tree bottom-up for each identifier, we lookup its type in Γ constants such as 2 or 0.5 have a fixed type b the types of the inner nodes of the tree are deduced using typing rules 8 / 30
9 Type Systems Formal consider judgements of the form: Γ e : t // (in the type environment Γ the expression e has type t) Axioms: Regeln: Const: Γ c : t c (t c type of constant c) Var: Γ x : Γ(x) (x Variable) Ref: Γ e : Γ & e : t t Deref: Γ e : t Γ e : t 9 / 30
10 Type Systems for C-like Languages More rules for typing an expression: Array: Array: Struct: App: Op: Cast: Γ e 1 : t Γ e 2 : Γ e 1 [e 2 ] : t Γ e 1 : t [ ] Γ e 2 : Γ e 1 [e 2 ] : t Γ e : struct {t 1 a 1 ;... t m a m ; } Γ e.a i : t i Γ e : t (t 1,..., t m ) Γ e 1 : t 1... Γ e m : t m Γ e(e 1,..., e m ) : t Γ e 1 : Γ e 2 : Γ e 1 + e 2 : Γ e : t 1 t 1 can be converted to t 2 Γ (t 2 ) e : t 2 10 / 30
11 Example: Type Checking Given expression *a[f(b->c)]+2 and Γ = { struct list { info; struct list* next; }; f(struct list* l); struct { struct list* c;}* b; * a[11]; }: + 2 [ ] a ( ) f. c b 11 / 30
12 Example: Type Checking Expression *a[f(b->c)]+2: + 2 [ ] [ ] a ( ) (struct list ) f. struct list struct {struct list c;} struct {struct list c;} b c 12 / 30
13 Equality of Types Summary type checking: Choosing which rule to apply at an AST node is determined by the type of the child nodes determining the rule requires a check for equality of types type equality in C: struct A {} and struct B {} are considered to be different the compiler could re-order the fields of A and B independently (not allowed in C) to extend an record A with more fields, it has to be embedded o another record: typedef struct B { struct A a; field_of_b; } extension_of_a; after issuing typedef C; the types C and are the same 13 / 30
14 Structural Type Equality Alternative erpretation of type equality (does not hold in C): semantically, two type t 1, t 2 can be considered as equal if the accept the same set of access paths. Example: struct list { info; struct list* next; } struct list1 { info; struct { info; struct list1* next; }* next; } Consider declarations struct list* l and struct list1* l. Both allow l->info l->next->info but the two declarations of l have unequal types in C. 14 / 30
15 Algorithm for Testing Structural Equality Idea: track a set of equivalence queries of type expressions if two types are syntactically equal, we stop and report success otherwise, reduce the equivalence query to a several equivalence queries on (hopefully) simpler type expressions Suppose that recursive types were roduces using type equalities of the form: A = t (we omit the Γ). Then define the following rules: 15 / 30
16 Rules for Well-Typedness t t s t A s t s t t A = s struct {s 1 a 1 ;... s m a m ; } struct {t 1 a 1 ;... t m a m ; } s 1 t 1 s m t m 16 / 30
17 Example: A = struct { info; A next; } B = struct { info; struct { info; B next; } next; } We ask, for instance, if the following equality holds: struct { info; A next; } = B We construct the following derivation tree: 17 / 30
18 Proof for the Example: A = struct { info; A next; } B = struct { info; struct { info; B next; } next; } struct{ info; A next; } B struct{ info; A next; } struct{ info;... next; } A... A struct{ info; B next; } struct{ info; A next; } struct{ info; B next; } A B A B struct{ info; A next; } B 18 / 30
19 Implementation We implement a function that implement the equivalence query for two types by applying the deduction rules: if no deduction rule applies, then the two types are not equal if the deduction rule for expanding a type definition applies, the function is called recursively with a potentially larger type during the construction of the proof tree, an equivalence query might occur several times in case an equivalence query appears a second time, the types are by definition equal Termination? the set D of all declared types is finite there are no more than D 2 different equivalence queries repeated queries for the same inputs are are automatically satisfied termination is ensured 19 / 30
20 Overloading and Coercion Some operators such as + are overloaded: + has several possible types for example: +(,), float +(float, float) but also float* +(float*, ), * +(, *) depending on the type, the operator + has a different implementation determining which implementation should be used is based on the arguments only Coercion: allow the application of + to and float. instead of defining + for all possible combinations of types, the arguments are automatically coerced this coercion may generate code (z.b. conversion from to float) coersion is usually done towards more general types i.e has type float (since float ) 20 / 30
21 Coercion of Integer-Types in C: Promotion C defines special conversion rules for egers: promotion unsigned char signed char unsigned short signed short unsigned... where a conversion has to happen via all ermediate types. subtle errors possible! Compute the character distribution of str: char* str = "..."; dist[256]; memset(dist, 0, sizeof(dist)); while (*str) { dist[(unsigned) *str]++; str++; }; Note: unsigned is shorthand for unsigned. 21 / 30
22 Subtypes on the arithmetic basic types char,, long, etc. there exists a rich subtype hierarchy here t 1 t 2, means that the values of type t 1 1 form a subset of the values of type t 2; 2 can be converted o a value of type t 2; 3 fulfill the requirements of type t 2. Example: assign smaller type (fewer values) to larger type t 1 x; t 2 y; y = x; extend the subtype relationship to more complex types 22 / 30
23 Example: Subtyping Observe: string extractinfo( struct { string info; } x) { return x.info; } we would like extractinfo to be applicable to all argument records that contain a field string info use deduction rules to describe when t 1 t 2 should hold the idea of subtyping on values is related to subtyping as implemented in object-oriented languages 23 / 30
24 Rules for Well-Typedness of Subtyping t t s t A t A = s s t s t struct {s j1 a j1 ;... s jm a jm ; } struct {t 1 a 1 ;... t k a k ; } s 1 t 1 s k t k struct { u, v} x; struct { u} y; y = x; 24 / 30
25 Rules and Examples for Subtyping s 0 (s 1,..., s m ) t 0 (t 1,..., t m ) s 0 t 0 t 1 s 1 t m s m Examples: Attention: For functions: struct { a; b; } struct {float a; } () float (float) (float) float () the return types are in normal subtype relationship for argument types, the subtype relation reverses 25 / 30
26 Co- and Contra Variance Definition Given two function types in subtype relation s 0 (s 1,... s n ) t 0 (t 1,... t n ) then we have co-variance of the return type s 0 t 0 and contra-variance of the arguments s i t i für 1 < i n Example from function languages: float float These rules can be applied directly to test for sub-type relationship of recursive types 26 / 30
27 Subtypes: Application of Rules (I) Check if S 1 R 1 : R 1 = struct { a; R 1 (R 1 ) f ; } S 1 = struct { a; b; S 1 (S 1 ) f ; } R 2 = struct { a; R 2 (S 2 ) f ; } S 2 = struct { a; b; S 2 (R 2 ) f ; } a S 1 R 1 f S 1 (S 1 ) R 1 (R 1 ) S 1 R 1 R 1 S 1 27 / 30
28 Subtypes: Application of Rules (II) Check if S 2 S 1 : R 1 = struct { a; R 1 (R 1 ) f ; } S 1 = struct { a; b; S 1 (S 1 ) f ; } R 2 = struct { a; R 2 (S 2 ) f ; } S 2 = struct { a; b; S 2 (R 2 ) f ; } S 2 S 1 a, b f S 2 (R 2 ) S 1 (S 1 ) S 2 S 1 a S 1 R 2 f S 1 (S 1 ) R 2 (S 2 ) S 1 R 2 S 2 S 1 28 / 30
29 Subtypes: Application of Rules (III) Check if S 2 R 1 : R 1 = struct { a; R 1 (R 1 ) f ; } S 1 = struct { a; b; S 1 (S 1 ) f ; } R 2 = struct { a; R 2 (S 2 ) f ; } S 2 = struct { a; b; S 2 (R 2 ) f ; } a S 2 R 1 f S 2 (R 2 ) R 1 (R 1 ) S 2 R 1 a R 1 R 2 f R 1 (R 1 ) R 2 (S 2 ) R 1 R 2 S 2 R 1 29 / 30
30 Discussion for presentational purposes, proof trees are often abbreviated by omitting deductions within the tree structural sub-types are very powerful and can be quite ricate to understand Java generalizes records to objects/classes where a sub-class A inheriting form base class O is a subtype A O subtype relations between classes must be explicitly declared inheritance ensures that all sub-classes contain all (visible) components of the super class a shadowed (overwritten) component in A must have a subtype of the the component in O Java does not allow argument subtyping for methods since it uses different signatures for overloading 30 / 30
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 informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCOMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking
Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review
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 informationIntroduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language
Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2013 1 / 59 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites
More informationIntroduction to C++ with content from
Introduction to C++ with content from www.cplusplus.com 2 Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup
More informationCSE 431S Type Checking. Washington University Spring 2013
CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks
More informationTopics 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 informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 12 C: structs, t linked lists, and casts Where we are We ve seen most of the basic stuff about C, but we still need to look at structs
More informationType Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413
Type Inference Systems CS412/CS413 Introduction to Compilers Tim Teitelbaum Type inference systems define types for all legal programs in a language Type inference systems are to type-checking: As regular
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 informationCMSC 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 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 informationMIT Semantic Analysis. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Semantic Analysis Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Error Issue Have assumed no problems in building IR But are many static checks that need
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 59 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites
More informationOverload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018
Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018 1 Introduction Definition of Function Overloading Determining which Overload to call How Overload Resolution Works Standard Conversion Sequences
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
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 informationOverriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון
Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 104 Topic: Semantic Analysis 2 / 104 Topic: Code Synthesis 3 / 104 Generating
More informationOOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.
OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every
More informationTypes. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus
Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type
More informationThe New C Standard (Excerpted material)
The New C Standard (Excerpted material) An Economic and Cultural Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved. 1378 type specifier type-specifier: void char
More informationStrict Inheritance. Object-Oriented Programming Winter
Strict Inheritance Object-Oriented Programming 236703 Winter 2014-5 1 1 Abstractions Reminder A class is an abstraction over objects A class hierarchy is an abstraction over classes Similar parts of different
More informationCSCE 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 informationProgramming in C++ 6. Floating point data types
Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction
More informationCOMPUTER SCIENCE TRIPOS
CST1.2018.4.1 COMPUTER SCIENCE TRIPOS Part IB Monday 4 June 2018 1.30 to 4.30 COMPUTER SCIENCE Paper 4 Answer five questions: up to four questions from Section A, and at least one question from Section
More informationJava Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.
Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either
More information2.4 Structuring programs
2.4 Structuring programs While theoretically a program could be written as one big expression, in reality we want some structure so that l The programmer has it easier to read the program l A compiler
More informationStrict Inheritance. Object-Oriented Programming Spring 2008
Strict Inheritance Object-Oriented Programming 236703 Spring 2008 1 Varieties of Polymorphism P o l y m o r p h i s m A d h o c U n i v e r s a l C o e r c i o n O v e r l o a d i n g I n c l u s i o n
More informationType Checking and Type Inference
Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled
More informationOverload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019
Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019 1 Introduction Prologue Definition of Function Overloading Determining which Overload to call How Works Standard Conversion Sequences Examples
More informationPierce Ch. 3, 8, 11, 15. Type Systems
Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using
More informationCompiler Passes. Semantic Analysis. Semantic Analysis/Checking. Symbol Tables. An Example
Semantic Analysis Having figured out the program s structure, now figure out what it means Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis token stream Syntactic
More informationSemantic Processing. Semantic Errors. Semantics - Part 1. Semantics - Part 1
Semantic Processing The Lexer and Parser Found lexical and syntax errors Built Abstract Syntax Tree Now!Find semantic errors.!build information about the program. Later!Generate IR Code!Optimize IR Code!Generate
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationCOS 320. Compiling Techniques
Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly
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 informationComputer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres
Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Introduction He am a driver might be syntactically correct but semantically wrong. Semantic
More informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationStatic Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1
Static Semantics Lecture 15 (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Current Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationInheritance & Polymorphism. Object-Oriented Programming Spring 2015
Inheritance & Polymorphism Object-Oriented Programming 236703 Spring 2015 1 1 Abstractions Reminder A class is an abstraction over objects A class hierarchy is an abstraction over classes Similar parts
More informationLecture 12: Data Types (and Some Leftover ML)
Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals
More informationCSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1
CSE P 501 Compilers Static Semantics Hal Perkins Winter 2008 1/22/2008 2002-08 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Attribute grammars Representing types Symbol tables Note: this covers
More informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationCharacter Stream : It provides a convenient means for handling input and output of characters.
Be Perfect, Do Perfect, Live Perfect 1 1. What is the meaning of public static void main(string args[])? public keyword is an access modifier which represents visibility, it means it is visible to all.
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationCompiler construction
Compiler construction Martin Steffen March 13, 2017 Contents 1 Abstract 1 1.1 Types and type checking....................................... 1 1.1.1 Intro...............................................
More informationSome instance messages and methods
Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x
More informationWriting Evaluators MIF08. Laure Gonnord
Writing Evaluators MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Evaluators, what for? Outline 1 Evaluators, what for? 2 Implementation Laure Gonnord (Lyon1/FST) Writing Evaluators 2 / 21 Evaluators,
More informationExam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming
Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose
More informationTail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)
CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)
More informationAnd Even More and More C++ Fundamentals of Computer Science
And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter SoSe 2015 1 / 58 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites Informatik
More informationCompilation 2012 Static Type Checking
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University The Type Checker The type checker has several tasks: determine the types of all expressions check that values and variables are
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationTopics Covered Thus Far CMSC 330: Organization of Programming Languages
Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free
More informationCSCI-GA Scripting Languages
CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation
More informationCSE 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 informationProgramming Assignment 5 Interpreter and Static Analysis
Lund University Computer Science Niklas Fors, Görel Hedin, Christoff Bürger Compilers EDAN65 2016-09-24 Programming Assignment 5 Interpreter and Static Analysis The goal of this assignment is to implement
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 informationStatic Checking and Type Systems
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009 2 The Structure of our Compiler Revisited Character stream Lexical
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationNote 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University
Note 3 Types Yunheung Paek Associate Professor Software Optimizations and Restructuring Lab. Seoul National University Topics Definition of a type Kinds of types Issues on types Type checking Type conversion
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 informationInstantiation of Template class
Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double
More information1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?
1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity
More informationSubtyping. Lecture 13 CS 565 3/27/06
Subtyping Lecture 13 CS 565 3/27/06 Polymorphism Different varieties of polymorphism: Parametric (ML) type variables are abstract, and used to encode the fact that the same term can be used in many different
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 informationMIT Semantic Analysis. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Semantic Analysis Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Error Issue Have assumed no problems in building IR But are many static checks that need
More informationThe Design of Core C++ (Notes)
The Design of Core C++ (Notes) Uday Reddy May 13, 1994 This note is to define a small formal language called Core C++ which reflects the essential structure of C++. As the name implies, the design only
More informationExtending SystemVerilog Data Types to Nets
Extending SystemVerilog Data Types to Nets Revision 3 This document proposes a set of SystemVerilog extensions to allow data types to be used to declare nets. The Overview section provides some rationale
More informationComputers in Engineering. Moving From Fortran to C Michael A. Hawker
Computers in Engineering COMP 208 Moving From Fortran to C Michael A. Hawker Remember our first Fortran program? PROGRAM hello IMPLICIT NONE!This is my first program WRITE (*,*) "Hello, World!" END PROGRAM
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 informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and
More informationInheritance -- Introduction
Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept
More informationConformance. Object-Oriented Programming Spring 2015
Conformance Object-Oriented Programming 236703 Spring 2015 1 What s Conformance? Overriding: replace method body in sub-class Polymorphism: subclass is usable wherever superclass is usable Dynamic Binding:
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 informationMore On Syntax Directed Translation
More On Syntax Directed Translation 1 Types of Attributes We have productions of the form: A X 1 X 2 X 3... X n with semantic rules of the form: b:= f(c 1, c 2, c 3,..., c n ) where b and the c s are attributes
More informationJava: introduction to object-oriented features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationXC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.
XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage
More informationType Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.
Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time
More informationHANDLING 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 informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2013 1 / 108 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites
More informationUser-Defined Algebraic Data Types
72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces
More informationOutline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference
Type Checking Outline General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time
More informationA Short Summary of Javali
A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler
More informationProgramming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee
1 0 1 0 Foundation Topics 1 0 Chapter 1 - Introduction to Programming 1 1 Systems Development Life Cycle N/A N/A N/A N/A N/A N/A 1-8 12-13 1 2 Bloodshed Dev-C++ 5 Compiler/IDE N/A N/A N/A N/A N/A N/A N/A
More informationMid-Term 2 Grades
Mid-Term 2 Grades 100 46 1 HW 9 Homework 9, in untyped class interpreter: Add instanceof Restrict field access to local class Implement overloading (based on argument count) Due date is the same as for
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More information