https://github.com/jonghough/tokamak
mini DSL language built with F# + FParsec
https://github.com/jonghough/tokamak
dot-net dsl f-sharp language mini-language tokamak
Last synced: 6 months ago
JSON representation
mini DSL language built with F# + FParsec
- Host: GitHub
- URL: https://github.com/jonghough/tokamak
- Owner: jonghough
- License: mit
- Created: 2016-12-26T09:56:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-26T01:36:28.000Z (over 9 years ago)
- Last Synced: 2025-01-10T02:25:51.969Z (over 1 year ago)
- Topics: dot-net, dsl, f-sharp, language, mini-language, tokamak
- Language: F#
- Homepage:
- Size: 828 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/jonghough/Tokamak)
# Tokamak
Advanced Fusion Reactor
# Tokamak DSL
Tokamak DSL is a Domain Specific Language for .NET, written with *FParsec* parser combinator library.
## Purpose
Tokamak can be embedded in .NET / mono applications (using .NET framework ~4.0+).
## Evaluation
Expressions are evaluated right to left, with no operator precedence. Parentheses are used to evaluate subexpressions before the
outer expression.
## DataTypes
* Integer - corresponds to int64
* Floating - corresponds to double
* Literal - corresponds to string
* Bool - bool
* Array - This is an array of expressions, which may be datatypes or other expressions that can be evaluated to a datatype.
## Functions
Functions are declared using ```function``` keyword followed by the function name, the parameters, the function body, and is
terminated using the ```end``` keyword.
### example
```
function fib(n)
if n <= 1 then 1
else
n * fib(n-1)
end
end
```
## Array creation
Array declarations are simple:
```
myArray = 0$10
```
This will create an array [0,1,...,9].
The contents of the array can be modified arbitrarily:
```
myArray[0] = 5.5
```
## Controls
Tokamak has *while-loops* and *for-loops*, as well as *if-elif-else* blocks.
### while loops
```
a = 0
ctr = "a"
while a < 10 do
a = a + 1
ctr = ctr+"a"
end
```
will produce the string ```aaaaaaaaaa```.
### for loops
```
function iseven(n) (n%2) = 0 end
arr = 0$100
for i in 0$100 do
arr[i] = iseven(i)
end
arr
```
### if-elseif-else control
```
a = 0$100
m0 = 0
m1 = 0
m2 = 0
for i in a do
if 0 = i%3 then
m0 = m0 + 1
elseif 1 = i%3 then
m1 = m1 + 1
else m2 = m2 + 1
end
end
```