Sigmac: Sigma Calculus Interpreter By Peer Vonna-Michell 225452.

Slides:



Advertisements
Similar presentations
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Advertisements

Assignments and Procs w/Params EOPL3 Chapter 4. Expressible vs. Denotable values Expressible Values –the language can express and compute these –represented.
10. Applications of Logic Programming. © O. Nierstrasz PS — Applications of Logic Programming 10.2 Roadmap 1. Search problems —SEND + MORE = MONEY 2.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Program Representations. Representing programs Goals.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
UNIT-III By Mr. M. V. Nikum (B.E.I.T). Programming Language Lexical and Syntactic features of a programming Language are specified by its grammar Language:-
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
Inheritance Part I. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
Chapter 3 Implementing Classes. Instance Variables Instance variables store the data of an object; the fields of an object. Instance of a class: an object.
CS 100Lecture 61 CS100J Lecture 6 n Previous Lecture –Programming Concepts n Programming by stepwise refinement –a pattern –sequential refinement –case.
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
1 Scheme Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Environments and Evaluation
MinML: an idealized programming language CS 510 David Walker.
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Winter 2003/4Pls – syntax – Catriel Beeri1 SYNTAX Syntax: form, structure The syntax of a pl: The set of its well-formed programs The rules that define.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
The Interpreter Pattern. Defining the Interpreter Intent Given a language, define a representation for its grammar along with an interpreter that uses.
Precision Going back to constant prop, in what cases would we lose precision?
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Imperative Programming
1 Abstract Syntax Tree--motivation The parse tree –contains too much detail e.g. unnecessary terminals such as parentheses –depends heavily on the structure.
COMS W4115 Programming Languages & Translators Maria Ayako Taku COMS W PLT Columbia University 1 April 24, 2013 Functional Programming.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Aim: What are the number system and order of operation? Do Now: 1. Write a few numbers as you like 2. Try to categorize the numbers you just wrote HW:
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
CMSC 330: Organization of Programming Languages
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
CPS 506 Comparative Programming Languages Syntax Specification.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
1.2 Adding Integers Adding 3 or more terms. Strategy You can add everything going from left to right Or you can use Commutative and Associative Properties.
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Winter 2013.
Operational Semantics of Scheme
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2017.
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
Interpreters Study Semantics of Programming Languages through interpreters (Executable Specifications) cs7100(Prasad) L8Interp.
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
Programming Language Concepts
Is everyone signed up on piazza?
Mini Language Interpreter Programming Languages (CS 550)
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Zach Tatlock Winter 2018.
Procedures App B: SLLGEN 1.
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2016.
Adapted from slides by Nicholas Shahan, Dan Grossman, and Tam Dang
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2017.
Assignments and Procs w/Params
CSCE 314: Programming Languages Dr. Dylan Shell
Warm Up. Warm Up Obj: Students will multiply, divide, and simplify rational expressions.
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
Changing Data: (Continued)
Evaluating Expressions
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2019.
Previous Lecture: Today’s Lecture: Reading (JV):
Presentation transcript:

Sigmac: Sigma Calculus Interpreter By Peer Vonna-Michell

Aims of the Project  Develop an Interpreter supporting: The Sigma Calculus Imperative Operations Integer extensions Arithmetic expressions Functions (Translated into Sigma Calc.)

What is the Sigma Calculus?  Small Object-based Language Objects are the only primitives No classes  Allows easy prototyping of languages Implementation free Ideal for OO languages  Formal understanding of objects Semantics, typing, inheritance, etc.

Why?  Expressions can be difficult to evaluate, and the interpreter allows for: Accurate evaluation Implicit translation of more complex expressions. I.e. Functions Ease of use  Provides a medium with which to rationalise about OO languages and features.

Syntax Overview a, b ::=term xvariable kconstant [l i = (x i ) b i i1..n ]object a.lmethod invocation a.l  (x) b methods update let x = a in bsequential eval clone(a)shallow copy fun(x) afunction definition fun(x)function call

Semantic Overview of Primitives Object reductions Let o[l i =(x i ) b i i1..n ] Invocation reductions o.l j  b j { x j ← o } Update reduction o.l j   (y) b  [l j = (y) b, l i =  (x i ) b i i (1..n)-{j} ]

Basic Interpreter Eval([l i =(x i ) b i i1..n ])  [l i =(x i ) b i i1..n ] Eval(a.l j )  Let o = Eval(a) in If o is of the form [l i =(x i ) bi {x i } i1..n ] with j1..n Then Eval(b j {o}) Else wrong Eval(a.l j   (x) b)  Let o = Eval(a) in If o is of the form [l i =(x i ) b i i1..n ] with j1..n Then Eval([l j =(x) b, l i =(xi) b i i1..n - {j} ]) Else wrong

Sigmac Packages  Split into 6 main packages AST – Syntax Classes  Arithmetic Eval – Evaluated -Objects Parser – Javacc Classes TextUI Classes GUIUI Classes

Sigmac Architecture Part 1 AST Classes Expression eval(Env) V eval() name O eval() Invoke eval() name Update eval() name F name Body expr * Let eval() expr1 expr2 Clone eval() expr Arithmetic eval(Env) op1 op2 Add eval(Env) Sub eval(Env) Parenthesis eval(Env) expr Function eval(Env) translate() Multiply eval(Env) Modulo eval(Env) Divide eval(Env) Note: All eval() methods should in fact be eval(Env). This is not shown due to space restrictions.

Sigmac Architecture Part 2 Eval Classes Value convert() Env Obj convert() Atomic Convert() Int convert() number Field name Method binderName Binder name Expression * *

BNF Tokens Part 1  SKIP: {" "|"\t"|"\n"|"\r"|"\r\n"}  TOKEN: { } //End of Expression  TOKEN: { }  TOKEN: { <VARIABLE: ( ("-") (["0"-"9"])+ ) | (["a"-"z"] | ["A"-"Z"] | ["0"-"9"])+ > }  TOKEN: { }

BNF Tokens Part 2  TOKEN: { }

Example – Bank Account bankAccount = [balance 0; name joe; withdraw fun(x) this.balance ((this.balance) - x); deposit fun(x) this.balance ((this.balance) + x); ]; amount = 5 * 20; (bankAccount.deposit(amount)).balance;