General Course Information. Catalogue Description. Objectives

Similar documents
CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

CSE 504: Compiler Design

ECE573 Introduction to Compilers & Translators

Introduction (1) COMP 520: Compiler Design (4 credits) Alexander Krolik MWF 13:30-14:30, MD 279

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

CS 241 Data Organization using C

CS/SE 153 Concepts of Compiler Design

CMPE 152 Compiler Design

CS/SE 153 Concepts of Compiler Design

CMPE 152 Compiler Design

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.

CSCI 565 Compiler Design and Implementation Spring 2014

CMPE 152 Compiler Design

Important Project Dates

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

Compilers. Computer Science 431

Compilers for Modern Architectures Course Syllabus, Spring 2015

ECE Introduction to Compilers and Translation Engineering

Data Structures and Algorithms

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

Course and Contact Information. Course Description. Course Objectives

Information. Introduction. Description. Outcome

Compiler Design (40-414)

Office hours: Tuesday and Thursday 3:30-5:00pm. project description, class notes, grades, etc. Web Data Management and XML L1: Introduction 2

Compilers and Interpreters

CA Compiler Construction

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1, 2, and 3, Spring 2018

15-411/ Compiler Design

Translator Design CRN Course Administration CMSC 4173 Spring 2017

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

Introduction to Compiler Construction

Introduction to Compiler Construction

CSCI 201L Syllabus Principles of Software Development Spring 2018

Course and Contact Information. Course Description. Course Objectives

BOSTON UNIVERSITY Metropolitan College MET CS342 Data Structures with Java Dr. V.Shtern (Fall 2011) Course Syllabus

Introduction. Leonidas Fegaras University of Texas at Arlington. Web Data Management and XML L1: Introduction 1

CPS352 - DATABASE SYSTEMS. Professor: Russell C. Bjork Spring semester, Office: KOSC 242 x4377

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1,2 and 3, Spring 2017

Course and Unix Intro

CS350 : Operating Systems. General Assignment Information

CS350 : Operating Systems. General Assignment Information

Introduction to Programming System Design CSCI 455x (4 Units)

Compilers Crash Course

San José State University Computer Science Department CS49J, Section 3, Programming in Java, Fall 2015

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

CS202 Compiler Construction. Christian Skalka. Course prerequisites. Solid programming skills a must.

CS 241 Data Organization. August 21, 2018

CSE 114, Computer Science 1 Course Information. Spring 2017 Stony Brook University Instructor: Dr. Paul Fodor

Spring 2018 El Camino College E. Ambrosio. Course Syllabus

San José State University Computer Science Department CS157A: Introduction to Database Management Systems Sections 5 and 6, Fall 2015

CSE 582 Autumn 2002 Exam 11/26/02

San José State University College of Science/Department of Computer Science CS152, Programming Paradigms, Sections 1 & 2, Fall Semester, 2017

CST-402(T): Language Processors

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Spring 2015

Object-Oriented Programming for Managers

CS426 Compiler Construction Fall 2006

CS153: Compilers Lecture 1: Introduction

Course introduction. Advanced Compiler Construction Michel Schinz

San José State University College of Science/Department of Computer Science CS152, Programming Paradigms, Sections 3 & 4, Fall Semester, 2016

PLAGIARISM. Administrivia. Compilers. CS143 11:00-12:15TT B03 Gates. Text. Staff. Instructor. TAs. Office hours, contact info on 143 web site

Compiler Construction

CS131: Programming Languages and Compilers. Spring 2017

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

CASPER COLLEGE COURSE SYLLABUS MSFT 1600 Managing Microsoft Exchange Server 2003 Semester/Year: Fall 2007

Translator Design CRN Course Administration CMSC 4173 Spring 2018

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Compiler Construction LECTURE # 1

San José State University Department of Computer Science CS151, Object Oriented Design, Section 04, Fall, 2016 (42968)

Object-Oriented Principles and Practice / C++

Compilers and Code Optimization EDOARDO FUSELLA

Working of the Compilers

Principles of Compiler Construction ( )

Introduction to UNIX

Introduction to Computer Systems

Administrivia. Compilers. CS143 10:30-11:50TT Gates B01. Text. Staff. Instructor. TAs. The Purple Dragon Book. Alex Aiken. Aho, Lam, Sethi & Ullman

AE Computer Programming for Aerospace Engineers

ISM 324: Information Systems Security Spring 2014

Overview of the Class

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

C Programming for Engineers Introduction

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

Who are we? Andre Platzer Out of town the first week GHC TAs Alex Crichton, senior in CS and ECE Ian Gillis, senior in CS

Course Administration

CSCI 6312 Advanced Internet Programming

