https://github.com/radrow/tiny-semantics
Task for Semantics and Programs Verification course at MIMUW – denotational semantics of extended Tiny programming language in continuational style
https://github.com/radrow/tiny-semantics
continuation-passing-style haskell interpreter programming-language semantics
Last synced: 11 months ago
JSON representation
Task for Semantics and Programs Verification course at MIMUW – denotational semantics of extended Tiny programming language in continuational style
- Host: GitHub
- URL: https://github.com/radrow/tiny-semantics
- Owner: radrow
- Created: 2019-01-15T12:36:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-12T10:20:46.000Z (over 5 years ago)
- Last Synced: 2025-01-22T21:28:28.341Z (about 1 year ago)
- Topics: continuation-passing-style, haskell, interpreter, programming-language, semantics
- Language: Haskell
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
* Tiny-Semantics
Tiny is a minimalistic programming language featuring evaluation of simple expressions like ~+~, ~-~, ~*~ on integral numbers along with some basic logic expressions to handle ~if~ statements.
#+BEGIN_SRC haskell
data Expr = LitInt Integer
| Var VarName
| Plus Expr Expr
| Minus Expr Expr
| Mult Expr Expr
data BExpr = LitBool Bool
| Con BExpr BExpr
| Eq Expr Expr
| Lt Expr Expr
| Neg BExpr
data Instr = Skip
| Assign VarName Expr
| Semicolon Instr Instr
| If BExpr Instr Instr
| While BExpr Instr
| Begin Decl Instr -- new feature!
| Call ProcName VarName -- new feature!
#+END_SRC
This version of Tiny is extended with variable declarations and recursive procedures.
#+BEGIN_SRC haskell
data Decl = VarDecl VarName Expr | ProcDecl ProcName VarName Instr | EmptyDecl | ConsDecl Decl Decl
#+END_SRC
All procedures take single argument by name reference and return nothing – the only way to gather it's result is to assign new value to the argument, for instance evaluating program:
#+BEGIN_SRC haskell
sample :: Instr
sample = Begin (ConsDecl
(VarDecl "x" (LitInt 0))
(ProcDecl "p" "y"
(Semicolon
(Assign "y" (LitInt 3))
(If (Eq (Var "x") (LitInt 3))
(Assign "y" (LitInt 4))
Skip
)
)
))
(Call "p" "x")
#+END_SRC
Will return state where ~x~ is bound to value ~3~.
The semantics of this language is written in continuational style as a task for MIMUW course.