Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

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

6 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} ]

7 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

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: { <VARIABLE: ( ("-") (["0"-"9"])+ ) | (["a"-"z"] | ["A"-"Z"] | ["0"-"9"])+ > }  TOKEN: { }

12 BNF Tokens Part 2  TOKEN: { }

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


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

Similar presentations


Ads by Google