-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmicro-tamsin.tamsin
29 lines (23 loc) · 1.13 KB
/
micro-tamsin.tamsin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Interpreter for "Micro-Tamsin", written in Tamsin.
# (see doc/Micro-Tamsin.markdown.)
# Distributed under a BSD-style license; see LICENSE.
# REQUIRES lib/tamsin_scanner.tamsin
# REQUIRES lib/tamsin_parser.tamsin
main = tamsin_parser:parse → AST & tamsin_scanner:skippable & "/" &
interpret(AST, AST).
interpret(P, program(L)) =
tamsin_parser:find_production_global('main', 'main', P) → Main &
interpret(P, Main).
interpret(P, production(N, list(prodbranch(Fs, Ls, E), nil))) = interpret(P, E).
interpret(P, call(prodref('$', 'return'), list(atom(X), nil))) = return X.
interpret(P, call(prodref('$', 'expect'), list(atom(X), nil))) = «X».
interpret(P, call(prodref('$', 'print'), list(atom(X), nil))) = print X.
interpret(P, call(prodref('', N), A)) =
interpret(P, call(prodref('main', N), A)).
interpret(P, call(prodref(M, N), A)) =
tamsin_parser:find_production_global(M, N, P) → Prod &
interpret(P, Prod).
interpret(P, or(L, R)) = interpret(P, L) | interpret(P, R).
interpret(P, and(L, R)) = interpret(P, L) & interpret(P, R).
interpret(P, not(X)) = !interpret(P, X).
interpret(P, while(X)) = {interpret(P, X)}.