Programming Languages Dan Grossman 2013

Slides:



Advertisements
Similar presentations
A Third Look At ML 1. Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order.
Advertisements

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
Types and Arithmetic Operators
Basic Control Structures Control order of execution of statements sequential selection iteration - Repeat some action while a certain condition is true.
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Fall 2011.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Fall 2011.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Lesson 1.7 Dividing Integers Standards: NS 1.2 and AF 2.1 Objectives: Dividing Integers Evaluate variable expressions.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
CSE 341 : Programming Languages Lecture 1 Hello World! Welcome to ML Zach Tatlock Spring 2014.
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Spring 2013.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
CSE 341 : Programming Languages Lecture 2 Functions, Pairs, Lists Zach Tatlock Spring 2014.
Input Validation 10/09/13. Input Validation with if Statements You, the C++ programmer, doing Quality Assurance (by hand!) C++ for Everyone by Cay Horstmann.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Learn to subtract integers. Course Subtracting Integers.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
Lesson 4 : Exponent Laws I Check it out... Can you see a short cut rule?
Programming Languages Dan Grossman 2013 ML Expressions and Variable Bindings.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Subtracting Integers #41.
CSE341: Programming Languages Lecture 11 Type Inference
CSE 341 Section 1 (9/28) With thanks to Dan Grossman, et. al. from previous versions of these slides.
Chapter 4 Repetition Statements (loops)
CSE 341 Section 1 (9/28) With thanks to Dan Grossman, et. al. from previous versions of these slides.
Advanced Excel Topics – Loops
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
Evaluating Algebraic Expressions
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Spring 2017.
Chapter 5: Loops and Files.
Nicholas Shahan Spring 2016
CSE 341: Programming Languages Section 1
CSE 341: Programming Langs
CSE341: Programming Languages Section 1
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Fall 2017.
CSE341: Programming Languages Section 1
Section 1-6: Multiplying Integers
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE 341: Programming Languages Section 1
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Autumn 2018.
What is a programming language?
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Language-based Security
Objective: Evaluate & Simplify expressions containing zero and integer exponents.
Flowcharts and Pseudo Code
CSE341: Programming Languages Lecture 11 Type Inference
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Spring 2019.
What is a programming language?
Objective: Evaluate & Simplify expressions containing zero and integer exponents.
CSE341: Programming Languages Lecture 11 Type Inference
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 11 Type Inference
Presentation transcript:

Programming Languages Dan Grossman 2013 ML Rules for Expressions (Seen So Far)

A very simple ML program This program has integers, variables, addition, if-expressions, less-than, subtraction, and calling a pre-defined function (* My first ML program *) val x = 34; val y = 17; val z = (x + y) + (y + 2); val q = z + 1; val abs_of_z = if z < 0 then 0 – z else z; val abs_of_z_simpler = abs z Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Expressions We have seen many kinds of expressions: 34 true false x e1+e2 e1<e2 if e1 then e2 else e3 Can get arbitrarily large since any subexpression can contain subsubexpressions, etc. Every kind of expression has Syntax Type-checking rules Produces a type or fails (with a bad error message ) Types so far: int bool unit Evaluation rules (used only on things that type-check) Produces a value (or exception or infinite-loop) Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Variables Syntax: sequence of letters, digits, _, not starting with digit Type-checking: Look up type in current static environment If not there, fail Evaluation: Look up value in current dynamic environment Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Addition Syntax: e1 + e2 where e1 and e2 are expressions Type-checking: If e1 and e2 have type int, then e1 + e2 has type int Evaluation: If e1 evaluates to v1 and e2 evaluates to v2, then e1 + e2 evaluates to sum of v1 and v2 Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Values All values are expressions Not all expressions are values Every value “evaluates to itself” in “zero steps” Examples: 34, 17, 42 have type int true, false have type bool () has type unit Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages A slightly tougher one What are the syntax, typing rules, and evaluation rules for conditional expressions? Let’s write it out… Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Now you try one Syntax, type-checking rules, and evaluation rules for less-than comparisons? Jan-Mar 2013 Dan Grossman, Programming Languages