CIS* Programming

Compiler construction

CSE 401/M501 Compilers

INF 315E Introduction to Databases School of Information Fall 2015

Finding People and Information (1) G53CMP: Lecture 1. Aims and Motivation (1) Finding People and Information (2)

Important Project Dates

COMP 412, Fall 2018 Lab 1: A Front End for ILOC

Syllabus of ENPM 691: Secure Programming in C

San José State University College of Science/Department of Computer Science CS152, Programming Paradigms, Sections 1 & 2 Spring Semester, 2018

Transcription:

General Course Information CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers Instructor: Leonidas Fegaras Office: ERB 653 (Engineering Research Bldg) Phone: (817) 272-3629 Email: fegaras@cse.uta.edu Office hours: Tuesday and Thursday 4:00-5:30pm Course web page: https://lambda.uta.edu/cse5317/ Leonidas Fegaras CSE 5317/4305 L1: Course Organization and Introduction 1 Catalogue Description Review of programming language structures, translation, and storage allocation. Introduction to context-free grammars and their description. Design and construction of compilers including lexical analysis, parsing and code generation techniques. Error analysis and simple code optimizations will be introduced. CSE 5317/4305 L1: Course Organization and Introduction 2 Objectives The goal of this course is to give a working knowledge of the basic techniques used in the implementation of modern programming languages. The course is centered around a substantial programming project: implementing a complete compiler for a realistic language. Students successfully completing this course will be able to apply the theory and methods learned during the course to design and implement optimizing compilers for most programming languages. CSE 5317/4305 L1: Course Organization and Introduction 3 CSE 5317/4305 L1: Course Organization and Introduction 4

Outcome Upon successful completion of this course, students will gain an in-depth understanding of many theoretical and practical aspects of modern compiler technology, including scanning, parsing, type-checking, code generation and optimization, and storage allocation; will have the skills to design and implement practical optimizing compilers for programming languages. Reasons to Take this Course To understand better programming languages (syntax, principles, semantics) by learning how to implement their features computer architecture and machine code structure by learning how to generate assembly code automatically the relation between source programs and generated machine code To apply the knowledge you gained in this and other CS classes to complete a substantial & practical programming project a compiler for a realistic programming language CSE 5317/4305 L1: Course Organization and Introduction 5 Prerequisites Prerequisites: CSE3302 (Programming Languages) CSE3315 (Theoretical Concepts) CSE3322 (Computer Architecture I) Students must: have knowledge and programming experience with Java the code in book & class notes is in Java although you will do most of your programming in Scala be familiar with the functions of modern computer architectures and be able to program in an assembly language we will use MIPS in class notes and project be familiar with data structure concepts and algorithms such as lists, trees, sorting, hashing, etc. Students without adequate preparation are at substantial risk of failing this course. CSE 5317/4305 L1: Course Organization and Introduction 6 Textbook Required Textbook and Notes: Andrew W. Appel: Modern Compiler Implementation in Java, Second Edition. Cambridge University Press, 2002. Lecture Notes will be available at https://lambda.uta.edu/cse5317/ Lecture slides are based on notes You may find the following texts useful for additional background and explanation: A. V. Aho, M. S. Lam., R. Sethi, and J. D. Ullman: Compilers: Principles, Techniques, and Tools, 2 nd edition, (this is the classic red "Dragon" book), Addison-Wesley, 2007. C. Fischer, R Cytron, and R. LeBlanc, Crafting a Compiler. Bejamin/Cummings, 2009. CSE 5317/4305 L1: Course Organization and Introduction 7 CSE 5317/4305 L1: Course Organization and Introduction 8

The final grade will be based on 40% project 25% midterm exam 35% final exam (comprehensive) Grading The course work will be the same for graduates and undergraduates. Final grades will be assigned according to the following scale: A: score >= 90 B: 80 <= score < 90 C: 70 <= score < 80 D: 60 <= score < 70 F: score < 60 Sometimes, I use lower cutoff points, depending on the overall performance of the class. After the first grades are posted, you can check your grades online at the course web page. Reading Assignments Completing reading assignments before the class period in which the material is discussed is essential to success in this class. Not all the assigned material will be covered in class, but you will be responsible for it on exams. CSE 5317/4305 L1: Course Organization and Introduction 9 Exams CSE 5317/4305 L1: Course Organization and Introduction 10 Project Both exams are open textbook (only the class required textbook) and open notes (all notes must be securely bound in one notebook). The final exam will cover the material from the first lecture up to and including the last lecture. Once the exam grades are posted, you will have 10 business days to dispute your grade and get your exam re-evaluated. Before you request for re-evaluation, make sure to compare your answer with the solution. No re-evaluation will be entertained after the 10 day period. No makeup exams will be given unless there is a justifiable reason (such as illness, sickness or death in the family). If you miss an exam and you can prove that your reason is justifiable, you should arrange with the instructor to take the makeup exam within a week from the regular exam time. For any other case, you will get a zero grade for the missed exam. CSE 5317/4305 L1: Course Organization and Introduction 11 The course project is to construct a compiler for a small programming language and will involve: lexical analysis, parsing, semantic analysis (type-checking), and code generation for a MIPS architecture. This project will be done in Scala, which shares some common characteristics with Java. You will use your own PC. The project is to be completed in six stages spaced throughout the term and will be done individually. Submissions must be done electronically using the class web site Late assignments will be marked 20 points off per day (out of 100 max). So, there is no point submitting a project report more than 4 days late! This penalty cannot be waived, unless there was a case of illness or other substantial impediment beyond your control, with proof in documents from the school. CSE 5317/4305 L1: Course Organization and Introduction 12

