-
Notifications
You must be signed in to change notification settings - Fork 1
/
PARSER
85 lines (62 loc) · 1.25 KB
/
PARSER
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
78
79
80
81
82
83
84
85
a = 10
b = 20
c = 30
my_array = [1,2,3]
push my_array, 20
a = pop my_array
-- this is a comment
-- yadda yadda yadda
def calculate(a, b = 20, c = 30) {
local x, y, z
length(my_array)
while a < b {
a = a + c
}
if c % 2 == 1 {
} else if c % 3 == 1 {
} else {
}
-- for, foreach
foreach my_array => i {
print i
}
}
def draw(a, b, c) {
pen #ff0000 -- function calls
linewidth 5
moveto 10, 10
lineto 30, 30
lineto 50, 100
}
def blue(isOn) {
fill isOn ? #blue : #black
pen #white
circle 100, 100, 50
}
def red(isOn) {
fill isOn ? #red : #black
pen #white
circle 300, 100, 50
}
def run {
while true {
red on
blue off
wait 0.5
red off
blue on
wait 0.5
}
}
how does scoping work?
- in the root scope, variables can be declared without `local`
- variables declared in root scope never escape the compilation unit
- variables are lexically scoped
- block scoping for locals
open questions:
- computed properties e.g. canvas width/height
- constants
ternary operator
- modify to support stashing of last computed result
- in empty 'if' blocks, set last result to null/undefined
- ternary operator then becomes if/else compilation + push last computed value