Splinter (Sequence Processing Language Interpreter) is a tree-walking interpreter for the Sequence Processing language.
Splinter is a work-in-progress project. For now, it builds an AST for the program, which then gets evaluated by the tree-walking interpreter.
- The next stage would be replacing the tree-walking interperter with a register-based virtual machine to gain speed.
- The last stage is fully dedicated to wrtiting down the specification.
As an example, there is an SPL program in main.spl, which solves the
Dyck-2 PTF problem for parentheses and brackets using only SPL:
def prefix_sums(bools) {
indices = Indices(bools);
selector = Select(indices, indices, <=);
shifted_indices = (Indices + 1)(bools);
indicators = Indicator(bools);
prefix_sum = shifted_indices * Aggregate(selector, indicators);
return prefix_sum;
}
def main(input) {
tokens = Tokens(input);
open_prefix = prefix_sums(
[true if char == "(" or char == "[" else false for char in tokens]
);
close_prefix = prefix_sums(
[true if char == ")" or char == "]" else false for char in tokens]
);
stack = {"empty": true};
bad = false;
out = [];
for char in tokens {
open = char == "(" or char == "[";
match = false if stack["empty"] else (
(stack["tok"] == "(" and char == ")") or (
stack["tok"] =="[" and char == "]"
)
);
label = "F" if bad else (
"P" if open else (
"F" if stack["empty"] else (
"T" if match and stack["prev"]["empty"] else ("P" if match else "F")
)
)
);
stack = {"empty": false, "tok": char, "prev": stack} if open else (
stack["prev"] if match else stack
);
bad = bad or (open == false and match == false);
out = out + [label];
}
return out;
}
result = main("([()])[]");
Print(result);The output should look like this:
List([String(P), String(P), String(P), String(P), String(P), String(T), String(P), String(T)]There's also a possibility to do non-trivial stuff in SPL, like Higher Order Functions or Comprehensions:
def hof(f, a) {
return f(a);
}
def pow(a) {
return a ^ 2;
}
result = hof(pow, 2);
Print(result);
list = [0, 2, 3, 1];
comp = [true if i < 1 else false for i in list];
Print(comp);