-
Notifications
You must be signed in to change notification settings - Fork 2
/
logolas.nit
77 lines (62 loc) · 1.07 KB
/
logolas.nit
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module logolas
import logolas_parser
import logolas_lexer
import logolas_test_parser
class Interp
super Visitor
var x = 0
var y = 0
var angle = 0
redef fun visit(node) do
node.accept(self)
#print "{x}, {y} @ {angle}"
end
end
redef class Node
fun accept(v: Interp) do visit_children(v)
end
redef class Nn
fun value: Int
do
return text.first.code_point - 'Ⅰ'.code_point + 1
end
end
redef class Ncmd_fw
redef fun accept(v)
do
var n = n_n.value.to_f
var a = v.angle.to_f / 6.0 * pi
v.x += (a.cos * n).to_i
v.y -= (a.sin * n).to_i
end
end
redef class Ncmd_tl
redef fun accept(v)
do
var n = n_n.value
v.angle += n
end
end
redef class Ncmd_tr
redef fun accept(v)
do
var n = n_n.value
v.angle -= n
end
end
redef class Ncmd_rp
redef fun accept(v)
do
var n = n_n.value
for i in [0..n] do v.enter_visit(n_cmds)
end
end
var text = args.first.to_path.read_all
var l = new Lexer_logolas(text)
var tokens = l.lex
var p = new Parser_logolas
p.tokens.add_all(tokens)
var node = p.parse
var i = new Interp
i.enter_visit(node)
print "({i.x},{i.y})"