Cheating Project assignments must be done individually. No copying is permitted. Cheating involves giving assistance to or receiving assistance from other students or from other individuals, copying material from the web, etc. I strictly adhere to the University of Texas at Arlington rules and guidelines for handling violations of academic dishonesty. Please refer to the pamphlet "CHEATING: Definitions and Consequences" for additional Information. If any one is caught for cheating, or indulge in plagiarism or collusion on a programming assignment or on a exam, the punishment will be a zero in the assignment/exam. A second offense will result to an automatic Fail grade (F) for the entire course. You are required to sign and return the statement about academic dishonesty CSE 5317/4305 L1: Course Organization and Introduction 13 Project The project will be done individually. The course project is to construct a compiler for a small programming language, called PCAT. It will involve: lexical analysis parsing semantic analysis (type checking) code generation for a MIPS architecture. The project is to be completed in six stages spaced throughout the term. Special Accommodations If you require an accommodation based on disability, I would like to meet with you in the privacy of my office, during the first week of the semester, to make sure you are appropriately accommodated. CSE 5317/4305 L1: Course Organization and Introduction 14 Survival Tips Start working on programming assignments as soon as they are handed out. Do not wait till the day before the deadline. You will see that assignments take much more time when you work on them under pressure than when you are more relaxed. Design carefully before you code. Writing a well-designed piece of code is always easier than starting with some code that "almost works" and adding patches to make it "really work". CSE 5317/4305 L1: Course Organization and Introduction 15 CSE 5317/4305 L1: Course Organization and Introduction 16

Platform and Tools You will do your project on your own PC (under Linux, Windows, OS X, etc) You must install Java JDK 7 (or 6) and Scala The programming will be done in Scala There are many on-line manuals on Scala (see the project web page) All data structures (abstract syntax trees, intermediate representations, symbol, table, etc) will be given You will also use a MIPS code simulator, called SPIM, to run the assembly code generated by your compiler To install the project on your own Linux/OS X/Windows PC: install JDK 7 and Scala optional: install Scala on Eclipse download the project and compile it Scala The project must be done in Scala Why Scala and not Java? the Scala syntax has some similarities with the Java syntax they both generate Java bytecode they are compatible: Java can call Scala, and vice versa both can be developed on Eclipse/Netbeans easier to construct trees and do pattern-matching in Scala I will give a short tutorial on Scala The project can be done on Eclipse Projects #1 & #2 do not use Scala Project #6 will also use SPIM (a MIPS emulator) CSE 5317/4305 L1: Course Organization and Introduction 17 Program Grading Programs will be graded according to their correctness, style, and readability. Programs should behave as specified in the assignment handouts. Bad data should be handled gracefully; your program should never have run-time errors like dereferencing a null pointer or using an out-of-bounds index. Special cases should be handled correctly. Unnecessarily inefficient algorithms or constructs should be avoided; however, efficiency should never be pursued at the expense of clarity or simplicity. Programs should be well documented, modular, and flexible, i.e. easy to modify. Indentation should reflect program structure. Use meaningful identifiers. CSE 5317/4305 L1: Course Organization and Introduction 18 Program Grading (cont.) Avoid static variables and side effects as much as possible. You should never use side effects during the semantic actions of a parser. The grader should be able to understand the program without undue strain. I will provide some test programs, but these programs will not test your compiler exhaustively. It is your responsibility to test every statement in your program by some piece of test data. Thorough testing is essential to establish the reliability of your code. Don't try to add fancy features until the required work is completely debugged. A correctly working simple program is worth much more (both in this class and in actual practice) than a fancy program with bugs. CSE 5317/4305 L1: Course Organization and Introduction 19 CSE 5317/4305 L1: Course Organization and Introduction 20

