A New CC Course – Based on Cooperation with Linz Vladimir Kurbalija, Mirjana Ivanović Department of Mathematics and Informatics University of Novi Sad.

Slides:



Advertisements
Similar presentations
CH4.1 Type Checking Md. Fahim Computer Engineering Department Jamia Millia Islamia (A Central University) New Delhi –
Advertisements

Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
CSI 3125, Preliminaries, page 1 Programming languages and the process of programming –Programming means more than coding. –Why study programming languages?
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
Compiler Construction
Organization of the New Course on Complier Construction in Novi Sad Vladimir Kurbalija, Mirjana Ivanović Department of Mathematics and Informatics University.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Overview of Compiler Design CIS 631, CSE 691, CIS400, CSE 400 Compiler Design Dr. Nancy McCracken January 15, 2008.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CIS Computer Programming Logic
Compiler1 Chapter V: Compiler Overview: r To study the design and operation of compiler for high-level programming languages. r Contents m Basic compiler.
COP4020 Programming Languages
CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
OPERATING SYSTEMS AND LANGUAGE TRANSLATORS CIS 2380 TERM 2 – LANGUAGE TRANSLATORS Lee McCluskey – 23/09/20151.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 1 - Introduction
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
Chapter 1 Introduction Major Data Structures in Compiler
Programming Languages
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
CS 153: Concepts of Compiler Design September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 5.Symbol Table 5.1Overview 5.2Symbols 5.3Scopes 5.4Types 5.5Universe.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 9 Symbol Table and Attributed Grammars
Advanced Computer Systems
CS 153: Concepts of Compiler Design September 14 Class Meeting
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Compiler Design (40-414) Main Text Book:
Introduction to Compiler Construction
5. Symbol Table 5.1 Overview 5.2 Symbols 5.3 Scopes 5.4 Types
Constructing Precedence Table
PROGRAMMING LANGUAGES
Compiling, Assembling and Executing Java using Java
CSE 3302 Programming Languages
CSE401 Introduction to Compiler Construction
CS 432: Compiler Construction Lecture 11
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

A New CC Course – Based on Cooperation with Linz Vladimir Kurbalija, Mirjana Ivanović Department of Mathematics and Informatics University of Novi Sad Serbia and Montenegro

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz Agenda Current CC Course in Novi Sad Current CC Course in Novi Sad Lectures Lectures Exercises Exercises CC Course in Linz CC Course in Linz Lectures Lectures Exercises Exercises Conclusion Conclusion

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Novi Sad One of core software courses at Computer Science directions One of core software courses at Computer Science directions 7th semester CC1 (obligatory), 8th semester CC2 (elective), for students of 7th semester CC1 (obligatory), 8th semester CC2 (elective), for students of Computer Science, Computer Science, Business Computer Science, Business Computer Science, Teaching of Computer Science Teaching of Computer Science

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Novi Sad - Lectures Practical approach Practical approach Development of Pascal- compiler Development of Pascal- compiler Subset of Pascal language: Subset of Pascal language: data types: Boolean and integer standard types, arrays and fixed records as structured types; data types: Boolean and integer standard types, arrays and fixed records as structured types; basic statements: assignment statement, procedure call, if and while statements; basic statements: assignment statement, procedure call, if and while statements; Standard input/output (read and write) procedures, user defined procedures including recursion. Standard input/output (read and write) procedures, user defined procedures including recursion.

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Novi Sad - Lectures The implementation: The implementation: recursive-descent manner for syntax analysis recursive-descent manner for syntax analysis code generation for abstract P machine code generation for abstract P machine This approach was interesting 10 years ago This approach was interesting 10 years ago Now, when new languages and tools are appeared we need modernisation!!! Now, when new languages and tools are appeared we need modernisation!!!

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Novi Sad - Exercises Students repeat and train practical skils gained during lectures Students repeat and train practical skils gained during lectures Several independent tasks – small grammars Several independent tasks – small grammars Implementation language is Modula-2 Implementation language is Modula-2 Compiler generator Coco/R Compiler generator Coco/R

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Novi Sad - Exercises Tasks: Tasks: Lexical and syntax analysis and some parts of semantic analysis using Coco/R Lexical and syntax analysis and some parts of semantic analysis using Coco/R “Hand written” parsers (LA & SA) “Hand written” parsers (LA & SA) “Hand written” parsers with semantic analysis and rarely with code generation or interpretation “Hand written” parsers with semantic analysis and rarely with code generation or interpretation Some algorithms on grammars (memory organisation, checking consistency, computing first and follow sets…) Some algorithms on grammars (memory organisation, checking consistency, computing first and follow sets…)

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz Agenda Current CC Course in Novi Sad Current CC Course in Novi Sad Lectures Lectures Exercises Exercises CC Course in Linz CC Course in Linz Lectures Lectures Exercises Exercises Conclusion Conclusion

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Linz - Lectures One semester course held in English One semester course held in English The same course – at University of Oxford The same course – at University of Oxford Goals of the course Goals of the course acquire the practical skills to write a simple compiler for an imperative programming language acquire the practical skills to write a simple compiler for an imperative programming language understand the concepts of scanning, parsing, name management in nested scopes, and code generation. understand the concepts of scanning, parsing, name management in nested scopes, and code generation. learn to transfer the skills also to general software engineering tasks learn to transfer the skills also to general software engineering tasks

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Linz - Lectures More theoretical approach More theoretical approach Course goes through all phases of a compiler writing Course goes through all phases of a compiler writing Shows the theoretical concepts underlying each phase as well as how to implement it efficiently Shows the theoretical concepts underlying each phase as well as how to implement it efficiently Examples: MicroJava compiler in Java, target language – subset of Java byte code Examples: MicroJava compiler in Java, target language – subset of Java byte code Example (05.SymbolTable.ppt, sl ) Example (05.SymbolTable.ppt, sl )

