Advanced Fusion Reactor
Tokamak DSL is a Domain Specific Language for .NET, written with FParsec parser combinator library.
Tokamak can be embedded in .NET / mono applications (using .NET framework ~4.0+).
Expressions are evaluated right to left, with no operator precedence. Parentheses are used to evaluate subexpressions before the outer expression.
- 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 are declared using function
keyword followed by the function name, the parameters, the function body, and is
terminated using the end
keyword.
function fib(n)
if n <= 1 then 1
else
n * fib(n-1)
end
end
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
Tokamak has while-loops and for-loops, as well as if-elif-else blocks.
a = 0
ctr = "a"
while a < 10 do
a = a + 1
ctr = ctr+"a"
end
will produce the string aaaaaaaaaa
.
function iseven(n) (n%2) = 0 end
arr = 0$100
for i in 0$100 do
arr[i] = iseven(i)
end
arr
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