-
Notifications
You must be signed in to change notification settings - Fork 203
/
testlang.t
69 lines (63 loc) · 1.43 KB
/
testlang.t
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
return {
keywords = {"akeyword"};
entrypoints = {"image", "foolist"};
expression = function(self,lex,noskip)
if not noskip then
if lex:nextif("foolist") then
return self:foolist(lex)
end
lex:next()
end
local ts = terralib.newlist({lex:cur()})
lex:next()
while lex:nextif(",") do
ts:insert(lex:cur())
lex:next()
end
return function(env)
terralib.printraw(ts)
return ts
end
end;
foolist = function(self,lex)
local begin = lex:expect("{").linenumber
local r = terralib.newlist()
if not lex:matches("}") then
repeat
local t = lex:expect(lex.name)
r:insert(t.value)
lex:ref(t.value)
until not lex:nextif(",")
end
lex:expectmatch("}","{",begin)
return function(envfn)
local env = envfn()
local rr = {}
for i,k in ipairs(r) do
rr[i] = env[k]
end
return unpack(rr)
end
end;
statement = function(self,lex)
lex:expect("image")
if not lex:matches(lex.name) or not lex:lookaheadmatches(lex.number) then
lex:lookahead()
return self:expression(lex,true)
end
local name = lex:expect(lex.name).value
local v = lex:expect(lex.number).value
return function(env)
return v,v+1
end, { {name}, name.."1" }
end;
localstatement = function(self,lex)
lex:expect("image")
local n = lex:expect(lex.name).value
local v = lex:expect(lex.number).value
local v2 = lex:expect(lex.number).value
return function(env)
return v + v2
end, { n }
end
}