CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Similar documents
CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE410 aka CSE306 Software Quality

CSE302: Compiler Design

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CPS 506 Comparative Programming Languages. Syntax Specification

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

1 Lexical Considerations

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSCI312 Principles of Programming Languages!

Theoretical Part. Chapter one:- - What are the Phases of compiler? Answer:

Lexical Considerations

EDA180: Compiler Construc6on Context- free grammars. Görel Hedin Revised:

Parsing. source code. while (k<=n) {sum = sum+k; k=k+1;}

Lexical Considerations

Syntax. In Text: Chapter 3

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

A programming language requires two major definitions A simple one pass compiler

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

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

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

Lexical Analysis. Introduction

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

CS 441G Fall 2018 Exam 1 Matching: LETTER

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

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part 1

QUIZ Lesson 4. Exercise 4: Write an if statement that assigns the value of x to the variable y if x is in between 1 and 20, otherwise y is unchanged.

Compiler Construction

CS 314 Principles of Programming Languages

LECTURE 3. Compiler Phases

Grammars and Parsing. Paul Klint. Grammars and Parsing

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

4. An interpreter is a program that

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSCE 314 Programming Languages

Lexical Analysis. Lecture 2-4

Bottom-Up Parsing. Lecture 11-12

Some Basic Definitions. Some Basic Definitions. Some Basic Definitions. Language Processing Systems. Syntax Analysis (Parsing) Prof.

Language Reference Manual simplicity

Parsing CSCI-400. Principles of Programming Languages.

Bottom-Up Parsing. Lecture 11-12

Syntax Analysis. Prof. James L. Frankel Harvard University. Version of 6:43 PM 6-Feb-2018 Copyright 2018, 2015 James L. Frankel. All rights reserved.

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

Compiler Construction

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

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

CSE302: Compiler Design

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

Formal Languages and Compilers Lecture I: Introduction to Compilers

Lexical and Syntax Analysis. Top-Down Parsing

CSE 3302 Programming Languages Lecture 2: Syntax

Compiler phases. Non-tokens

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

Building Compilers with Phoenix

Undergraduate Compilers in a Day

Introduction. Compiler Design CSE Overview. 2 Syntax-Directed Translation. 3 Phases of Translation

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

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

LANGUAGE PROCESSORS. Presented By: Prof. S.J. Soni, SPCE Visnagar.

A Simple Syntax-Directed Translator

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CMSC 330: Organization of Programming Languages. Context Free Grammars

Syntax-Directed Translation. Lecture 14

CS 415 Midterm Exam Spring SOLUTION

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Chapter 3. Describing Syntax and Semantics

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS 406/534 Compiler Construction Parsing Part I

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

THE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES

Compiler Code Generation COMP360

Dr. D.M. Akbar Hussain

WARNING for Autumn 2004:

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

CS313T ADVANCED PROGRAMMING LANGUAGE

CS453 Compiler Construction

CMSC 350: COMPILER DESIGN

Principles of Compiler Construction ( )

Languages and Compilers

Syntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing

announcements CSE 311: Foundations of Computing review: regular expressions review: languages---sets of strings

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

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

Habanero Extreme Scale Software Research Project

Semantic Analysis. Compiler Architecture

Compilers. Computer Science 431

1. Consider the following program in a PCAT-like language.

Crafting a Compiler with C (II) Compiler V. S. Interpreter

Lecture 8: Context Free Grammars

EECS483 D1: Project 1 Overview

CSE 307: Principles of Programming Languages

Transcription:

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei

BUILD A COMPILER!

Learning outcomes Learning outcome Identify and describe the function of the major phases of a compiler. Define formally the grammars used in the front end of a compiler, their application in the front end, and techniques for parsing such grammars. Evaluate (compare and contrast) different intermediate representations. Explain the compiler s role in creating and managing run-time environments. Explain and evaluate (compare and contrast) different approaches to code generation. Identify and explain the applicability and operation of code optimizations. Build both the front and back ends of a compiler. Instructional methods Lecture-based instruction Hands-on activities in lecture and recitation Assessment HW, EX PRE, HW, EX PROJ

Assessment Homework - 5-7 assignments Project - 5-7 phases Presentation - 1-2 per team Examination - 3 hour final, based on homework/project

Grading INDIVIDUAL TEAM Homework 30% Exam 20% Project 40% Presentation 10%

