EECS 395 Programming Languages

Similar documents
EECS 321 Programming Languages

EECS 321 Programming Languages

CMSC 330: Organization of Programming Languages

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Last time. What are compilers? Phases of a compiler. Scanner. Parser. Semantic Routines. Optimizer. Code Generation. Sunday, August 29, 2010

EECS 6083 Intro to Parsing Context Free Grammars

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

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

"Good" vs. "Bad" Expressions. ; interp-expr FAE... -> FAE-Value

CPS 506 Comparative Programming Languages. Syntax Specification

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

CSE 12 Abstract Syntax Trees

Programming Language Definition. Regular Expressions

COP 3402 Systems Software Syntax Analysis (Parser)

Introduction to Parsing

Lecture 10 Parsing 10.1

Syntax. A. Bellaachia Page: 1

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part 1

Lecture 4: Syntax Specification

Higher-Order Functions (Part I)

Context-Free Grammar (CFG)

Syntax. In Text: Chapter 3

CSCI312 Principles of Programming Languages!

Defining syntax using CFGs

Exercises Software Development I. 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF)

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:

F453 Module 7: Programming Techniques. 7.2: Methods for defining syntax

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

Advanced Topics in Software Engineering (02265) Ekkart Kindler

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

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Today. Elements of Programming Languages. Concrete vs. abstract syntax. L Arith. Lecture 1: Abstract syntax

Examination in Compilers, EDAN65

Creating a Matching Activity using Pictures from the Internet

Outline CS412/413. Administrivia. Review. Grammars. Left vs. Right Recursion. More tips forll(1) grammars Bottom-up parsing LR(0) parser construction

Inside PHP Tom OSCON th July, 2012

Parsing II Top-down parsing. Comp 412

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

Compiler Construction 1. Introduction. Oscar Nierstrasz

22c:111 Programming Language Concepts. Fall Syntax III

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

CS 415 Midterm Exam Spring 2002

CMSC 330: Organization of Programming Languages. Context Free Grammars

COP 3402 Systems Software Top Down Parsing (Recursive Descent)

Chapter 3. Describing Syntax and Semantics

Outline. Helper Functions and Reuse. Conditionals. Evaluation Rules for cond. Design Recipe with cond. Compound Data

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Introduction to Compilers

The Substitution Model

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

Two Problems. Programming Languages and Compilers (CS 421) Type Inference - Example. Type Inference - Outline. Type Inference - Example

Introduction to Data Management CSE 344. Lecture 1: Introduction

Chapter 3 (part 3) Describing Syntax and Semantics

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

Building Compilers with Phoenix

A language is a subset of the set of all strings over some alphabet. string: a sequence of symbols alphabet: a set of symbols

Compiler Construction 1. Introduction. Oscar Nierstrasz

Integers II. CSE 351 Autumn Instructor: Justin Hsia

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

Integers II. CSE 351 Autumn Instructor: Justin Hsia

cs173: Programming Languages

Memory, Data, & Addressing II

Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2

DSL vs. Library API Shootout

Scientific Computing: Lecture 1

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

CSE 351. Introduction & Course Tools

Chapter 3. Describing Syntax and Semantics

Lexical Addresses. let x = 1 y = 2 in let f = proc (x) +(x, y) in (f x) let _ = 1 _ = 2 in let _ = proc (_) +(<0,0>, <1,1>) in (<0,0> <1,0>)

General course information

Formal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack

Preparing for the ACW Languages & Compilers

Ray Pereda Unicon Technical Report UTR-03. February 25, Abstract

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics

Memory and Arrays. CSE 333 Spring Instructor: Justin Hsia

CS 3304 Comparative Languages. Lecture 1: Introduction

CS 314 Principles of Programming Languages. Lecture 3

Integers II. CSE 351 Autumn 2018

CS558 Programming Languages

CSc 372. Comparative Programming Languages. 36 : Scheme Conditional Expressions. Department of Computer Science University of Arizona

Lexical and Syntax Analysis

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions

Programming Languages Third Edition

Dr. D.M. Akbar Hussain

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

Part 5 Program Analysis Principles and Techniques

afewadminnotes CSC324 Formal Language Theory Dealing with Ambiguity: Precedence Example Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm

Principles of Programming Languages COMP251: Syntax and Grammars

The Substitution Model. Nate Foster Spring 2018

Introduction to Linux. Fundamentals of Computer Science

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

Object-Oriented Design Lecture 7 CSU 370 Fall 2008 (Pucella) Friday, Oct 3, 2008

SOFTWARE ARCHITECTURE 5. COMPILER

CSCI 334: Principles of Programming Languages. Lecture 2: Lisp Wrapup & Fundamentals. Higher-Order Functions. Activity

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg

CPSC 411: Introduction to Compiler Construction

Transcription:

EECS 395 Programming Languages Winter 2010 Instructor: Robby Findler 1

Course Details http://www.eecs.northwestern.edu/~robby/ courses/395-2010-winter/ (or google findler and follow the links) 2

Programming Language Concepts This course teaches concepts in two ways: By implementing interpreters new concept! new interpreter By using Scheme and variants we don t assume that you already know Scheme 3

Interpreters vs Compilers An interpreter takes a program and produces a result DrScheme x86 processor desktop calculator bash Algebra student 4

