Download presentation

Presentation is loading. Please wait.

Published byTodd Tyler Modified about 1 year ago

1
Sigmac: Sigma Calculus Interpreter By Peer Vonna-Michell

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

3
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.

4
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.

5
Syntax Overview a, b ::=term xvariable kconstant [l i = (x i ) b i i1..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

6
Semantic Overview of Primitives Object reductions Let o[l i =(x i ) b i i1..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} ]

7
Basic Interpreter Eval([l i =(x i ) b i i1..n ]) [l i =(x i ) b i i1..n ] Eval(a.l j ) Let o = Eval(a) in If o is of the form [l i =(x i ) bi {x i } i1..n ] with j1..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 i1..n ] with j1..n Then Eval([l j =(x) b, l i =(xi) b i i1..n - {j} ]) Else wrong

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

9
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.

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

11
BNF Tokens Part 1 SKIP: {" "|"\t"|"\n"|"\r"|"\r\n"} TOKEN: { } //End of Expression TOKEN: { } TOKEN: {

12
BNF Tokens Part 2 TOKEN: { }

13
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;

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google