Teams & Recitations Form teams this week - I recommend teams of size 3-4. Recitations start this week. Recommend all team members attend same recitation, but not required (you can attend either recitation). For project, you may choose either C or SML - decide with your teammates (you must have a unanimous decision). We will discuss more in recitation this week.

Goal: build a compiler source program executable

Phases of a compiler source program executable Figure 1.6, page 5 of text

Why? Deeper understanding of languages Become a better programmer Learn how to build tools Build special-purpose languages (DSLs) Theory meets practice High-level meets low-level

Deep understanding - ex 1 name vs identifier vs variable

Deep understanding - ex 1 void foo() { int x = 0; printf(x); }

Deep understanding - ex 1 int func(int x) { if (x == 0) { return 1; } else { return x * func(x-1); } }

Deep understanding - ex 1 struct Pair { int x; int y; }; void bar() { Pair r, s; }

name y.x variable identifier x refers to location in memory

RUNTIME CODE variable variable identifier x variable variable variables in distinct scopes, variables in distinct records/objects, or variables in distinct function invocations

Deep understanding - ex 2 order of evaluation

Deep understanding - ex 2 a + b * c;

Deep understanding - ex 2 a + b * c; f() + g() * h();

Deep understanding - ex 2 a + b * c; f() + g() * h(); f() + f() * f();

Languages: the Chomsky hierarchy "On Certain Formal Properties of Grammars" recursively enumerable context-sensitive context-free regular https://upload.wikimedia.org/wikipedia/commons/8/86/noam_chomsky.jpg

SOURCE: https://openi.nlm.nih.gov/detailedresult.php?img=pmc3367694_rstb20120103-g2&req=4 AUTHORS: Fitch WT, Friederici AD - Philos. Trans. R. Soc. Lond., B, Biol. Sci. (2012) LICENSE: http://creativecommons.org/licenses/by/3.0/

Syntactic structure Lexical structure SOURCE: https://openi.nlm.nih.gov/detailedresult.php?img=pmc3367694_rstb20120103-g2&req=4 AUTHORS: Fitch WT, Friederici AD - Philos. Trans. R. Soc. Lond., B, Biol. Sci. (2012) LICENSE: http://creativecommons.org/licenses/by/3.0/

Phases of a compiler Lexical structure Syntactic structure Figure 1.6, page 5 of text

Lexical Structure int main(){

Lexical Structure int main(){ character stream i n t m a i n ( ) {

Lexical Structure int main(){ character stream -> token stream i n t m a i n ( ) { id( int ) id( main ) LPAR RPAR LBRACE

Lexical Structure tokens keywords (e.g. static, for, while, struct) operators (e.g. <, >, <=, =, ==, +, -, &,.) identifiers (e.g. foo, bar, sum, mystery) literals (e.g. -17, 34.52E-45, true, e, Serenity ) punctuation (e.g. {, }, (, ), ; )

meta vs object language object language: the language we are describing meta language: the language we use to describe the object language

meta vs object language use quotes (meta vs object ) punctuation (e.g. {, }, (, ), ; ) use font or font property (meta vs object) punctuation (e.g. {, }, (, ), ; )

languages & grammars Formally, a language is a set of strings over some alphabet Ex. {00, 01, 10, 11} is the set of all strings of length 2 over the alphabet {0, 1} Ex. {00, 11} is the set of all even parity strings of length 2 over the alphabet {0, 1}

languages & grammars Formally, a grammar is defined by 4 items: 1. N, a set of non-terminals 2., a set of terminals 3. P, a set of productions 4. S, a start symbol G = (N,, P, S)

languages & grammars N, a set of non-terminals, a set of terminals (alphabet) N = {} P, a set of productions of the form (right linear) X -> a X -> ay X -> ℇ X N, Y N, a, ℇ denotes the empty string S, a start symbol S N

languages & grammars Given a string αα, where α * and Α N, and a production Α -> β P we write αα => αβ to indicate that αα derives αβ in one step. => k and => * can be used to indicate k or arbitrarily many derivation steps, respectively.

languages & grammars L(G) is the set of all strings derivable from G starting with the start symbol; i.e. it denotes the language of G.

languages & grammars Given a grammar G the language it generates, L(G), is unique. Given a language L there are many grammars H such that L(H) = L.