Interpreters vs Compilers An interpreter takes a program and produces a result DrScheme x86 processor desktop calculator bash Algebra student A compiler takes a program and produces a program DrScheme x86 processor gcc javac 5

Interpreters vs Compilers An interpreter takes a program and produces a result DrScheme x86 processor desktop calculator bash Algebra student Good for understanding program behavior, easy to implement A compiler takes a program and produces a program DrScheme x86 processor gcc javac Good for speed, more complex (come back next quarter) 6

Interpreters vs Compilers An interpreter takes a program and produces a result DrScheme x86 processor desktop calculator bash Algebra student Good for understanding program behavior, easy to implement A compiler takes a program and produces a program DrScheme x86 processor gcc javac Good for speed, more complex (come back next quarter) So, what s a program? 7

A Grammar for Algebra Programs A grammar of Algebra in BNF (Backus-Naur Form): prog ::= defn * expr defn ::= id ( id ) = expr expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num id ::= a variable name: f, x, y, z,... num ::= a number: 1, 42, 17,... 8

A Grammar for Algebra Programs A grammar of Algebra in BNF (Backus-Naur Form): prog ::= defn * expr defn ::= id ( id ) = expr expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num id ::= a variable name: f, x, y, z,... num ::= a number: 1, 42, 17,... Each meta-variable, such as prog, defines a set 9

Using a BNF Grammar id ::= a variable name: f, x, y, z,... num ::= a number: 1, 42, 17,... The set id is the set of all variable names The set num is the set of all numbers 10

Using a BNF Grammar id ::= a variable name: f, x, y, z,... num ::= a number: 1, 42, 17,... The set id is the set of all variable names The set num is the set of all numbers To make an example member of num, simply pick an element from the set 11

Using a BNF Grammar id ::= a variable name: f, x, y, z,... num ::= a number: 1, 42, 17,... The set id is the set of all variable names The set num is the set of all numbers To make an example member of num, simply pick an element from the set 2 " num 298 " num 12

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num The set expr is defined in terms of other sets 13

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable combine the examples with literal text 14

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable combine the examples with literal text 15

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable 7 " num combine the examples with literal text 16

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable 7 " num combine the examples with literal text 7 " expr 17

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable combine the examples with literal text 18

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable f " id combine the examples with literal text 19

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable f " id 7 " expr combine the examples with literal text 20

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable f " id 7 " expr combine the examples with literal text f(7) " expr 21

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable f " id f(7) " expr combine the examples with literal text 22

Using a BNF Grammar expr ::= ( expr + expr ) ( expr - expr ) id ( expr ) id num To make an example expr : choose one case in the grammar pick an example for each meta-variable f " id f(7) " expr combine the examples with literal text f(f(7)) " expr 23

Using a BNF Grammar prog ::= defn * expr defn ::= id ( id ) = expr f(x) = (x + 1) " defn 24

Using a BNF Grammar prog ::= defn * expr defn ::= id ( id ) = expr f(x) = (x + 1) " defn To make a prog pick some number of defn s (x + y) " prog f(x) = (x + 1) g(y) = f((y - 2)) g(7) " prog 25

Programming Language A programming language is defined by a grammar for programs rules for evaluating any program to produce a result 26

Programming Language A programming language is defined by a grammar for programs rules for evaluating any program to produce a result For example, Algebra evaluation is defined in terms of evaluation steps: (2 + (7-4))! (2 + 3)! 5 27

Programming Language A programming language is defined by a grammar for programs rules for evaluating any program to produce a result For example, Algebra evaluation is defined in terms of evaluation steps: f(x) = (x + 1) f(10)! (10 + 1)! 11 28

Evaluation Evaluation! is defined by a set of pattern-matching rules: (2 + (7-4))! (2 + 3) due to the pattern rule... (7-4)...!... 3... 29

Evaluation Evaluation! is defined by a set of pattern-matching rules: f(x) = (x + 1) f(10)! (10 + 1) due to the pattern rule... id 1 ( id 2 ) = expr 1...... id 1 ( expr 2 )...!... expr 3... where expr 3 is expr 1 with id 2 replaced by expr 2 30

Rules for Evaluation Rule 1 - one pattern... id 1 ( id 2 ) = expr 1...... id 1 ( expr 2 )...!... expr 3... where expr 3 is expr 1 with id 2 replaced by expr 2 31

Rules for Evaluation Rule 1 - one pattern... id 1 ( id 2 ) = expr 1...... id 1 ( expr 2 )...!... expr 3... where expr 3 is expr 1 with id 2 replaced by expr 2 Rules 2 -! special cases... (0 + 0)... "... 0...... (0-0)... "... 0...... (1 + 0)... "... 1...... (1-0)... "... 1...... (2 + 0)... "... 2...... (2-0)... "... 2... etc. etc. 32

Rules for Evaluation Rule 1 - one pattern... id 1 ( id 2 ) = expr 1...... id 1 ( expr 2 )...!... expr 3... where expr 3 is expr 1 with id 2 replaced by expr 2 Rules 2 -! special cases... (0 + 0)... "... 0...... (0-0)... "... 0...... (1 + 0)... "... 1...... (1-0)... "... 1...... (2 + 0)... "... 2...... (2-0)... "... 2... etc. etc. When the interpreter is a program instead of an Algebra student, the rules look a little different 33

HW 1 On the course web page: Write an interpreter for a small language of string manipulations Assignment is due Friday Your code may be featured in class on Monday 34