5.Symbol Table 5.1Overview 5.2Objects 5.3Scopes 5.4Types 5.5Universe

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Types Every object has a type with the following properties size (in MicroJava always 4 bytes) structure (fields for classes, element type for arrays,...) Kinds of types in MicroJava? primitive types ( int, char ) arrays classes Types are represented by structure nodes class Struct { static final int// type kinds None = 0, Int = 1, Char = 2, Arr = 3, Class = 4; int kind;// None, Int, Char, Arr, Class StructelemType;// Arr: element type intnFields;// Class: number of fields Objfields;// Class: list of fields }

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Structure Nodes for Primitive Types int a, b; char c; kind name type next val adr level nPars locals Var "a" Var "b" Var "c" kind elemType nFields fields Int - Char - object node structure node There is just one structure node for int in the whole symbol table. It is referenced by all objects of type int. The same is true for structure nodes of type char.

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Structure Nodes for Arrays int[] a; int b; kind name type next val adr level nPars locals Var "a" Var "b" kind elemType nFields fields Arr - The length of an array is statically unknown. It is stored in the array at run time. Int -

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Structure Nodes for Classes class C { int x; int y; int z; } C v; kind name type next val adr level nPars locals Type "C" - Var "v" kind elemType nFields fields Class - 3 Int - kind name type next val adr level nPars locals Var "x" Var "y" Var "z" - 2 -

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Type Compatibility: Name Equivalence Two types are the same if they are represented by the same type node (i.e. if they are denoted by the same type name) class T {...} T a; T b; Type "T"... Var "a"... Var "b"... Class -... The types of a and b are the same Name equivalence is used in Java, C/C++/C#, Pascal,..., MicroJava Exception In Java (and MicroJava) two array types are the same if they have the same element types!

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Type Compatibility: Structural Equivalence Two types are the same if they have the same structure (i.e. the same fields of the same types, the same element type,...) class T1 { int a, b; } class T2 { int c, d; } T1 x; T2 y; Type "T1"... Var "x"... Class - 2 The types of x and y are the same (but not in MicroJava!) Structural equivalence is used in Modula-3 but not in MicroJava and in most other languages! Var "a"... Var "b"... Type "T2"... Var "y"... Class - 2 Var "c"... Var "d"... Int -

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Methods for Checking Type Compatibility class Struct {... // checks if two types are compatible (e.g. in compare operations) public boolean compatibleWith (Struct other) { return (this.equals(other) ||this == Tab.nullType && other.isRefType() ||other == Tab.nullType && this.isRefType()); } // checks if "this" is assignable to "other" public boolean assignableTo (Struct other) { return (this.equals(other) ||this == Tab.nullType && other.isRefType()); } // checks if two types are the same (structural equivalence for arrays, name equivalence otherwise) public boolean equals (Struct other) { if (kind == Arr) return (other.kind == Arr && (other.elemType == elemType || other.elemType == Tab.noType)); else return (other == this); } public boolean isRefType() { return kind == Class || kind = Arr; } necessary because of standard function len(arr)

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Solving LL(1) Conflicts with the Symbol Table Method syntax in MicroJava void foo() int a; { a = 0;... } Actually we would like to write it like this void foo() { int a; a = 0;... } But this would result in an LL(1) conflict Block ="{" { VarDecl | Statement } "}". VarDecl =Type ident {"," ident}. Type =ident ["[" "]"]. Statement=Designator "=" Expr ";" |.... Designator=ident {"." ident | "[" Expr "]"}. First(VarDecl)  First(Statement) = {ident}

V. Kurbalija, M. IvanovićA New CC Course - Based on Cooperation with Linz Solving the Conflict With Semantic Information private static void Block() { check(lbrace); for (;;) { if (NextTokenIsType()) VarDecl(); else if (sym  First(Statement)) Statement(); else if (sym  {rbrace, eof}) break; else { error("...");... recover... } check(rbrace); } private static boolean NextTokenIsType() { if (sym != ident) return false; Obj obj = Tab.find(la.str); return obj.kind == Obj.Type; } Block = "{" { VarDecl | Statement } "}".

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Linz – Exercises Students should acquire practical skills in compiler writing Students should acquire practical skills in compiler writing One (big) project divided in smaller subtasks One (big) project divided in smaller subtasks Students should write a small compiler for a Java-like language - MicroJava Students should write a small compiler for a Java-like language - MicroJava The implementation language is also Java The implementation language is also Java

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Linz – Exercises The project consists of three levels: The project consists of three levels: Level 1 – implementation of a scanner and a parser for the language MicroJava, error handling Level 1 – implementation of a scanner and a parser for the language MicroJava, error handling Level 2 - deals with symbol table handling and type checking Level 2 - deals with symbol table handling and type checking Level 3 - deals with code generation for the MicroJava Level 3 - deals with code generation for the MicroJava

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Linz – Exercises Study material: Study material: Teaching material (slides) Teaching material (slides) Description of the project Description of the project Specification of MicroJava language (tokens, language grammar, semantic and context constraints) Specification of MicroJava language (tokens, language grammar, semantic and context constraints) Specification of MicroJava virtual machine (similar but simpler than Java VM) – Memory layout and Instruction set Specification of MicroJava virtual machine (similar but simpler than Java VM) – Memory layout and Instruction set Specification of object file format Specification of object file format

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz CC Course in Linz – Exercises Sources Sources Frameworks of all classes needed for compiler Frameworks of all classes needed for compiler Complete implementation of MicroJava VM Complete implementation of MicroJava VM Samples of MicroJava programs (for testing) Samples of MicroJava programs (for testing) program P { void main() int i; { i = 0; while (i < 5) { print(i); i = i + 1; }

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz program Eratos char[] sieve; int max;// maximum prime to be found int npp;// numbers per page { void put(int x) { if (npp == 10) {print(chr(13)); print(chr(10)); npp = 0;} if (npp == 10) {print(chr(13)); print(chr(10)); npp = 0;} print(x, 5); print(x, 5); npp++; npp++;} void found(int x) int i; int i;{ put(x); put(x); i = x; i = x; while (i <= max) {sieve[i] = 'o'; i = i + x;} while (i <= max) {sieve[i] = 'o'; i = i + x;}} void main() int i; int i;{ read(max); read(max); npp = 0; npp = 0; sieve = new char[max+1]; sieve = new char[max+1]; i = 0; i = 0; while (i <= max) {sieve[i] = 'x'; i++;} while (i <= max) {sieve[i] = 'x'; i++;} i = 2; i = 2; while (i <= max) { while (i <= max) {found(i); while(i <= max && sieve[i] == 'o') i++; }}}//test

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz Agenda Current CC Course in Novi Sad Current CC Course in Novi Sad Lectures Lectures Exercises Exercises CC Course in Linz CC Course in Linz Lectures Lectures Exercises Exercises Conclusion Conclusion

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz Conclusion Contents of both courses is similar Contents of both courses is similar Approach is slightly different. In new course: Approach is slightly different. In new course: Lectures are purely theoretical Lectures are purely theoretical Exercises are more practical Exercises are more practical A newer programming language (Java) is used instead of Modula-2 A newer programming language (Java) is used instead of Modula-2 A target language (for code generation) is a subset of Java byte code instead of P-code A target language (for code generation) is a subset of Java byte code instead of P-code

V. Kurbalija, M. Ivanović A New CC Course - Based on Cooperation with Linz Conclusion Advantages of new course: Advantages of new course: Concepts of compiler construction are shown on more formal way Concepts of compiler construction are shown on more formal way Modern and object-oriented language is used (Java and Java byte code) Modern and object-oriented language is used (Java and Java byte code) Students autonomously write (almost) whole compiler Students autonomously write (almost) whole compiler Disadvantages of new course Disadvantages of new course Defining several language extensions for each student – students like to corporate during task solution  Defining several language extensions for each student – students like to corporate during task solution 

Thank you for your attention