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

Similar documents
CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Compilers. Computer Science 431

Programming Languages and Compilers (CS 421)

Programming Languages & Compilers. Programming Languages and Compilers (CS 421) I. Major Phases of a Compiler. Programming Languages & Compilers

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

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 2: Lexical Analysis 23 Jan 08

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Programming Languages & Compilers. Programming Languages and Compilers (CS 421) Programming Languages & Compilers. Major Phases of a Compiler

Compilers and Interpreters

ECE251 Midterm practice questions, Fall 2010

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

LECTURE 3. Compiler Phases

A simple syntax-directed

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

Overview of the Class

Outline CS4120/4121. Compilation in a Nutshell 1. Administration. Introduction to Compilers Andrew Myers. HW1 out later today due next Monday.

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

CS453 Compiler Construction

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Introduction to Compiler Construction

Introduction to Lexing and Parsing

CS164: Midterm I. Fall 2003

CPS 506 Comparative Programming Languages. Syntax Specification

CSCI312 Principles of Programming Languages!

Programming Languages and Compilers (CS 421)

n (0 1)*1 n a*b(a*) n ((01) (10))* n You tell me n Regular expressions (equivalently, regular 10/20/ /20/16 4

General Course Information. Catalogue Description. Objectives

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming

Introduction to Compiler Design

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Semantic Analysis. Lecture 9. February 7, 2018

CS/SE 153 Concepts of Compiler Design

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

CS 415 Midterm Exam Spring 2002

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Introduction to Compiler Construction

Compilers CS S-01 Compiler Basics & Lexical Analysis

Group A Assignment 3(2)

Automated Tools. The Compilation Task. Automated? Automated? Easier ways to create parsers. The final stages of compilation are language dependant

HOLY ANGEL UNIVERSITY COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY COMPILER THEORY COURSE SYLLABUS

Lexical Analysis. Lecture 2-4

Compilers. Lecture 2 Overview. (original slides by Sam

CMPE 152 Compiler Design

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

Lexical Analysis. Lecture 3-4

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

Compiling Regular Expressions COMP360

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

Compiler Design (40-414)

Principles of Compiler Construction ( )

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CMPE 152 Compiler Design

CSE 3302 Programming Languages Lecture 2: Syntax

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

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

ECE573 Introduction to Compilers & Translators

A lexical analyzer generator for Standard ML. Version 1.6.0, October 1994

Grammars and Parsing, second week

CS S-01 Compiler Basics & Lexical Analysis 1

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

CMSC 350: COMPILER DESIGN

Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

15-411/ Compiler Design

Structure of Programming Languages Lecture 3

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

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

CS 4201 Compilers 2014/2015 Handout: Lab 1

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Lexical Analysis. Chapter 2

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

A Simple Syntax-Directed Translator

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

CSCI 3155: Lab Assignment 6

Parsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics

Principles of Compiler Construction ( )

CMPE 152 Compiler Design

CS/SE 153 Concepts of Compiler Design

CSCI 3155: Lab Assignment 6

The Structure of a Syntax-Directed Compiler

Compilers CS S-01 Compiler Basics & Lexical Analysis

CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

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

Compiler Construction LECTURE # 3

CST-402(T): Language Processors

CSE 401 Midterm Exam Sample Solution 2/11/15

CSCI 565 Compiler Design and Implementation Spring 2014

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

UNIVERSITY OF CALIFORNIA

Languages and Automata

Lexical Scanning COMP360

CSC 467 Lecture 3: Regular Expressions

Introduction to Lexical Analysis

Compilers for Modern Architectures Course Syllabus, Spring 2015

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

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

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

Transcription:

CS202 Compiler Construction Christian Skalka www.cs.uvm.edu/~skalka/202 CS 202-1 Introduction 1 Course prerequisites CS101 Must be able to read assembly CS103 Understand tree operations basic grammars CS104 Basic data structures CS243 Helpful - more grammar + FA Solid programming skills a must. CS 202-1 Expectations 2 My specialty: programming language design, type systems Office hours: Tuesday 3:00PM-5:00PM Votey 379 Can schedule extra hours as needed skalka@cs.uvm.edu CS 202-1 Admin 3 1

GTF: Torgeir Lien Lab Hours: Monday 12:15PM-2:15PM Votey 369 Please see Torgeir for programming issues, me for conceptual issues CS 202-1 Admin 4 Weekly assignments Generally include both written problems and programming Assignments out every Tuesday in class, due next Tuesday at midnight Electronic submission via submit program NO LATE ASSIGNMENTS CS 202-1 Admin 5 Programming is central to course Programming is in java Program assignments accumulate End up with working compiler Compiles subset of C Generates SPARC code Significant code already written, you complete templates CS 202-1 Programming 6 2

Discussing assignments is permitted Everyone writes their own code See: http://www.cs.uvm.edu/ugradinfo/academic_honesty.html CS 202-1 Programming 7 13 assignments during course: 75% grad, 85% undergrad will drop lowest assignment Midterm Exam: 5% Final Exam: 10% Project: 10% Undergrads: either final or project Grads: final and project CS 202-1 Grading 8 Lectures will cover: Background theory Compiler implementations Material for assignments Slides on course web site Posted in time to print out for class notes Readings for each lecture Recommended; good book, provides insights CS 202-1 Lectures 9 3

Watch the schedule page on the class web site I will update as the semester goes on Please give me emba username Needed for submit program Please give me your effective email address I will post announcements/comments/hints to mailing list CS 202-1 Updates 10 Course is a lot of work Only about 100-200 working compiler writers in the world at a time A highly specialized craft Why take this class? CS 202-1 motivation 11 To fulfill a requirement To be well-rounded Component techniques are applicable to wide range of problems Programmers work with compilers Get the most out of your tools Understand error messages Optimize low level code CS 202-1 why 12 4

The C compiler (cc) Traditionally, the bin/cc command: cc myprog.c -o myprog executes 5 programs CS 202-1 classic bin/cc 13 cpp C preprocessor Resolves #if, #define, #include ccom C compiler itself Produces assembly source file copt (or c2) C optimizer From assembly to assembly as assembler Converts assembly to machine instrs ld linker Links machine instrs, libs CS 202-1 bin/cc programs 14 ccom consists of multiple pieces: 1. Lexer 2. Parser/type checking 3. Register allocation 4. Code generation CS 202-1 ccom internals 15 5

Classic compiler architecture source file chars lexer words (tokens) parser trees type check trees code gen machine instrs optim machine instrs emitter.o file CS 202-1 Classic compiler architecture 16 Our compiler (lake compiler) will include Lexer Parser + parse tree construction Type checking Intermediate code generation Canonicalization Code generation Data flow analysis Register allocation Optimization Code emit + runtime support CS 202-1 lake compiler 17 Two very useful tools: jlex (equivalent to lex/flex) Construct lexer from regular expressions; only need to write regexps. jcup (equivalent to yacc/bison) Construct parser from grammars; only need to write grammars CS 202-1 tools 18 6

Lexing: first step in compiler Turns stream of characters into stream of tokens Ignores many things: Comments White space CS 202-1 lexing 19 Tokens can have attributes: id or symbol what token is this Value(s) string, float, int Position where in the source code Tokens can be ints (lex) or simple objects (jlex) CS 202-1 tokens 20 Tokens defined by regular expressions Each class of tokens described by a separate regular expression Token is longest string matching any regular expression Also need expressions for portions that will be ignored (e.g. comments) CS 202-1 regular expressions 21 7

5 basic operations for reg exps: 1. primitive (character) 2. alternatives 3. concatenation 4. ε (nothing) 5. repetition CS 202-1 regular expressions 22 common notation character stands for itself (nothing) ε a b alternatives ab concatenation a* zero or more a+ one or more CS 202-1 notation 23 more common notation a? zero or one times [a-z] any character from a to z [^a-c] any character except a to c abc-g literals. any character (except new line) \x x, even if x is special character CS 202-1 notation 24 8

example regular expressions if [0-9]+ [a-za-z_][a-za-z0-9_]* // [^\n]*\n CS 202-1 examples 25 only consider longest match if8 could be lexed as 2 identifiers and a number (i,f,8) if and number (if,8) 2 identifiers (i, f8) 1 identifier (if8) 1 identifier (if8) is the right choice Always the longest possible match Order of regexp defns matters CS 202-1 longest match 26 Programs have 3 kinds of statically detectable errors: Lexical character stream matches no tokens Syntactic token stream cannot be parsed into legal abstract syntax tree (AST) Trees are semantically (e.g. type) inconsistent CS 202-1 errors 27 9

Lexer must account for lexical errors Recognize common errors and report them Missing close quotes most common Final regexp. to catch next few chars Error reporting, error recovery CS 202-1 lexical errors 28 Assignment 1 is very easy Mostly to get used to java Refresh your memory of recursively defined datastructures Download.tar.gz file from web site Includes java code for simple parse tree classes CS 202-1 assignment 1 29 ParseTree top level abstract class Concrete subclasses: UnaryExp BinaryExp ConstExp CallExp CS 202-1 ParseTree classes 30 10

ParseTree defines function argcount: Returns maximum number of arguments to any function call in the input tree You need to implement argcount in each subclass CS 202-1 argcount 31 We also include javadoc.html files provides simplistic documentation for classes We suggest starting with ParseTree.html or AllNames.html Java overview is the beginning of next lecture CS 202-1 javadoc 32 11