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

## Presentation on theme: "Sigmac: Sigma Calculus Interpreter By Peer Vonna-Michell 225452."— Presentation transcript:

Sigmac: Sigma Calculus Interpreter By Peer Vonna-Michell 225452

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: { }  TOKEN: { }

BNF Tokens Part 2  TOKEN: { }

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