Cheating Project assignments must be done individually. No copying is permitted. Cheating involves giving assistance to or receiving assistance from other students or from other individuals, copying material from the web, etc. The punishment for cheating is a zero in the assignment and will be subject to the university's academic dishonesty policy. A second offence will result to a Fail in the course. If you have any questions regarding an assignment, see the instructor or teaching assistant. Deliverables Project phases: Lexical Analysis: worth 10% of your project grade. Parsing: worth 15% of your project grade. Abstract Syntax: worth 15% of your project grade. Type-Checking: worth 20% of your project grade. Code generation: worth 25% of your project grade. Instruction Selection: worth 15% of your project grade. The due time of each project is the midnight of the indicated due day You will hand-in your project source code electronically You may hand-in your source files as many times as you want; only the last one will be taken into account Late projects will be marked 20 points off per day (out of 100 max). So, there is no point submitting a project more than 4 days late! CSE 5317/4305 L1: Course Organization and Introduction 21 Solution CSE 5317/4305 L1: Course Organization and Introduction 22 What is a Compiler? There is a solution jar archive Solution.jar It provides all the classes (obfuscated), so you can compare the output of your program with that of the solution. For each project phase, you can compare the output of your program with that of the solution. You can run the solution PCAT compiler over a test PCAT program, say tests/hanoi.pcat, using the command solution 6 tests/hanoi.pcat inside your project directory. If you mess up a project phase you can still do the next project phases by removing the appropriate source files from your directory. That way, the missing Scalla classes will be copied from the Solution.jar file, rather than compiled from your sources. We will mostly study: high-level source code eg, C++ program compiler easy to understand user-friendly syntax many high-level programming constructs machine-independent variables, procedures, classes,... low-level machine code eg, MIPS code hard to understand specific to hardware registers & unnamed locations CSE 5317/4305 L1: Course Organization and Introduction 23 CSE 5317/4305 L1: Course Organization and Introduction 24

Architecture Many Other Translators Compiler: assembly code machine code machine code source program compiler assembler linker loader libraries data Interpreter: result Source Language Translator Target Language LaTeX Text Formater PostScript SQL database query optimizer Query Evaluation Plan Java javac compiler Java byte code Java cross-compiler C++ code English text Natural Lang Understanding semantics (meaning) Regular Expressions JLex scanner generator a scanner in Java BNF of a language CUP parser generator a parser in Java source program interpreter result data Java uses both a compiler (javac) and an interpreter (java) CSE 5317/4305 L1: Course Organization and Introduction 25 Challenges Many variations: many programming languages (eg, Java, C++, Scala) many programming paradigms (eg, object-oriented, functional, logic) many computer architectures (eg, x86, MIPS, ARM, PowerPC) many operating systems (eg, Linux, OS X, Windows) CSE 5317/4305 L1: Course Organization and Introduction 26 Qualities of a Compiler the compiler itself must be bug-free it must generate correct machine code the generated machine code must run fast the compiler itself must run fast (compilation time must be proportional to program size) the compiler must be portable (ie, modular, supporting separate compilation) it must print good diagnostics and error messages the generated code must work well with existing debuggers CSE 5317/4305 L1: Course Organization and Introduction 27 CSE 5317/4305 L1: Course Organization and Introduction 28

Challenges Building a compiler requires knowledge of programming languages (parameter passing, variable scoping, memory allocation, etc) theory (automata, context-free languages, etc) algorithms and data structures (hash tables, graph algorithms, dynamic programming, etc) computer architecture (assembly programming) software engineering Addressing Portability Suppose you want to write compilers from m source languages to n computer platforms. A naïve solution requires n*m programs: C++ MIPS Java x86 ARM FORTRAN PowerPC but we can do it with n+m programs: C++ FE BE MIPS Java x86 FE IR BE BE ARM FE FORTRAN PowerPC BE IR: Intermediate Representation FE: Front-End CSE 5317/4305 L1: Course Organization and Introduction 29 Phases BE: Back-End CSE 5317/4305 L1: Course Organization and Introduction 30 A typical real-world compiler usually has multiple phases The front-end consists of the following phases: scanning: a scanner groups input characters into tokens parsing: a parser recognizes sequences of tokens according to some grammar and generates Abstract Syntax Trees (ASTs) semantic analysis: performs type checking and translates ASTs into IRs optimization: optimizes IRs The back-end consists of the following phases: instruction selection: maps IRs into assembly code code optimization: optimizes the assembly code using control-flow and data-flow analyses, register allocation, etc code emission: generates machine code from assembly code CSE 5317/4305 L1: Course Organization and Introduction 31