aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/test_lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/bisect.lua27
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/cf.lua16
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/echo.lua5
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/env.lua7
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/factorial.lua32
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fib.lua40
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fibfor.lua13
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/globals.lua13
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/hello.lua3
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/life.lua111
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/luac.lua7
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/printf.lua7
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/readonly.lua12
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sieve.lua29
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sort.lua66
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/table.lua12
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-calls.lua32
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-globals.lua38
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/undefined.lua9
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/xd.lua14
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/bisect.lua27
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/cf.lua16
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/echo.lua5
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/env.lua7
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/factorial.lua32
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua40
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fibfor.lua13
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/globals.lua13
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/hello.lua3
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/life.lua111
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/luac.lua7
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/printf.lua7
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/readonly.lua12
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sieve.lua29
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sort.lua66
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/table.lua12
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-calls.lua32
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-globals.lua38
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/xd.lua14
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/README65
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.0.txt21
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.1.txt20
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.0.txt21
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.1.txt3
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.0.txt34
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.1.txt19
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua761
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.1.lua783
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua158
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua158
50 files changed, 3020 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/bisect.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/bisect.lua
new file mode 100644
index 0000000..f91e69b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/bisect.lua
@@ -0,0 +1,27 @@
1-- bisection method for solving non-linear equations
2
3delta=1e-6 -- tolerance
4
5function bisect(f,a,b,fa,fb)
6 local c=(a+b)/2
7 io.write(n," c=",c," a=",a," b=",b,"\n")
8 if c==a or c==b or math.abs(a-b)<delta then return c,b-a end
9 n=n+1
10 local fc=f(c)
11 if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end
12end
13
14-- find root of f in the inverval [a,b]. needs f(a)*f(b)<0
15function solve(f,a,b)
16 n=0
17 local z,e=bisect(f,a,b,f(a),f(b))
18 io.write(string.format("after %d steps, root is %.17g with error %.1e, f=%.1e\n",n,z,e,f(z)))
19end
20
21-- our function
22function f(x)
23 return x*x*x-x-1
24end
25
26-- find zero in [1,2]
27solve(f,1,2)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/cf.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/cf.lua
new file mode 100644
index 0000000..8cda54b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/cf.lua
@@ -0,0 +1,16 @@
1-- temperature conversion table (celsius to farenheit)
2
3for c0=-20,50-1,10 do
4 io.write("C ")
5 for c=c0,c0+10-1 do
6 io.write(string.format("%3.0f ",c))
7 end
8 io.write("\n")
9
10 io.write("F ")
11 for c=c0,c0+10-1 do
12 f=(9/5)*c+32
13 io.write(string.format("%3.0f ",f))
14 end
15 io.write("\n\n")
16end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/echo.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/echo.lua
new file mode 100644
index 0000000..4313439
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/echo.lua
@@ -0,0 +1,5 @@
1-- echo command line arguments
2
3for i=0,table.getn(arg) do
4 print(i,arg[i])
5end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/env.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/env.lua
new file mode 100644
index 0000000..9e62a57
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/env.lua
@@ -0,0 +1,7 @@
1-- read environment variables as if they were global variables
2
3local f=function (t,i) return os.getenv(i) end
4setmetatable(getfenv(),{__index=f})
5
6-- an example
7print(a,USER,PATH)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/factorial.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/factorial.lua
new file mode 100644
index 0000000..7c4cf0f
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/factorial.lua
@@ -0,0 +1,32 @@
1-- function closures are powerful
2
3-- traditional fixed-point operator from functional programming
4Y = function (g)
5 local a = function (f) return f(f) end
6 return a(function (f)
7 return g(function (x)
8 local c=f(f)
9 return c(x)
10 end)
11 end)
12end
13
14
15-- factorial without recursion
16F = function (f)
17 return function (n)
18 if n == 0 then return 1
19 else return n*f(n-1) end
20 end
21 end
22
23factorial = Y(F) -- factorial is the fixed point of F
24
25-- now test it
26function test(x)
27 io.write(x,"! = ",factorial(x),"\n")
28end
29
30for n=0,16 do
31 test(n)
32end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fib.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fib.lua
new file mode 100644
index 0000000..97a921b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fib.lua
@@ -0,0 +1,40 @@
1-- fibonacci function with cache
2
3-- very inefficient fibonacci function
4function fib(n)
5 N=N+1
6 if n<2 then
7 return n
8 else
9 return fib(n-1)+fib(n-2)
10 end
11end
12
13-- a general-purpose value cache
14function cache(f)
15 local c={}
16 return function (x)
17 local y=c[x]
18 if not y then
19 y=f(x)
20 c[x]=y
21 end
22 return y
23 end
24end
25
26-- run and time it
27function test(s,f)
28 N=0
29 local c=os.clock()
30 local v=f(n)
31 local t=os.clock()-c
32 print(s,n,v,t,N)
33end
34
35n=arg[1] or 24 -- for other values, do lua fib.lua XX
36n=tonumber(n)
37print("","n","value","time","evals")
38test("plain",fib)
39fib=cache(fib)
40test("cached",fib)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fibfor.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fibfor.lua
new file mode 100644
index 0000000..19bb34b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/fibfor.lua
@@ -0,0 +1,13 @@
1-- example of for with generator functions
2
3function generatefib (n)
4 return coroutine.wrap(function ()
5 local a,b = 1, 1
6 while a <= n do
7 coroutine.yield(a)
8 a, b = b, a+b
9 end
10 end, n)
11end
12
13for i in generatefib(1000) do print(i) end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/globals.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/globals.lua
new file mode 100644
index 0000000..d4c20e1
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/globals.lua
@@ -0,0 +1,13 @@
1-- reads luac listings and reports global variable usage
2-- lines where a global is written to are marked with "*"
3-- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua
4
5while 1 do
6 local s=io.read()
7 if s==nil then break end
8 local ok,_,l,op,g=string.find(s,"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$")
9 if ok then
10 if op=="S" then op="*" else op="" end
11 io.write(g,"\t",l,op,"\n")
12 end
13end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/hello.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/hello.lua
new file mode 100644
index 0000000..0925498
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/hello.lua
@@ -0,0 +1,3 @@
1-- the first program in every language
2
3io.write("Hello world, from ",_VERSION,"!\n")
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/life.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/life.lua
new file mode 100644
index 0000000..911d9fe
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/life.lua
@@ -0,0 +1,111 @@
1-- life.lua
2-- original by Dave Bollinger <DBollinger@compuserve.com> posted to lua-l
3-- modified to use ANSI terminal escape sequences
4-- modified to use for instead of while
5
6local write=io.write
7
8ALIVE="¥" DEAD="þ"
9ALIVE="O" DEAD="-"
10
11function delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary
12 for i=1,10000 do end
13 -- local i=os.clock()+1 while(os.clock()<i) do end
14end
15
16function ARRAY2D(w,h)
17 local t = {w=w,h=h}
18 for y=1,h do
19 t[y] = {}
20 for x=1,w do
21 t[y][x]=0
22 end
23 end
24 return t
25end
26
27_CELLS = {}
28
29-- give birth to a "shape" within the cell array
30function _CELLS:spawn(shape,left,top)
31 for y=0,shape.h-1 do
32 for x=0,shape.w-1 do
33 self[top+y][left+x] = shape[y*shape.w+x+1]
34 end
35 end
36end
37
38-- run the CA and produce the next generation
39function _CELLS:evolve(next)
40 local ym1,y,yp1,yi=self.h-1,self.h,1,self.h
41 while yi > 0 do
42 local xm1,x,xp1,xi=self.w-1,self.w,1,self.w
43 while xi > 0 do
44 local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] +
45 self[y][xm1] + self[y][xp1] +
46 self[yp1][xm1] + self[yp1][x] + self[yp1][xp1]
47 next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0
48 xm1,x,xp1,xi = x,xp1,xp1+1,xi-1
49 end
50 ym1,y,yp1,yi = y,yp1,yp1+1,yi-1
51 end
52end
53
54-- output the array to screen
55function _CELLS:draw()
56 local out="" -- accumulate to reduce flicker
57 for y=1,self.h do
58 for x=1,self.w do
59 out=out..(((self[y][x]>0) and ALIVE) or DEAD)
60 end
61 out=out.."\n"
62 end
63 write(out)
64end
65
66-- constructor
67function CELLS(w,h)
68 local c = ARRAY2D(w,h)
69 c.spawn = _CELLS.spawn
70 c.evolve = _CELLS.evolve
71 c.draw = _CELLS.draw
72 return c
73end
74
75--
76-- shapes suitable for use with spawn() above
77--
78HEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 }
79GLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 }
80EXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 }
81FISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 }
82BUTTERFLY = { 1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1; w=5,h=5 }
83
84-- the main routine
85function LIFE(w,h)
86 -- create two arrays
87 local thisgen = CELLS(w,h)
88 local nextgen = CELLS(w,h)
89
90 -- create some life
91 -- about 1000 generations of fun, then a glider steady-state
92 thisgen:spawn(GLIDER,5,4)
93 thisgen:spawn(EXPLODE,25,10)
94 thisgen:spawn(FISH,4,12)
95
96 -- run until break
97 local gen=1
98 write("\027[2J") -- ANSI clear screen
99 while 1 do
100 thisgen:evolve(nextgen)
101 thisgen,nextgen = nextgen,thisgen
102 write("\027[H") -- ANSI home cursor
103 thisgen:draw()
104 write("Life - generation ",gen,"\n")
105 gen=gen+1
106 if gen>2000 then break end
107 --delay() -- no delay
108 end
109end
110
111LIFE(40,20)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/luac.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/luac.lua
new file mode 100644
index 0000000..b009ae9
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/luac.lua
@@ -0,0 +1,7 @@
1-- bare-bones luac in Lua
2-- usage: lua luac.lua file.lua
3
4assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
5f=assert(io.open("luac.out","wb"))
6f:write(string.dump(assert(loadfile(arg[1]))))
7io.close(f)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/printf.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/printf.lua
new file mode 100644
index 0000000..66dfda6
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/printf.lua
@@ -0,0 +1,7 @@
1-- an implementation of printf
2
3function printf(...)
4 io.write(string.format(unpack(arg)))
5end
6
7printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date())
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/readonly.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/readonly.lua
new file mode 100644
index 0000000..85c0b4e
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/readonly.lua
@@ -0,0 +1,12 @@
1-- make global variables readonly
2
3local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end
4local g={}
5local G=getfenv()
6setmetatable(g,{__index=G,__newindex=f})
7setfenv(1,g)
8
9-- an example
10rawset(g,"x",3)
11x=2
12y=1 -- cannot redefine `y'
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sieve.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sieve.lua
new file mode 100644
index 0000000..0871bb2
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sieve.lua
@@ -0,0 +1,29 @@
1-- the sieve of of Eratosthenes programmed with coroutines
2-- typical usage: lua -e N=1000 sieve.lua | column
3
4-- generate all the numbers from 2 to n
5function gen (n)
6 return coroutine.wrap(function ()
7 for i=2,n do coroutine.yield(i) end
8 end)
9end
10
11-- filter the numbers generated by `g', removing multiples of `p'
12function filter (p, g)
13 return coroutine.wrap(function ()
14 while 1 do
15 local n = g()
16 if n == nil then return end
17 if math.mod(n, p) ~= 0 then coroutine.yield(n) end
18 end
19 end)
20end
21
22N=N or 1000 -- from command line
23x = gen(N) -- generate primes up to N
24while 1 do
25 local n = x() -- pick a number until done
26 if n == nil then break end
27 print(n) -- must be a prime number
28 x = filter(n, x) -- now remove its multiples
29end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sort.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sort.lua
new file mode 100644
index 0000000..0bcb15f
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/sort.lua
@@ -0,0 +1,66 @@
1-- two implementations of a sort function
2-- this is an example only. Lua has now a built-in function "sort"
3
4-- extracted from Programming Pearls, page 110
5function qsort(x,l,u,f)
6 if l<u then
7 local m=math.random(u-(l-1))+l-1 -- choose a random pivot in range l..u
8 x[l],x[m]=x[m],x[l] -- swap pivot to first position
9 local t=x[l] -- pivot value
10 m=l
11 local i=l+1
12 while i<=u do
13 -- invariant: x[l+1..m] < t <= x[m+1..i-1]
14 if f(x[i],t) then
15 m=m+1
16 x[m],x[i]=x[i],x[m] -- swap x[i] and x[m]
17 end
18 i=i+1
19 end
20 x[l],x[m]=x[m],x[l] -- swap pivot to a valid place
21 -- x[l+1..m-1] < x[m] <= x[m+1..u]
22 qsort(x,l,m-1,f)
23 qsort(x,m+1,u,f)
24 end
25end
26
27function selectionsort(x,n,f)
28 local i=1
29 while i<=n do
30 local m,j=i,i+1
31 while j<=n do
32 if f(x[j],x[m]) then m=j end
33 j=j+1
34 end
35 x[i],x[m]=x[m],x[i] -- swap x[i] and x[m]
36 i=i+1
37 end
38end
39
40function show(m,x)
41 io.write(m,"\n\t")
42 local i=1
43 while x[i] do
44 io.write(x[i])
45 i=i+1
46 if x[i] then io.write(",") end
47 end
48 io.write("\n")
49end
50
51function testsorts(x)
52 local n=1
53 while x[n] do n=n+1 end; n=n-1 -- count elements
54 show("original",x)
55 qsort(x,1,n,function (x,y) return x<y end)
56 show("after quicksort",x)
57 selectionsort(x,n,function (x,y) return x>y end)
58 show("after reverse selection sort",x)
59 qsort(x,1,n,function (x,y) return x<y end)
60 show("after quicksort again",x)
61end
62
63-- array to be sorted
64x={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}
65
66testsorts(x)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/table.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/table.lua
new file mode 100644
index 0000000..235089c
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/table.lua
@@ -0,0 +1,12 @@
1-- make table, grouping all data for the same item
2-- input is 2 columns (item, data)
3
4local A
5while 1 do
6 local l=io.read()
7 if l==nil then break end
8 local _,_,a,b=string.find(l,'"?([_%w]+)"?%s*(.*)$')
9 if a~=A then A=a io.write("\n",a,":") end
10 io.write(" ",b)
11end
12io.write("\n")
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-calls.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-calls.lua
new file mode 100644
index 0000000..63c8b8f
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-calls.lua
@@ -0,0 +1,32 @@
1-- trace calls
2-- example: lua -ltrace-calls.lua bisect.lua
3
4local level=0
5
6function hook(event)
7 local t=debug.getinfo(3)
8 io.write(level," >>> ",string.rep(" ",level))
9 if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end
10 t=debug.getinfo(2)
11 if event=="call" then
12 level=level+1
13 else
14 level=level-1 if level<0 then level=0 end
15 end
16 if t.what=="main" then
17 if event=="call" then
18 io.write("begin ",t.short_src)
19 else
20 io.write("end ",t.short_src)
21 end
22 elseif t.what=="Lua" then
23-- table.foreach(t,print)
24 io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">")
25 else
26 io.write(event," ",t.name or "(C)"," [",t.what,"] ")
27 end
28 io.write("\n")
29end
30
31debug.sethook(hook,"cr")
32level=0
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-globals.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-globals.lua
new file mode 100644
index 0000000..295e670
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/trace-globals.lua
@@ -0,0 +1,38 @@
1-- trace assigments to global variables
2
3do
4 -- a tostring that quotes strings. note the use of the original tostring.
5 local _tostring=tostring
6 local tostring=function(a)
7 if type(a)=="string" then
8 return string.format("%q",a)
9 else
10 return _tostring(a)
11 end
12 end
13
14 local log=function (name,old,new)
15 local t=debug.getinfo(3,"Sl")
16 local line=t.currentline
17 io.write(t.short_src)
18 if line>=0 then io.write(":",line) end
19 io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n")
20 end
21
22 local g={}
23 local set=function (t,name,value)
24 log(name,g[name],value)
25 g[name]=value
26 end
27 setmetatable(getfenv(),{__index=g,__newindex=set})
28end
29
30-- an example
31
32a=1
33b=2
34a=10
35b=20
36b=nil
37b=200
38print(a,b,c)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/undefined.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/undefined.lua
new file mode 100644
index 0000000..efe5f24
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/undefined.lua
@@ -0,0 +1,9 @@
1-- catch "undefined" global variables
2
3local f=function (t,i) error("undefined global variable `"..i.."'",2) end
4setmetatable(getfenv(),{__index=f})
5
6-- an example
7a=1
8c=3
9print(a,b,c) -- `b' is undefined
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/xd.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/xd.lua
new file mode 100644
index 0000000..32331dc
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.0/xd.lua
@@ -0,0 +1,14 @@
1-- hex dump
2-- usage: lua xd.lua < file
3
4local offset=0
5
6while 1 do
7 local s=io.read(16)
8 if s==nil then return end
9 io.write(string.format("%08X ",offset))
10 string.gsub(s,"(.)",function (c) io.write(string.format("%02X ",string.byte(c))) end)
11 io.write(string.rep(" ",3*(16-string.len(s))))
12 io.write(" ",string.gsub(s,"%c","."),"\n")
13 offset=offset+16
14end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/bisect.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/bisect.lua
new file mode 100644
index 0000000..f91e69b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/bisect.lua
@@ -0,0 +1,27 @@
1-- bisection method for solving non-linear equations
2
3delta=1e-6 -- tolerance
4
5function bisect(f,a,b,fa,fb)
6 local c=(a+b)/2
7 io.write(n," c=",c," a=",a," b=",b,"\n")
8 if c==a or c==b or math.abs(a-b)<delta then return c,b-a end
9 n=n+1
10 local fc=f(c)
11 if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end
12end
13
14-- find root of f in the inverval [a,b]. needs f(a)*f(b)<0
15function solve(f,a,b)
16 n=0
17 local z,e=bisect(f,a,b,f(a),f(b))
18 io.write(string.format("after %d steps, root is %.17g with error %.1e, f=%.1e\n",n,z,e,f(z)))
19end
20
21-- our function
22function f(x)
23 return x*x*x-x-1
24end
25
26-- find zero in [1,2]
27solve(f,1,2)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/cf.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/cf.lua
new file mode 100644
index 0000000..8cda54b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/cf.lua
@@ -0,0 +1,16 @@
1-- temperature conversion table (celsius to farenheit)
2
3for c0=-20,50-1,10 do
4 io.write("C ")
5 for c=c0,c0+10-1 do
6 io.write(string.format("%3.0f ",c))
7 end
8 io.write("\n")
9
10 io.write("F ")
11 for c=c0,c0+10-1 do
12 f=(9/5)*c+32
13 io.write(string.format("%3.0f ",f))
14 end
15 io.write("\n\n")
16end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/echo.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/echo.lua
new file mode 100644
index 0000000..4313439
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/echo.lua
@@ -0,0 +1,5 @@
1-- echo command line arguments
2
3for i=0,table.getn(arg) do
4 print(i,arg[i])
5end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/env.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/env.lua
new file mode 100644
index 0000000..9e62a57
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/env.lua
@@ -0,0 +1,7 @@
1-- read environment variables as if they were global variables
2
3local f=function (t,i) return os.getenv(i) end
4setmetatable(getfenv(),{__index=f})
5
6-- an example
7print(a,USER,PATH)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/factorial.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/factorial.lua
new file mode 100644
index 0000000..7c4cf0f
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/factorial.lua
@@ -0,0 +1,32 @@
1-- function closures are powerful
2
3-- traditional fixed-point operator from functional programming
4Y = function (g)
5 local a = function (f) return f(f) end
6 return a(function (f)
7 return g(function (x)
8 local c=f(f)
9 return c(x)
10 end)
11 end)
12end
13
14
15-- factorial without recursion
16F = function (f)
17 return function (n)
18 if n == 0 then return 1
19 else return n*f(n-1) end
20 end
21 end
22
23factorial = Y(F) -- factorial is the fixed point of F
24
25-- now test it
26function test(x)
27 io.write(x,"! = ",factorial(x),"\n")
28end
29
30for n=0,16 do
31 test(n)
32end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua
new file mode 100644
index 0000000..97a921b
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua
@@ -0,0 +1,40 @@
1-- fibonacci function with cache
2
3-- very inefficient fibonacci function
4function fib(n)
5 N=N+1
6 if n<2 then
7 return n
8 else
9 return fib(n-1)+fib(n-2)
10 end
11end
12
13-- a general-purpose value cache
14function cache(f)
15 local c={}
16 return function (x)
17 local y=c[x]
18 if not y then
19 y=f(x)
20 c[x]=y
21 end
22 return y
23 end
24end
25
26-- run and time it
27function test(s,f)
28 N=0
29 local c=os.clock()
30 local v=f(n)
31 local t=os.clock()-c
32 print(s,n,v,t,N)
33end
34
35n=arg[1] or 24 -- for other values, do lua fib.lua XX
36n=tonumber(n)
37print("","n","value","time","evals")
38test("plain",fib)
39fib=cache(fib)
40test("cached",fib)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fibfor.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fibfor.lua
new file mode 100644
index 0000000..8bbba39
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fibfor.lua
@@ -0,0 +1,13 @@
1-- example of for with generator functions
2
3function generatefib (n)
4 return coroutine.wrap(function ()
5 local a,b = 1, 1
6 while a <= n do
7 coroutine.yield(a)
8 a, b = b, a+b
9 end
10 end)
11end
12
13for i in generatefib(1000) do print(i) end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/globals.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/globals.lua
new file mode 100644
index 0000000..d4c20e1
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/globals.lua
@@ -0,0 +1,13 @@
1-- reads luac listings and reports global variable usage
2-- lines where a global is written to are marked with "*"
3-- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua
4
5while 1 do
6 local s=io.read()
7 if s==nil then break end
8 local ok,_,l,op,g=string.find(s,"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$")
9 if ok then
10 if op=="S" then op="*" else op="" end
11 io.write(g,"\t",l,op,"\n")
12 end
13end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/hello.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/hello.lua
new file mode 100644
index 0000000..0925498
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/hello.lua
@@ -0,0 +1,3 @@
1-- the first program in every language
2
3io.write("Hello world, from ",_VERSION,"!\n")
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/life.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/life.lua
new file mode 100644
index 0000000..911d9fe
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/life.lua
@@ -0,0 +1,111 @@
1-- life.lua
2-- original by Dave Bollinger <DBollinger@compuserve.com> posted to lua-l
3-- modified to use ANSI terminal escape sequences
4-- modified to use for instead of while
5
6local write=io.write
7
8ALIVE="¥" DEAD="þ"
9ALIVE="O" DEAD="-"
10
11function delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary
12 for i=1,10000 do end
13 -- local i=os.clock()+1 while(os.clock()<i) do end
14end
15
16function ARRAY2D(w,h)
17 local t = {w=w,h=h}
18 for y=1,h do
19 t[y] = {}
20 for x=1,w do
21 t[y][x]=0
22 end
23 end
24 return t
25end
26
27_CELLS = {}
28
29-- give birth to a "shape" within the cell array
30function _CELLS:spawn(shape,left,top)
31 for y=0,shape.h-1 do
32 for x=0,shape.w-1 do
33 self[top+y][left+x] = shape[y*shape.w+x+1]
34 end
35 end
36end
37
38-- run the CA and produce the next generation
39function _CELLS:evolve(next)
40 local ym1,y,yp1,yi=self.h-1,self.h,1,self.h
41 while yi > 0 do
42 local xm1,x,xp1,xi=self.w-1,self.w,1,self.w
43 while xi > 0 do
44 local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] +
45 self[y][xm1] + self[y][xp1] +
46 self[yp1][xm1] + self[yp1][x] + self[yp1][xp1]
47 next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0
48 xm1,x,xp1,xi = x,xp1,xp1+1,xi-1
49 end
50 ym1,y,yp1,yi = y,yp1,yp1+1,yi-1
51 end
52end
53
54-- output the array to screen
55function _CELLS:draw()
56 local out="" -- accumulate to reduce flicker
57 for y=1,self.h do
58 for x=1,self.w do
59 out=out..(((self[y][x]>0) and ALIVE) or DEAD)
60 end
61 out=out.."\n"
62 end
63 write(out)
64end
65
66-- constructor
67function CELLS(w,h)
68 local c = ARRAY2D(w,h)
69 c.spawn = _CELLS.spawn
70 c.evolve = _CELLS.evolve
71 c.draw = _CELLS.draw
72 return c
73end
74
75--
76-- shapes suitable for use with spawn() above
77--
78HEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 }
79GLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 }
80EXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 }
81FISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 }
82BUTTERFLY = { 1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1; w=5,h=5 }
83
84-- the main routine
85function LIFE(w,h)
86 -- create two arrays
87 local thisgen = CELLS(w,h)
88 local nextgen = CELLS(w,h)
89
90 -- create some life
91 -- about 1000 generations of fun, then a glider steady-state
92 thisgen:spawn(GLIDER,5,4)
93 thisgen:spawn(EXPLODE,25,10)
94 thisgen:spawn(FISH,4,12)
95
96 -- run until break
97 local gen=1
98 write("\027[2J") -- ANSI clear screen
99 while 1 do
100 thisgen:evolve(nextgen)
101 thisgen,nextgen = nextgen,thisgen
102 write("\027[H") -- ANSI home cursor
103 thisgen:draw()
104 write("Life - generation ",gen,"\n")
105 gen=gen+1
106 if gen>2000 then break end
107 --delay() -- no delay
108 end
109end
110
111LIFE(40,20)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/luac.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/luac.lua
new file mode 100644
index 0000000..96a0a97
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/luac.lua
@@ -0,0 +1,7 @@
1-- bare-bones luac in Lua
2-- usage: lua luac.lua file.lua
3
4assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
5f=assert(io.open("luac.out","wb"))
6assert(f:write(string.dump(assert(loadfile(arg[1])))))
7assert(f:close())
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/printf.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/printf.lua
new file mode 100644
index 0000000..58c63ff
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/printf.lua
@@ -0,0 +1,7 @@
1-- an implementation of printf
2
3function printf(...)
4 io.write(string.format(...))
5end
6
7printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date())
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/readonly.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/readonly.lua
new file mode 100644
index 0000000..85c0b4e
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/readonly.lua
@@ -0,0 +1,12 @@
1-- make global variables readonly
2
3local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end
4local g={}
5local G=getfenv()
6setmetatable(g,{__index=G,__newindex=f})
7setfenv(1,g)
8
9-- an example
10rawset(g,"x",3)
11x=2
12y=1 -- cannot redefine `y'
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sieve.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sieve.lua
new file mode 100644
index 0000000..0871bb2
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sieve.lua
@@ -0,0 +1,29 @@
1-- the sieve of of Eratosthenes programmed with coroutines
2-- typical usage: lua -e N=1000 sieve.lua | column
3
4-- generate all the numbers from 2 to n
5function gen (n)
6 return coroutine.wrap(function ()
7 for i=2,n do coroutine.yield(i) end
8 end)
9end
10
11-- filter the numbers generated by `g', removing multiples of `p'
12function filter (p, g)
13 return coroutine.wrap(function ()
14 while 1 do
15 local n = g()
16 if n == nil then return end
17 if math.mod(n, p) ~= 0 then coroutine.yield(n) end
18 end
19 end)
20end
21
22N=N or 1000 -- from command line
23x = gen(N) -- generate primes up to N
24while 1 do
25 local n = x() -- pick a number until done
26 if n == nil then break end
27 print(n) -- must be a prime number
28 x = filter(n, x) -- now remove its multiples
29end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sort.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sort.lua
new file mode 100644
index 0000000..0bcb15f
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/sort.lua
@@ -0,0 +1,66 @@
1-- two implementations of a sort function
2-- this is an example only. Lua has now a built-in function "sort"
3
4-- extracted from Programming Pearls, page 110
5function qsort(x,l,u,f)
6 if l<u then
7 local m=math.random(u-(l-1))+l-1 -- choose a random pivot in range l..u
8 x[l],x[m]=x[m],x[l] -- swap pivot to first position
9 local t=x[l] -- pivot value
10 m=l
11 local i=l+1
12 while i<=u do
13 -- invariant: x[l+1..m] < t <= x[m+1..i-1]
14 if f(x[i],t) then
15 m=m+1
16 x[m],x[i]=x[i],x[m] -- swap x[i] and x[m]
17 end
18 i=i+1
19 end
20 x[l],x[m]=x[m],x[l] -- swap pivot to a valid place
21 -- x[l+1..m-1] < x[m] <= x[m+1..u]
22 qsort(x,l,m-1,f)
23 qsort(x,m+1,u,f)
24 end
25end
26
27function selectionsort(x,n,f)
28 local i=1
29 while i<=n do
30 local m,j=i,i+1
31 while j<=n do
32 if f(x[j],x[m]) then m=j end
33 j=j+1
34 end
35 x[i],x[m]=x[m],x[i] -- swap x[i] and x[m]
36 i=i+1
37 end
38end
39
40function show(m,x)
41 io.write(m,"\n\t")
42 local i=1
43 while x[i] do
44 io.write(x[i])
45 i=i+1
46 if x[i] then io.write(",") end
47 end
48 io.write("\n")
49end
50
51function testsorts(x)
52 local n=1
53 while x[n] do n=n+1 end; n=n-1 -- count elements
54 show("original",x)
55 qsort(x,1,n,function (x,y) return x<y end)
56 show("after quicksort",x)
57 selectionsort(x,n,function (x,y) return x>y end)
58 show("after reverse selection sort",x)
59 qsort(x,1,n,function (x,y) return x<y end)
60 show("after quicksort again",x)
61end
62
63-- array to be sorted
64x={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}
65
66testsorts(x)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/table.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/table.lua
new file mode 100644
index 0000000..235089c
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/table.lua
@@ -0,0 +1,12 @@
1-- make table, grouping all data for the same item
2-- input is 2 columns (item, data)
3
4local A
5while 1 do
6 local l=io.read()
7 if l==nil then break end
8 local _,_,a,b=string.find(l,'"?([_%w]+)"?%s*(.*)$')
9 if a~=A then A=a io.write("\n",a,":") end
10 io.write(" ",b)
11end
12io.write("\n")
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-calls.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-calls.lua
new file mode 100644
index 0000000..6d7a7b3
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-calls.lua
@@ -0,0 +1,32 @@
1-- trace calls
2-- example: lua -ltrace-calls bisect.lua
3
4local level=0
5
6local function hook(event)
7 local t=debug.getinfo(3)
8 io.write(level," >>> ",string.rep(" ",level))
9 if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end
10 t=debug.getinfo(2)
11 if event=="call" then
12 level=level+1
13 else
14 level=level-1 if level<0 then level=0 end
15 end
16 if t.what=="main" then
17 if event=="call" then
18 io.write("begin ",t.short_src)
19 else
20 io.write("end ",t.short_src)
21 end
22 elseif t.what=="Lua" then
23-- table.foreach(t,print)
24 io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">")
25 else
26 io.write(event," ",t.name or "(C)"," [",t.what,"] ")
27 end
28 io.write("\n")
29end
30
31debug.sethook(hook,"cr")
32level=0
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-globals.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-globals.lua
new file mode 100644
index 0000000..295e670
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/trace-globals.lua
@@ -0,0 +1,38 @@
1-- trace assigments to global variables
2
3do
4 -- a tostring that quotes strings. note the use of the original tostring.
5 local _tostring=tostring
6 local tostring=function(a)
7 if type(a)=="string" then
8 return string.format("%q",a)
9 else
10 return _tostring(a)
11 end
12 end
13
14 local log=function (name,old,new)
15 local t=debug.getinfo(3,"Sl")
16 local line=t.currentline
17 io.write(t.short_src)
18 if line>=0 then io.write(":",line) end
19 io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n")
20 end
21
22 local g={}
23 local set=function (t,name,value)
24 log(name,g[name],value)
25 g[name]=value
26 end
27 setmetatable(getfenv(),{__index=g,__newindex=set})
28end
29
30-- an example
31
32a=1
33b=2
34a=10
35b=20
36b=nil
37b=200
38print(a,b,c)
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/xd.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/xd.lua
new file mode 100644
index 0000000..ebc3eff
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/xd.lua
@@ -0,0 +1,14 @@
1-- hex dump
2-- usage: lua xd.lua < file
3
4local offset=0
5while true do
6 local s=io.read(16)
7 if s==nil then return end
8 io.write(string.format("%08X ",offset))
9 string.gsub(s,"(.)",
10 function (c) io.write(string.format("%02X ",string.byte(c))) end)
11 io.write(string.rep(" ",3*(16-string.len(s))))
12 io.write(" ",string.gsub(s,"%c","."),"\n")
13 offset=offset+16
14end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/README b/LuaSL/testLua/yueliang-0.4.1/test_lua/README
new file mode 100644
index 0000000..07d9eb2
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/README
@@ -0,0 +1,65 @@
1test_scripts-5.*.lua
2----------------------
3
4The scripts test_scripts*.lua are for exercising the frontends. Such
5testing is non-exhaustive, but useful all the same.
6
7The files in the 5.0 directory are the sample scripts from the Lua 5.0.x
8test directory. Ditto for the 5.1 directory. See the COPYRIGHT_Lua5 for
9the copyright notice.
10
11For example, to run the 5.0.x script tester:
12
13 >lua test_scripts-5.0.lua
14
15Or, if you have both Lua 5.0.x and Lua 5.1.x, you can prepare two
16binaries and run them like this:
17
18 >lua5.0 test_scripts-5.0.lua
19 >lua5.1 test_scripts-5.1.lua
20
21If the compilation result is exact, "CORRECT" is printed, otherwise both
22binary chunks are written to the current directory as bc1.out and
23bc2.out. You can use a disassembly tool like ChunkSpy to generate
24listings for both files, then they can be compared with a visual diff
25tool. ChunkSpy 0.9.8 supports 5.0.x and 5.1.x.
26
27For testing additional files, add the argument "ALL" like this:
28
29 >lua test_scripts-5.0.lua ALL
30
31This will pull in additional personal script files for testing. But in
32order to do so, you'd have to adjust the files files-other-*.txt.
33
34Current status:
35
36Frontend version File set Result
37---------------------------------------------------------------------
38Yueliang 5.0.3 files-lua-5.0.txt ALL CORRECT
39 files-yueliang-5.0.txt ALL CORRECT
40Yueliang 5.1.2 files-lua-5.1.txt ALL CORRECT
41 files-yueliang-5.1.txt ALL CORRECT
42---------------------------------------------------------------------
43
44test_parser-5.x.lua
45-------------------
46
47The script files test_parser-5.0.lua and test_parser-5.1.lua contains
48many test cases for both parsers. There are a lot of failure cases as
49well as pass cases in order to exercise the parsers well, though the
50test list is not exhaustive.
51
52 test_parser-5.0.lua 503 test cases
53 test_parser-5.1.lua 524 test cases
54
55For the actual test scripts, see test_lparser2.lua in the respective
56test directories of each front end. The 5.0.x front end of Yueliang
57passed all the tests in test_parser-5.0.lua without any failures, while
58testing of the 5.1.x front end using test_parser-5.1.lua led to one
59bug found and fixed.
60
61For Lua 5.0.2, see Yueliang 0.1.3, which was the last release of Lua
625.0.2 material.
63
64For Lua 5.1.1, see Yueliang 0.2.1, which was the last release of Lua
655.1.1 material.
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.0.txt b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.0.txt
new file mode 100644
index 0000000..d6b0c3c
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.0.txt
@@ -0,0 +1,21 @@
1# these are the sample scripts found in Lua 5.0.x
25.0/bisect.lua
35.0/cf.lua
45.0/echo.lua
55.0/env.lua
65.0/factorial.lua
75.0/fib.lua
85.0/fibfor.lua
95.0/globals.lua
105.0/hello.lua
115.0/life.lua
125.0/luac.lua
135.0/printf.lua
145.0/readonly.lua
155.0/sieve.lua
165.0/sort.lua
175.0/table.lua
185.0/trace-calls.lua
195.0/trace-globals.lua
205.0/undefined.lua
215.0/xd.lua
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.1.txt b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.1.txt
new file mode 100644
index 0000000..a11d670
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-lua-5.1.txt
@@ -0,0 +1,20 @@
1# these are the sample scripts found in Lua 5.1.x
25.1/bisect.lua
35.1/cf.lua
45.1/echo.lua
55.1/env.lua
65.1/factorial.lua
75.1/fib.lua
85.1/fibfor.lua
95.1/globals.lua
105.1/hello.lua
115.1/life.lua
125.1/luac.lua
135.1/printf.lua
145.1/readonly.lua
155.1/sieve.lua
165.1/sort.lua
175.1/table.lua
185.1/trace-calls.lua
195.1/trace-globals.lua
205.1/xd.lua
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.0.txt b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.0.txt
new file mode 100644
index 0000000..a661bc5
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.0.txt
@@ -0,0 +1,21 @@
1# these are other 5.0.x scripts found in my project directories
2# WARNING currently out of date...
3
4../../SciTELuaExporters/SciTE_ExportBase.lua
5../../SciTELuaExporters/SciTE_ExporterABW.lua
6../../SciTELuaExporters/SciTE_ExporterHTML.lua
7../../SciTELuaExporters/SciTE_ExporterHTMLPlus.lua
8../../SciTELuaExporters/SciTE_ExporterODT.lua
9../../SciTELuaExporters/SciTE_ExporterPDF.lua
10../../SciTELuaExporters/SciTE_ExporterPDFPlus.lua
11../../SciTELuaExporters/SciTE_ExporterRTF.lua
12../../SciTELuaExporters/SciTE_ExporterSXW.lua
13../../SciTELuaExporters/SciTE_ExporterTeX.lua
14../../SciTELuaExporters/SciTE_ExporterTemplate.lua
15../../SciTELuaExporters/SciTE_ExporterXML.lua
16../../LuaSrcDiet/LuaSrcDiet.lua
17../../LuaSrcDiet/LuaSrcDiet_.lua
18../../ChunkBake/ChunkBake.lua
19../../ChunkBake/misc/TestRig.lua
20../../ChunkSpy/5.0.2/ChunkSpy.lua
21../../ChunkSpy/5.1-work4/ChunkSpy.lua
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.1.txt b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.1.txt
new file mode 100644
index 0000000..fa5827d
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-other-5.1.txt
@@ -0,0 +1,3 @@
1# these are other 5.1.x scripts found in my project directories
2# WARNING currently out of date...
3
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.0.txt b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.0.txt
new file mode 100644
index 0000000..72e1da9
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.0.txt
@@ -0,0 +1,34 @@
1# these are yueliang files for 5.0.x
2
3test_scripts-5.0.lua
4
5../orig-5.0.3/lzio.lua
6../orig-5.0.3/ldump.lua
7../orig-5.0.3/lopcodes.lua
8../orig-5.0.3/llex.lua
9../orig-5.0.3/lparser.lua
10../orig-5.0.3/lcode.lua
11../orig-5.0.3/luac.lua
12
13../orig-5.0.3/test/test_lzio.lua
14../orig-5.0.3/test/test_ldump.lua
15../orig-5.0.3/test/test_llex.lua
16../orig-5.0.3/test/test_lparser.lua
17../orig-5.0.3/test/test_number.lua
18../orig-5.0.3/test/bench_llex.lua
19../orig-5.0.3/tools/call_graph.lua
20../orig-5.0.3/tools/sample_expr.lua
21
22../nat-5.0.3/lzio_mk2.lua
23../nat-5.0.3/lzio_mk4.lua
24../nat-5.0.3/llex_mk2.lua
25../nat-5.0.3/llex_mk3.lua
26../nat-5.0.3/llex_mk4.lua
27
28../nat-5.0.3/test/test_lzio_mk2.lua
29../nat-5.0.3/test/test_llex_mk2.lua
30../nat-5.0.3/test/test_llex_mk3.lua
31../nat-5.0.3/test/test_llex_mk4.lua
32../nat-5.0.3/test/bench_llex_mk2.lua
33../nat-5.0.3/test/bench_llex_mk3.lua
34../nat-5.0.3/test/bench_llex_mk4.lua
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.1.txt b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.1.txt
new file mode 100644
index 0000000..6a112d9
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/files-yueliang-5.1.txt
@@ -0,0 +1,19 @@
1# these are yueliang files for 5.1.x
2
3test_scripts-5.1.lua
4
5../orig-5.1.3/lzio.lua
6../orig-5.1.3/ldump.lua
7../orig-5.1.3/lopcodes.lua
8../orig-5.1.3/llex.lua
9../orig-5.1.3/lparser.lua
10../orig-5.1.3/lcode.lua
11../orig-5.1.3/luac.lua
12
13../orig-5.1.3/test/test_lzio.lua
14../orig-5.1.3/test/test_ldump.lua
15../orig-5.1.3/test/test_llex.lua
16../orig-5.1.3/test/test_lparser.lua
17../orig-5.1.3/test/test_number.lua
18../orig-5.1.3/test/bench_llex.lua
19
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua
new file mode 100644
index 0000000..b563ed3
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.0.lua
@@ -0,0 +1,761 @@
1--[[--------------------------------------------------------------------
2
3 test_parser-5.0.lua
4 Lua 5.0.x parser test cases
5 This file is part of Yueliang.
6
7 Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15--[[--------------------------------------------------------------------
16-- Notes:
17-- * there is no intention of properly specifying a grammar; the notes
18-- are meant to reflect the structure of lparser so that it is easy
19-- to locate and modify lparser if so desired
20-- * some test may have invalid expressions but will compile, this
21-- is because the chunk hasn't been executed yet
22----------------------------------------------------------------------]]
23
24--[[--------------------------------------------------------------------
25-- lparser parsing structure, the Lua 5.0.x version...
26----------------------------------------------------------------------]]
27 --------------------------------------------------------------------
28 -- chunk -> { stat [';'] }
29 --------------------------------------------------------------------
30 -- stat -> DO block END
31 -- block -> chunk
32 --------------------------------------------------------------------
33 -- stat -> breakstat
34 -- breakstat -> BREAK
35 -- * must have a loop to break
36 -- * must be last statement in a block
37 --------------------------------------------------------------------
38 -- stat -> retstat
39 -- retstat -> RETURN explist
40 -- * must be last statement in a block
41 --------------------------------------------------------------------
42 -- stat -> exprstat
43 -- exprstat -> primaryexp
44 -- (-> func | assignment)
45 -- * if LHS is VCALL then func, otherwise assignment
46 -- * for func, LHS is VCALL if funcargs in expression
47 --------------------------------------------------------------------
48 -- stat -> funcstat
49 -- funcstat -> FUNCTION funcname body
50 -- funcname -> NAME {'.' NAME} [':' NAME]
51 --------------------------------------------------------------------
52 -- body -> '(' parlist ')' chunk END
53 -- parlist -> [ param { ',' param } ]
54 -- param -> NAME
55 -- * DOTS must be the last parameter in a parlist
56 --------------------------------------------------------------------
57 -- stat -> LOCAL localstat
58 -- LOCAL localstat -> LOCAL NAME {',' NAME} ['=' explist1]
59 -- explist1 -> expr { ',' expr }
60 --------------------------------------------------------------------
61 -- stat -> LOCAL FUNCTION localfunc
62 -- LOCAL FUNCTION localfunc -> LOCAL FUNCTION NAME body
63 --------------------------------------------------------------------
64 -- stat -> ifstat
65 -- ifstat -> IF cond THEN block
66 -- {ELSEIF cond THEN block}
67 -- [ELSE block] END
68 -- block -> chunk
69 -- cond -> expr
70 --------------------------------------------------------------------
71 -- stat -> forstat
72 -- forstat -> fornum | forlist
73 -- forlist -> NAME {,NAME} IN explist1 forbody END
74 -- fornum -> NAME = exp1,exp1[,exp1] forbody END
75 -- forbody -> DO block
76 -- block -> chunk
77 --------------------------------------------------------------------
78 -- stat -> whilestat
79 -- whilestat -> WHILE cond DO block END
80 -- block -> chunk
81 -- cond -> expr
82 --------------------------------------------------------------------
83 -- stat -> repeatstat
84 -- repeatstat -> REPEAT block UNTIL cond
85 -- block -> chunk
86 -- cond -> expr
87 --------------------------------------------------------------------
88 -- assignment -> ',' primaryexp assignment
89 -- | '=' explist1
90 -- explist1 -> expr { ',' expr }
91 -- * for assignment, LHS must be LOCAL, UPVAL, GLOBAL or INDEXED
92 --------------------------------------------------------------------
93 -- primaryexp -> prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
94 -- prefixexp -> NAME | '(' expr ')'
95 -- funcargs -> '(' [ explist1 ] ')' | constructor | STRING
96 -- * funcargs turn an expr into a function call
97 --------------------------------------------------------------------
98 -- expr -> subexpr
99 -- subexpr -> (UNOPR subexpr | simpleexp) { BINOPR subexpr }
100 -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE
101 -- | constructor | FUNCTION body | primaryexp
102 --------------------------------------------------------------------
103 -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}'
104 -- fieldsep -> ',' | ';'
105 -- field -> recfield | listfield
106 -- recfield -> ( NAME | '[' exp1 ']' ) = exp1
107 -- listfield -> expr
108 --------------------------------------------------------------------
109
110--[[--------------------------------------------------------------------
111-- parser test cases, Lua 5.0.x
112-- * uncomment string delimiter to enable syntax highlighting...
113-- * anything that matches "^%s*%-%-" is a comment
114-- * headings to display are "^%s*TESTS:%s*(.*)$"
115-- * FAIL test cases should match "%s*%-%-%s*FAIL%s*$"
116----------------------------------------------------------------------]]
117tests_source = [[
118 --------------------------------------------------------------------
119 TESTS: empty chunks
120 --------------------------------------------------------------------
121 -- chunk -> { stat [';'] }
122 --------------------------------------------------------------------
123
124; -- FAIL
125 --------------------------------------------------------------------
126 TESTS: optional semicolon, simple local statements
127 --------------------------------------------------------------------
128 -- stat -> LOCAL localstat
129 -- LOCAL localstat -> LOCAL NAME {',' NAME} ['=' explist1]
130 -- explist1 -> expr { ',' expr }
131 --------------------------------------------------------------------
132local -- FAIL
133local; -- FAIL
134local = -- FAIL
135local end -- FAIL
136local a
137local a;
138local a, b, c
139local a; local b local c;
140local a = 1
141local a local b = a
142local a, b = 1, 2
143local a, b, c = 1, 2, 3
144local a, b, c = 1
145local a = 1, 2, 3
146local a, local -- FAIL
147local 1 -- FAIL
148local "foo" -- FAIL
149local a = local -- FAIL
150local a, b, = -- FAIL
151local a, b = 1, local -- FAIL
152local a, b = , local -- FAIL
153 --------------------------------------------------------------------
154 TESTS: simple DO blocks
155 --------------------------------------------------------------------
156 -- stat -> DO block END
157 -- block -> chunk
158 --------------------------------------------------------------------
159do -- FAIL
160end -- FAIL
161do end
162do ; end -- FAIL
163do 1 end -- FAIL
164do "foo" end -- FAIL
165do local a, b end
166do local a local b end
167do local a; local b; end
168do local a = 1 end
169do do end end
170do do end; end
171do do do end end end
172do do do end; end; end
173do do do return end end end
174do end do -- FAIL
175do end end -- FAIL
176do return end
177do return return end -- FAIL
178do break end -- FAIL
179 --------------------------------------------------------------------
180 TESTS: simple WHILE loops
181 --------------------------------------------------------------------
182 -- stat -> whilestat
183 -- whilestat -> WHILE cond DO block END
184 -- block -> chunk
185 -- cond -> expr
186 --------------------------------------------------------------------
187while -- FAIL
188while do -- FAIL
189while = -- FAIL
190while 1 do -- FAIL
191while 1 do end
192while 1 do local a end
193while 1 do local a local b end
194while 1 do local a; local b; end
195while 1 do 2 end -- FAIL
196while 1 do "foo" end -- FAIL
197while true do end
198while 1 do ; end -- FAIL
199while 1 do while -- FAIL
200while 1 end -- FAIL
201while 1 2 do -- FAIL
202while 1 = 2 do -- FAIL
203while 1 do return end
204while 1 do return return end -- FAIL
205while 1 do do end end
206while 1 do do return end end
207while 1 do break end
208while 1 do break break end -- FAIL
209while 1 do do break end end
210 --------------------------------------------------------------------
211 TESTS: simple REPEAT loops
212 --------------------------------------------------------------------
213 -- stat -> repeatstat
214 -- repeatstat -> REPEAT block UNTIL cond
215 -- block -> chunk
216 -- cond -> expr
217 --------------------------------------------------------------------
218repeat -- FAIL
219repeat until -- FAIL
220repeat until 0
221repeat until false
222repeat until local -- FAIL
223repeat end -- FAIL
224repeat 1 -- FAIL
225repeat = -- FAIL
226repeat local a until 1
227repeat local a local b until 0
228repeat local a; local b; until 0
229repeat ; until 1 -- FAIL
230repeat 2 until 1 -- FAIL
231repeat "foo" until 1 -- FAIL
232repeat return until 0
233repeat return return until 0 -- FAIL
234repeat break until 0
235repeat break break until 0 -- FAIL
236repeat do end until 0
237repeat do return end until 0
238repeat do break end until 0
239 --------------------------------------------------------------------
240 TESTS: simple FOR loops
241 --------------------------------------------------------------------
242 -- stat -> forstat
243 -- forstat -> fornum | forlist
244 -- forlist -> NAME {,NAME} IN explist1 forbody END
245 -- fornum -> NAME = exp1,exp1[,exp1] forbody END
246 -- forbody -> DO block
247 -- block -> chunk
248 --------------------------------------------------------------------
249for -- FAIL
250for do -- FAIL
251for end -- FAIL
252for 1 -- FAIL
253for a -- FAIL
254for true -- FAIL
255for a, in -- FAIL
256for a in -- FAIL
257for a do -- FAIL
258for a in do -- FAIL
259for a in b do -- FAIL
260for a in b end -- FAIL
261for a in b, do -- FAIL
262for a in b do end
263for a in b do local a local b end
264for a in b do local a; local b; end
265for a in b do 1 end -- FAIL
266for a in b do "foo" end -- FAIL
267for a b in -- FAIL
268for a, b, c in p do end
269for a, b, c in p, q, r do end
270for a in 1 do end
271for a in true do end
272for a in "foo" do end
273for a in b do break end
274for a in b do break break end -- FAIL
275for a in b do return end
276for a in b do return return end -- FAIL
277for a in b do do end end
278for a in b do do break end end
279for a in b do do return end end
280for = -- FAIL
281for a = -- FAIL
282for a, b = -- FAIL
283for a = do -- FAIL
284for a = 1, do -- FAIL
285for a = p, q, do -- FAIL
286for a = p q do -- FAIL
287for a = b do end -- FAIL
288for a = 1, 2, 3, 4 do end -- FAIL
289for a = p, q do end
290for a = 1, 2 do end
291for a = 1, 2 do local a local b end
292for a = 1, 2 do local a; local b; end
293for a = 1, 2 do 3 end -- FAIL
294for a = 1, 2 do "foo" end -- FAIL
295for a = p, q, r do end
296for a = 1, 2, 3 do end
297for a = p, q do break end
298for a = p, q do break break end -- FAIL
299for a = 1, 2 do return end
300for a = 1, 2 do return return end -- FAIL
301for a = p, q do do end end
302for a = p, q do do break end end
303for a = p, q do do return end end
304 --------------------------------------------------------------------
305 TESTS: break statement
306 --------------------------------------------------------------------
307 -- stat -> breakstat
308 -- breakstat -> BREAK
309 -- * must have a loop to break
310 -- * must be last statement in a block
311 --------------------------------------------------------------------
312break -- FAIL
313 --------------------------------------------------------------------
314 TESTS: return statement
315 --------------------------------------------------------------------
316 -- stat -> retstat
317 -- retstat -> RETURN explist
318 -- * must be last statement in a block
319 --------------------------------------------------------------------
320return
321return;
322return return -- FAIL
323return 1
324return local -- FAIL
325return "foo"
326return 1, -- FAIL
327return 1,2,3
328return a,b,c,d
329return 1,2;
330 --------------------------------------------------------------------
331 TESTS: conditional statements
332 --------------------------------------------------------------------
333 -- stat -> ifstat
334 -- ifstat -> IF cond THEN block
335 -- {ELSEIF cond THEN block}
336 -- [ELSE block] END
337 -- block -> chunk
338 -- cond -> expr
339 --------------------------------------------------------------------
340if -- FAIL
341elseif -- FAIL
342else -- FAIL
343then -- FAIL
344if then -- FAIL
345if 1 -- FAIL
346if 1 then -- FAIL
347if 1 else -- FAIL
348if 1 then else -- FAIL
349if 1 then elseif -- FAIL
350if 1 then end
351if 1 then local a end
352if 1 then local a local b end
353if 1 then local a; local b; end
354if 1 then else end
355if 1 then local a else local b end
356if 1 then local a; else local b; end
357if 1 then elseif 2 -- FAIL
358if 1 then elseif 2 then -- FAIL
359if 1 then elseif 2 then end
360if 1 then local a elseif 2 then local b end
361if 1 then local a; elseif 2 then local b; end
362if 1 then elseif 2 then else end
363if 1 then else if 2 then end end
364if 1 then else if 2 then end -- FAIL
365if 1 then break end -- FAIL
366if 1 then return end
367if 1 then return return end -- FAIL
368if 1 then end; if 1 then end;
369 --------------------------------------------------------------------
370 TESTS: function statements
371 --------------------------------------------------------------------
372 -- stat -> funcstat
373 -- funcstat -> FUNCTION funcname body
374 -- funcname -> NAME {'.' NAME} [':' NAME]
375 --------------------------------------------------------------------
376 -- body -> '(' parlist ')' chunk END
377 -- parlist -> [ param { ',' param } ]
378 -- param -> NAME
379 -- * DOTS must be the last parameter in a parlist
380 --------------------------------------------------------------------
381function -- FAIL
382function 1 -- FAIL
383function end -- FAIL
384function a -- FAIL
385function a end -- FAIL
386function a( end -- FAIL
387function a() end
388function a(1 -- FAIL
389function a("foo" -- FAIL
390function a(p -- FAIL
391function a(p,) -- FAIL
392function a(p q -- FAIL
393function a(p) end
394function a(p,q,) end -- FAIL
395function a(p,q,r) end
396function a(p,q,1 -- FAIL
397function a(p) do -- FAIL
398function a(p) 1 end -- FAIL
399function a(p) return end
400function a(p) break end -- FAIL
401function a(p) return return end -- FAIL
402function a(p) do end end
403function a.( -- FAIL
404function a.1 -- FAIL
405function a.b() end
406function a.b, -- FAIL
407function a.b.( -- FAIL
408function a.b.c.d() end
409function a: -- FAIL
410function a:1 -- FAIL
411function a:b() end
412function a:b: -- FAIL
413function a:b. -- FAIL
414function a.b.c:d() end
415function a(...) end
416function a(..., -- FAIL
417function a(p,...) end
418function a(p,q,r,...) end
419function a() local a local b end
420function a() local a; local b; end
421function a() end; function a() end;
422 --------------------------------------------------------------------
423 TESTS: local function statements
424 --------------------------------------------------------------------
425 -- stat -> LOCAL FUNCTION localfunc
426 -- LOCAL FUNCTION localfunc -> LOCAL FUNCTION NAME body
427 --------------------------------------------------------------------
428local function -- FAIL
429local function 1 -- FAIL
430local function end -- FAIL
431local function a -- FAIL
432local function a end -- FAIL
433local function a( end -- FAIL
434local function a() end
435local function a(1 -- FAIL
436local function a("foo" -- FAIL
437local function a(p -- FAIL
438local function a(p,) -- FAIL
439local function a(p q -- FAIL
440local function a(p) end
441local function a(p,q,) end -- FAIL
442local function a(p,q,r) end
443local function a(p,q,1 -- FAIL
444local function a(p) do -- FAIL
445local function a(p) 1 end -- FAIL
446local function a(p) return end
447local function a(p) break end -- FAIL
448local function a(p) return return end -- FAIL
449local function a(p) do end end
450local function a. -- FAIL
451local function a: -- FAIL
452local function a(...) end
453local function a(..., -- FAIL
454local function a(p,...) end
455local function a(p,q,r,...) end
456local function a() local a local b end
457local function a() local a; local b; end
458local function a() end; local function a() end;
459 --------------------------------------------------------------------
460 -- stat -> exprstat
461 -- exprstat -> primaryexp
462 -- (-> func | assignment)
463 -- * if LHS is VCALL then func, otherwise assignment
464 -- * for func, LHS is VCALL if funcargs in expression
465 --------------------------------------------------------------------
466 TESTS: assignments
467 --------------------------------------------------------------------
468 -- assignment -> ',' primaryexp assignment
469 -- | '=' explist1
470 -- explist1 -> expr { ',' expr }
471 -- * for assignment, LHS must be LOCAL, UPVAL, GLOBAL or INDEXED
472 --------------------------------------------------------------------
473a -- FAIL
474a, -- FAIL
475a,b,c -- FAIL
476a,b = -- FAIL
477a = 1
478a = 1,2,3
479a,b,c = 1
480a,b,c = 1,2,3
481a.b = 1
482a.b.c = 1
483a[b] = 1
484a[b][c] = 1
485a.b[c] = 1
486a[b].c = 1
4870 = -- FAIL
488"foo" = -- FAIL
489true = -- FAIL
490(a) = -- FAIL
491{} = -- FAIL
492a:b() = -- FAIL
493a() = -- FAIL
494a.b:c() = -- FAIL
495a[b]() = -- FAIL
496a = a b -- FAIL
497a = 1 2 -- FAIL
498a = a = 1 -- FAIL
499 --------------------------------------------------------------------
500 TESTS: function calls
501 --------------------------------------------------------------------
502 -- primaryexp -> prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
503 -- prefixexp -> NAME | '(' expr ')'
504 -- funcargs -> '(' [ explist1 ] ')' | constructor | STRING
505 -- * funcargs turn an expr into a function call
506 --------------------------------------------------------------------
507a( -- FAIL
508a()
509a(1)
510a(1,) -- FAIL
511a(1,2,3)
5121() -- FAIL
513a()()
514a.b()
515a[b]()
516a.1 -- FAIL
517a.b -- FAIL
518a[b] -- FAIL
519a.b.( -- FAIL
520a.b.c()
521a[b][c]()
522a[b].c()
523a.b[c]()
524a:b()
525a:b -- FAIL
526a:1 -- FAIL
527a.b:c()
528a[b]:c()
529a:b: -- FAIL
530a:b():c()
531a:b().c[d]:e()
532a:b()[c].d:e()
533(a)()
534()() -- FAIL
535(1)()
536("foo")()
537(true)()
538(a)()()
539(a.b)()
540(a[b])()
541(a).b()
542(a)[b]()
543(a):b()
544(a).b[c]:d()
545(a)[b].c:d()
546(a):b():c()
547(a):b().c[d]:e()
548(a):b()[c].d:e()
549 --------------------------------------------------------------------
550 TESTS: more function calls
551 --------------------------------------------------------------------
552a"foo"
553a[[foo]]
554a.b"foo"
555a[b]"foo"
556a:b"foo"
557a{}
558a.b{}
559a[b]{}
560a:b{}
561a()"foo"
562a"foo"()
563a"foo".b()
564a"foo"[b]()
565a"foo":c()
566a"foo""bar"
567a"foo"{}
568(a):b"foo".c[d]:e"bar"
569(a):b"foo"[c].d:e"bar"
570a(){}
571a{}()
572a{}.b()
573a{}[b]()
574a{}:c()
575a{}"foo"
576a{}{}
577(a):b{}.c[d]:e{}
578(a):b{}[c].d:e{}
579 --------------------------------------------------------------------
580 TESTS: simple expressions
581 --------------------------------------------------------------------
582 -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE
583 -- | constructor | FUNCTION body | primaryexp
584 --------------------------------------------------------------------
585a = -- FAIL
586a = a
587a = nil
588a = false
589a = 1
590a = "foo"
591a = [[foo]]
592a = {}
593a = (a)
594a = (nil)
595a = (true)
596a = (1)
597a = ("foo")
598a = ([[foo]])
599a = ({})
600a = a.b
601a = a.b. -- FAIL
602a = a.b.c
603a = a:b -- FAIL
604a = a[b]
605a = a[1]
606a = a["foo"]
607a = a[b][c]
608a = a.b[c]
609a = a[b].c
610a = (a)[b]
611a = (a).c
612a = () -- FAIL
613a = a()
614a = a.b()
615a = a[b]()
616a = a:b()
617a = (a)()
618a = (a).b()
619a = (a)[b]()
620a = (a):b()
621a = a"foo"
622a = a{}
623a = function -- FAIL
624a = function 1 -- FAIL
625a = function a -- FAIL
626a = function end -- FAIL
627a = function( -- FAIL
628a = function() end
629a = function(1 -- FAIL
630a = function(p) end
631a = function(p,) -- FAIL
632a = function(p q -- FAIL
633a = function(p,q,r) end
634a = function(p,q,1 -- FAIL
635a = function(...) end
636a = function(..., -- FAIL
637a = function(p,...) end
638a = function(p,q,r,...) end
639 --------------------------------------------------------------------
640 TESTS: operators
641 --------------------------------------------------------------------
642 -- expr -> subexpr
643 -- subexpr -> (UNOPR subexpr | simpleexp) { BINOPR subexpr }
644 -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE
645 -- | constructor | FUNCTION body | primaryexp
646 --------------------------------------------------------------------
647a = -10
648a = -"foo"
649a = -a
650a = -nil
651a = -true
652a = -{}
653a = -function() end
654a = -a()
655a = -(a)
656a = - -- FAIL
657a = not 10
658a = not "foo"
659a = not a
660a = not nil
661a = not true
662a = not {}
663a = not function() end
664a = not a()
665a = not (a)
666a = not -- FAIL
667a = 1 + 2; a = 1 - 2
668a = 1 * 2; a = 1 / 2
669a = 1 ^ 2; a = 1 .. 2
670a = 1 + -- FAIL
671a = 1 .. -- FAIL
672a = 1 * / -- FAIL
673a = 1 + -2; a = 1 - -2
674a = 1 * - -- FAIL
675a = 1 * not 2; a = 1 / not 2
676a = 1 / not -- FAIL
677a = 1 + 2 - 3 * 4 / 5 ^ 6
678a = ((1 + 2) - 3) * (4 / (5 ^ 6))
679a = (1 + (2 - (3 * (4 / (5 ^ ((6)))))))
680a = ((1 -- FAIL
681a = ((1 + 2) -- FAIL
682a = 1) -- FAIL
683a = a + b - c
684a = "foo" + "bar"
685a = "foo".."bar".."baz"
686a = true + false - nil
687a = {} * {}
688a = function() end / function() end
689a = a() ^ b()
690 --------------------------------------------------------------------
691 TESTS: more operators
692 --------------------------------------------------------------------
693a = 1 == 2; a = 1 ~= 2
694a = 1 < 2; a = 1 <= 2
695a = 1 > 2; a = 1 >= 2
696a = 1 < 2 < 3
697a = 1 >= 2 >= 3
698a = 1 == -- FAIL
699a = ~= 2 -- FAIL
700a = "foo" == "bar"
701a = "foo" > "bar"
702a = a ~= b
703a = true == false
704a = 1 and 2; a = 1 or 2
705a = 1 and -- FAIL
706a = or 1 -- FAIL
707a = 1 and 2 and 3
708a = 1 or 2 or 3
709a = 1 and 2 or 3
710a = a and b or c
711a = a() and (b)() or c.d
712a = "foo" and "bar"
713a = true or false
714a = {} and {} or {}
715a = (1) and ("foo") or (nil)
716a = function() end == function() end
717a = function() end or function() end
718 --------------------------------------------------------------------
719 TESTS: constructors
720 --------------------------------------------------------------------
721 -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}'
722 -- fieldsep -> ',' | ';'
723 -- field -> recfield | listfield
724 -- recfield -> ( NAME | '[' exp1 ']' ) = exp1
725 -- listfield -> expr
726 --------------------------------------------------------------------
727a = { -- FAIL
728a = {}
729a = {,} -- FAIL
730a = {;}
731a = {,,} -- FAIL
732a = {;;} -- FAIL
733a = {{ -- FAIL
734a = {{{}}}
735a = {{},{},{{}},}
736a = { 1 }
737a = { 1, }
738a = { 1; }
739a = { 1, 2 }
740a = { a, b, c, }
741a = { true; false, nil; }
742a = { a.b, a[b]; a:c(), }
743a = { 1 + 2, a > b, "a" or "b" }
744a = { a=1, }
745a = { a=1, b="foo", c=nil }
746a = { a -- FAIL
747a = { a= -- FAIL
748a = { a=, -- FAIL
749a = { a=; -- FAIL
750a = { 1, a="foo" -- FAIL
751a = { 1, a="foo"; b={}, d=true; }
752a = { [ -- FAIL
753a = { [1 -- FAIL
754a = { [1] -- FAIL
755a = { [a]= -- FAIL
756a = { ["foo"]="bar" }
757a = { [1]=a, [2]=b, }
758a = { true, a=1; ["foo"]="bar", }
759]]
760
761-- end of script
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.1.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.1.lua
new file mode 100644
index 0000000..0809652
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_parser-5.1.lua
@@ -0,0 +1,783 @@
1--[[--------------------------------------------------------------------
2
3 test_parser-5.1.lua
4 Lua 5.1.x parser test cases
5 This file is part of Yueliang.
6
7 Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15--[[--------------------------------------------------------------------
16-- Notes:
17-- * there is no intention of properly specifying a grammar; the notes
18-- are meant to reflect the structure of lparser so that it is easy
19-- to locate and modify lparser if so desired
20-- * some test may have invalid expressions but will compile, this
21-- is because the chunk hasn't been executed yet
22--
23-- Changed in 5.1.x:
24-- * added ..., %, # cases
25----------------------------------------------------------------------]]
26
27--[[--------------------------------------------------------------------
28-- lparser parsing structure, the Lua 5.1.x version...
29----------------------------------------------------------------------]]
30 --------------------------------------------------------------------
31 -- chunk -> { stat [';'] }
32 --------------------------------------------------------------------
33 -- stat -> DO block END
34 -- block -> chunk
35 --------------------------------------------------------------------
36 -- stat -> breakstat
37 -- breakstat -> BREAK
38 -- * must have a loop to break
39 -- * must be last statement in a block
40 --------------------------------------------------------------------
41 -- stat -> retstat
42 -- retstat -> RETURN explist
43 -- * must be last statement in a block
44 --------------------------------------------------------------------
45 -- stat -> exprstat
46 -- exprstat -> primaryexp
47 -- (-> func | assignment)
48 -- * if LHS is VCALL then func, otherwise assignment
49 -- * for func, LHS is VCALL if funcargs in expression
50 --------------------------------------------------------------------
51 -- stat -> funcstat
52 -- funcstat -> FUNCTION funcname body
53 -- funcname -> NAME {'.' NAME} [':' NAME]
54 --------------------------------------------------------------------
55 -- body -> '(' parlist ')' chunk END
56 -- parlist -> [ param { ',' param } ]
57 -- param -> NAME
58 -- * DOTS must be the last parameter in a parlist
59 --------------------------------------------------------------------
60 -- stat -> LOCAL localstat
61 -- LOCAL localstat -> LOCAL NAME {',' NAME} ['=' explist1]
62 -- explist1 -> expr { ',' expr }
63 --------------------------------------------------------------------
64 -- stat -> LOCAL FUNCTION localfunc
65 -- LOCAL FUNCTION localfunc -> LOCAL FUNCTION NAME body
66 --------------------------------------------------------------------
67 -- stat -> ifstat
68 -- ifstat -> IF cond THEN block
69 -- {ELSEIF cond THEN block}
70 -- [ELSE block] END
71 -- block -> chunk
72 -- cond -> expr
73 --------------------------------------------------------------------
74 -- stat -> forstat
75 -- forstat -> fornum | forlist
76 -- forlist -> NAME {,NAME} IN explist1 forbody END
77 -- fornum -> NAME = exp1,exp1[,exp1] forbody END
78 -- forbody -> DO block
79 -- block -> chunk
80 --------------------------------------------------------------------
81 -- stat -> whilestat
82 -- whilestat -> WHILE cond DO block END
83 -- block -> chunk
84 -- cond -> expr
85 --------------------------------------------------------------------
86 -- stat -> repeatstat
87 -- repeatstat -> REPEAT chunk UNTIL cond
88 -- cond -> expr
89 --------------------------------------------------------------------
90 -- assignment -> ',' primaryexp assignment
91 -- | '=' explist1
92 -- explist1 -> expr { ',' expr }
93 -- * for assignment, LHS must be LOCAL, UPVAL, GLOBAL or INDEXED
94 --------------------------------------------------------------------
95 -- primaryexp -> prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
96 -- prefixexp -> NAME | '(' expr ')'
97 -- funcargs -> '(' [ explist1 ] ')' | constructor | STRING
98 -- * funcargs turn an expr into a function call
99 --------------------------------------------------------------------
100 -- expr -> subexpr
101 -- subexpr -> (UNOPR subexpr | simpleexp) { BINOPR subexpr }
102 -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ...
103 -- | constructor | FUNCTION body | primaryexp
104 --------------------------------------------------------------------
105 -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}'
106 -- fieldsep -> ',' | ';'
107 -- field -> recfield | listfield
108 -- recfield -> ( NAME | '[' exp1 ']' ) = exp1
109 -- listfield -> expr
110 --------------------------------------------------------------------
111
112--[[--------------------------------------------------------------------
113-- parser test cases, Lua 5.1.x
114-- * uncomment string delimiter to enable syntax highlighting...
115-- * anything that matches "^%s*%-%-" is a comment
116-- * headings to display are "^%s*TESTS:%s*(.*)$"
117-- * FAIL test cases should match "%s*%-%-%s*FAIL%s*$"
118----------------------------------------------------------------------]]
119tests_source = [=[
120 --------------------------------------------------------------------
121 TESTS: empty chunks
122 --------------------------------------------------------------------
123 -- chunk -> { stat [';'] }
124 --------------------------------------------------------------------
125
126; -- FAIL
127 --------------------------------------------------------------------
128 TESTS: optional semicolon, simple local statements
129 --------------------------------------------------------------------
130 -- stat -> LOCAL localstat
131 -- LOCAL localstat -> LOCAL NAME {',' NAME} ['=' explist1]
132 -- explist1 -> expr { ',' expr }
133 --------------------------------------------------------------------
134local -- FAIL
135local; -- FAIL
136local = -- FAIL
137local end -- FAIL
138local a
139local a;
140local a, b, c
141local a; local b local c;
142local a = 1
143local a local b = a
144local a, b = 1, 2
145local a, b, c = 1, 2, 3
146local a, b, c = 1
147local a = 1, 2, 3
148local a, local -- FAIL
149local 1 -- FAIL
150local "foo" -- FAIL
151local a = local -- FAIL
152local a, b, = -- FAIL
153local a, b = 1, local -- FAIL
154local a, b = , local -- FAIL
155 --------------------------------------------------------------------
156 TESTS: simple DO blocks
157 --------------------------------------------------------------------
158 -- stat -> DO block END
159 -- block -> chunk
160 --------------------------------------------------------------------
161do -- FAIL
162end -- FAIL
163do end
164do ; end -- FAIL
165do 1 end -- FAIL
166do "foo" end -- FAIL
167do local a, b end
168do local a local b end
169do local a; local b; end
170do local a = 1 end
171do do end end
172do do end; end
173do do do end end end
174do do do end; end; end
175do do do return end end end
176do end do -- FAIL
177do end end -- FAIL
178do return end
179do return return end -- FAIL
180do break end -- FAIL
181 --------------------------------------------------------------------
182 TESTS: simple WHILE loops
183 --------------------------------------------------------------------
184 -- stat -> whilestat
185 -- whilestat -> WHILE cond DO block END
186 -- block -> chunk
187 -- cond -> expr
188 --------------------------------------------------------------------
189while -- FAIL
190while do -- FAIL
191while = -- FAIL
192while 1 do -- FAIL
193while 1 do end
194while 1 do local a end
195while 1 do local a local b end
196while 1 do local a; local b; end
197while 1 do 2 end -- FAIL
198while 1 do "foo" end -- FAIL
199while true do end
200while 1 do ; end -- FAIL
201while 1 do while -- FAIL
202while 1 end -- FAIL
203while 1 2 do -- FAIL
204while 1 = 2 do -- FAIL
205while 1 do return end
206while 1 do return return end -- FAIL
207while 1 do do end end
208while 1 do do return end end
209while 1 do break end
210while 1 do break break end -- FAIL
211while 1 do do break end end
212 --------------------------------------------------------------------
213 TESTS: simple REPEAT loops
214 --------------------------------------------------------------------
215 -- stat -> repeatstat
216 -- repeatstat -> REPEAT chunk UNTIL cond
217 -- cond -> expr
218 --------------------------------------------------------------------
219repeat -- FAIL
220repeat until -- FAIL
221repeat until 0
222repeat until false
223repeat until local -- FAIL
224repeat end -- FAIL
225repeat 1 -- FAIL
226repeat = -- FAIL
227repeat local a until 1
228repeat local a local b until 0
229repeat local a; local b; until 0
230repeat ; until 1 -- FAIL
231repeat 2 until 1 -- FAIL
232repeat "foo" until 1 -- FAIL
233repeat return until 0
234repeat return return until 0 -- FAIL
235repeat break until 0
236repeat break break until 0 -- FAIL
237repeat do end until 0
238repeat do return end until 0
239repeat do break end until 0
240 --------------------------------------------------------------------
241 TESTS: simple FOR loops
242 --------------------------------------------------------------------
243 -- stat -> forstat
244 -- forstat -> fornum | forlist
245 -- forlist -> NAME {,NAME} IN explist1 forbody END
246 -- fornum -> NAME = exp1,exp1[,exp1] forbody END
247 -- forbody -> DO block
248 -- block -> chunk
249 --------------------------------------------------------------------
250for -- FAIL
251for do -- FAIL
252for end -- FAIL
253for 1 -- FAIL
254for a -- FAIL
255for true -- FAIL
256for a, in -- FAIL
257for a in -- FAIL
258for a do -- FAIL
259for a in do -- FAIL
260for a in b do -- FAIL
261for a in b end -- FAIL
262for a in b, do -- FAIL
263for a in b do end
264for a in b do local a local b end
265for a in b do local a; local b; end
266for a in b do 1 end -- FAIL
267for a in b do "foo" end -- FAIL
268for a b in -- FAIL
269for a, b, c in p do end
270for a, b, c in p, q, r do end
271for a in 1 do end
272for a in true do end
273for a in "foo" do end
274for a in b do break end
275for a in b do break break end -- FAIL
276for a in b do return end
277for a in b do return return end -- FAIL
278for a in b do do end end
279for a in b do do break end end
280for a in b do do return end end
281for = -- FAIL
282for a = -- FAIL
283for a, b = -- FAIL
284for a = do -- FAIL
285for a = 1, do -- FAIL
286for a = p, q, do -- FAIL
287for a = p q do -- FAIL
288for a = b do end -- FAIL
289for a = 1, 2, 3, 4 do end -- FAIL
290for a = p, q do end
291for a = 1, 2 do end
292for a = 1, 2 do local a local b end
293for a = 1, 2 do local a; local b; end
294for a = 1, 2 do 3 end -- FAIL
295for a = 1, 2 do "foo" end -- FAIL
296for a = p, q, r do end
297for a = 1, 2, 3 do end
298for a = p, q do break end
299for a = p, q do break break end -- FAIL
300for a = 1, 2 do return end
301for a = 1, 2 do return return end -- FAIL
302for a = p, q do do end end
303for a = p, q do do break end end
304for a = p, q do do return end end
305 --------------------------------------------------------------------
306 TESTS: break statement
307 --------------------------------------------------------------------
308 -- stat -> breakstat
309 -- breakstat -> BREAK
310 -- * must have a loop to break
311 -- * must be last statement in a block
312 --------------------------------------------------------------------
313break -- FAIL
314 --------------------------------------------------------------------
315 TESTS: return statement
316 --------------------------------------------------------------------
317 -- stat -> retstat
318 -- retstat -> RETURN explist
319 -- * must be last statement in a block
320 --------------------------------------------------------------------
321return
322return;
323return return -- FAIL
324return 1
325return local -- FAIL
326return "foo"
327return 1, -- FAIL
328return 1,2,3
329return a,b,c,d
330return 1,2;
331return ...
332return 1,a,...
333 --------------------------------------------------------------------
334 TESTS: conditional statements
335 --------------------------------------------------------------------
336 -- stat -> ifstat
337 -- ifstat -> IF cond THEN block
338 -- {ELSEIF cond THEN block}
339 -- [ELSE block] END
340 -- block -> chunk
341 -- cond -> expr
342 --------------------------------------------------------------------
343if -- FAIL
344elseif -- FAIL
345else -- FAIL
346then -- FAIL
347if then -- FAIL
348if 1 -- FAIL
349if 1 then -- FAIL
350if 1 else -- FAIL
351if 1 then else -- FAIL
352if 1 then elseif -- FAIL
353if 1 then end
354if 1 then local a end
355if 1 then local a local b end
356if 1 then local a; local b; end
357if 1 then else end
358if 1 then local a else local b end
359if 1 then local a; else local b; end
360if 1 then elseif 2 -- FAIL
361if 1 then elseif 2 then -- FAIL
362if 1 then elseif 2 then end
363if 1 then local a elseif 2 then local b end
364if 1 then local a; elseif 2 then local b; end
365if 1 then elseif 2 then else end
366if 1 then else if 2 then end end
367if 1 then else if 2 then end -- FAIL
368if 1 then break end -- FAIL
369if 1 then return end
370if 1 then return return end -- FAIL
371if 1 then end; if 1 then end;
372 --------------------------------------------------------------------
373 TESTS: function statements
374 --------------------------------------------------------------------
375 -- stat -> funcstat
376 -- funcstat -> FUNCTION funcname body
377 -- funcname -> NAME {'.' NAME} [':' NAME]
378 --------------------------------------------------------------------
379 -- body -> '(' parlist ')' chunk END
380 -- parlist -> [ param { ',' param } ]
381 -- param -> NAME
382 -- * DOTS must be the last parameter in a parlist
383 --------------------------------------------------------------------
384function -- FAIL
385function 1 -- FAIL
386function end -- FAIL
387function a -- FAIL
388function a end -- FAIL
389function a( end -- FAIL
390function a() end
391function a(1 -- FAIL
392function a("foo" -- FAIL
393function a(p -- FAIL
394function a(p,) -- FAIL
395function a(p q -- FAIL
396function a(p) end
397function a(p,q,) end -- FAIL
398function a(p,q,r) end
399function a(p,q,1 -- FAIL
400function a(p) do -- FAIL
401function a(p) 1 end -- FAIL
402function a(p) return end
403function a(p) break end -- FAIL
404function a(p) return return end -- FAIL
405function a(p) do end end
406function a.( -- FAIL
407function a.1 -- FAIL
408function a.b() end
409function a.b, -- FAIL
410function a.b.( -- FAIL
411function a.b.c.d() end
412function a: -- FAIL
413function a:1 -- FAIL
414function a:b() end
415function a:b: -- FAIL
416function a:b. -- FAIL
417function a.b.c:d() end
418function a(...) end
419function a(..., -- FAIL
420function a(p,...) end
421function a(p,q,r,...) end
422function a() local a local b end
423function a() local a; local b; end
424function a() end; function a() end;
425 --------------------------------------------------------------------
426 TESTS: local function statements
427 --------------------------------------------------------------------
428 -- stat -> LOCAL FUNCTION localfunc
429 -- LOCAL FUNCTION localfunc -> LOCAL FUNCTION NAME body
430 --------------------------------------------------------------------
431local function -- FAIL
432local function 1 -- FAIL
433local function end -- FAIL
434local function a -- FAIL
435local function a end -- FAIL
436local function a( end -- FAIL
437local function a() end
438local function a(1 -- FAIL
439local function a("foo" -- FAIL
440local function a(p -- FAIL
441local function a(p,) -- FAIL
442local function a(p q -- FAIL
443local function a(p) end
444local function a(p,q,) end -- FAIL
445local function a(p,q,r) end
446local function a(p,q,1 -- FAIL
447local function a(p) do -- FAIL
448local function a(p) 1 end -- FAIL
449local function a(p) return end
450local function a(p) break end -- FAIL
451local function a(p) return return end -- FAIL
452local function a(p) do end end
453local function a. -- FAIL
454local function a: -- FAIL
455local function a(...) end
456local function a(..., -- FAIL
457local function a(p,...) end
458local function a(p,q,r,...) end
459local function a() local a local b end
460local function a() local a; local b; end
461local function a() end; local function a() end;
462 --------------------------------------------------------------------
463 -- stat -> exprstat
464 -- exprstat -> primaryexp
465 -- (-> func | assignment)
466 -- * if LHS is VCALL then func, otherwise assignment
467 -- * for func, LHS is VCALL if funcargs in expression
468 --------------------------------------------------------------------
469 TESTS: assignments
470 --------------------------------------------------------------------
471 -- assignment -> ',' primaryexp assignment
472 -- | '=' explist1
473 -- explist1 -> expr { ',' expr }
474 -- * for assignment, LHS must be LOCAL, UPVAL, GLOBAL or INDEXED
475 --------------------------------------------------------------------
476a -- FAIL
477a, -- FAIL
478a,b,c -- FAIL
479a,b = -- FAIL
480a = 1
481a = 1,2,3
482a,b,c = 1
483a,b,c = 1,2,3
484a.b = 1
485a.b.c = 1
486a[b] = 1
487a[b][c] = 1
488a.b[c] = 1
489a[b].c = 1
4900 = -- FAIL
491"foo" = -- FAIL
492true = -- FAIL
493(a) = -- FAIL
494{} = -- FAIL
495a:b() = -- FAIL
496a() = -- FAIL
497a.b:c() = -- FAIL
498a[b]() = -- FAIL
499a = a b -- FAIL
500a = 1 2 -- FAIL
501a = a = 1 -- FAIL
502 --------------------------------------------------------------------
503 TESTS: function calls
504 --------------------------------------------------------------------
505 -- primaryexp -> prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
506 -- prefixexp -> NAME | '(' expr ')'
507 -- funcargs -> '(' [ explist1 ] ')' | constructor | STRING
508 -- * funcargs turn an expr into a function call
509 --------------------------------------------------------------------
510a( -- FAIL
511a()
512a(1)
513a(1,) -- FAIL
514a(1,2,3)
5151() -- FAIL
516a()()
517a.b()
518a[b]()
519a.1 -- FAIL
520a.b -- FAIL
521a[b] -- FAIL
522a.b.( -- FAIL
523a.b.c()
524a[b][c]()
525a[b].c()
526a.b[c]()
527a:b()
528a:b -- FAIL
529a:1 -- FAIL
530a.b:c()
531a[b]:c()
532a:b: -- FAIL
533a:b():c()
534a:b().c[d]:e()
535a:b()[c].d:e()
536(a)()
537()() -- FAIL
538(1)()
539("foo")()
540(true)()
541(a)()()
542(a.b)()
543(a[b])()
544(a).b()
545(a)[b]()
546(a):b()
547(a).b[c]:d()
548(a)[b].c:d()
549(a):b():c()
550(a):b().c[d]:e()
551(a):b()[c].d:e()
552 --------------------------------------------------------------------
553 TESTS: more function calls
554 --------------------------------------------------------------------
555a"foo"
556a[[foo]]
557a.b"foo"
558a[b]"foo"
559a:b"foo"
560a{}
561a.b{}
562a[b]{}
563a:b{}
564a()"foo"
565a"foo"()
566a"foo".b()
567a"foo"[b]()
568a"foo":c()
569a"foo""bar"
570a"foo"{}
571(a):b"foo".c[d]:e"bar"
572(a):b"foo"[c].d:e"bar"
573a(){}
574a{}()
575a{}.b()
576a{}[b]()
577a{}:c()
578a{}"foo"
579a{}{}
580(a):b{}.c[d]:e{}
581(a):b{}[c].d:e{}
582 --------------------------------------------------------------------
583 TESTS: simple expressions
584 --------------------------------------------------------------------
585 -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ...
586 -- | constructor | FUNCTION body | primaryexp
587 --------------------------------------------------------------------
588a = -- FAIL
589a = a
590a = nil
591a = false
592a = 1
593a = "foo"
594a = [[foo]]
595a = {}
596a = (a)
597a = (nil)
598a = (true)
599a = (1)
600a = ("foo")
601a = ([[foo]])
602a = ({})
603a = a.b
604a = a.b. -- FAIL
605a = a.b.c
606a = a:b -- FAIL
607a = a[b]
608a = a[1]
609a = a["foo"]
610a = a[b][c]
611a = a.b[c]
612a = a[b].c
613a = (a)[b]
614a = (a).c
615a = () -- FAIL
616a = a()
617a = a.b()
618a = a[b]()
619a = a:b()
620a = (a)()
621a = (a).b()
622a = (a)[b]()
623a = (a):b()
624a = a"foo"
625a = a{}
626a = function -- FAIL
627a = function 1 -- FAIL
628a = function a -- FAIL
629a = function end -- FAIL
630a = function( -- FAIL
631a = function() end
632a = function(1 -- FAIL
633a = function(p) end
634a = function(p,) -- FAIL
635a = function(p q -- FAIL
636a = function(p,q,r) end
637a = function(p,q,1 -- FAIL
638a = function(...) end
639a = function(..., -- FAIL
640a = function(p,...) end
641a = function(p,q,r,...) end
642a = ...
643a = a, b, ...
644a = (...)
645a = ..., 1, 2
646a = function() return ... end -- FAIL
647 --------------------------------------------------------------------
648 TESTS: operators
649 --------------------------------------------------------------------
650 -- expr -> subexpr
651 -- subexpr -> (UNOPR subexpr | simpleexp) { BINOPR subexpr }
652 -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ...
653 -- | constructor | FUNCTION body | primaryexp
654 --------------------------------------------------------------------
655a = -10
656a = -"foo"
657a = -a
658a = -nil
659a = -true
660a = -{}
661a = -function() end
662a = -a()
663a = -(a)
664a = - -- FAIL
665a = not 10
666a = not "foo"
667a = not a
668a = not nil
669a = not true
670a = not {}
671a = not function() end
672a = not a()
673a = not (a)
674a = not -- FAIL
675a = #10
676a = #"foo"
677a = #a
678a = #nil
679a = #true
680a = #{}
681a = #function() end
682a = #a()
683a = #(a)
684a = # -- FAIL
685a = 1 + 2; a = 1 - 2
686a = 1 * 2; a = 1 / 2
687a = 1 ^ 2; a = 1 % 2
688a = 1 .. 2
689a = 1 + -- FAIL
690a = 1 .. -- FAIL
691a = 1 * / -- FAIL
692a = 1 + -2; a = 1 - -2
693a = 1 * - -- FAIL
694a = 1 * not 2; a = 1 / not 2
695a = 1 / not -- FAIL
696a = 1 * #"foo"; a = 1 / #"foo"
697a = 1 / # -- FAIL
698a = 1 + 2 - 3 * 4 / 5 % 6 ^ 7
699a = ((1 + 2) - 3) * (4 / (5 % 6 ^ 7))
700a = (1 + (2 - (3 * (4 / (5 % 6 ^ ((7)))))))
701a = ((1 -- FAIL
702a = ((1 + 2) -- FAIL
703a = 1) -- FAIL
704a = a + b - c
705a = "foo" + "bar"
706a = "foo".."bar".."baz"
707a = true + false - nil
708a = {} * {}
709a = function() end / function() end
710a = a() ^ b()
711a = ... % ...
712 --------------------------------------------------------------------
713 TESTS: more operators
714 --------------------------------------------------------------------
715a = 1 == 2; a = 1 ~= 2
716a = 1 < 2; a = 1 <= 2
717a = 1 > 2; a = 1 >= 2
718a = 1 < 2 < 3
719a = 1 >= 2 >= 3
720a = 1 == -- FAIL
721a = ~= 2 -- FAIL
722a = "foo" == "bar"
723a = "foo" > "bar"
724a = a ~= b
725a = true == false
726a = 1 and 2; a = 1 or 2
727a = 1 and -- FAIL
728a = or 1 -- FAIL
729a = 1 and 2 and 3
730a = 1 or 2 or 3
731a = 1 and 2 or 3
732a = a and b or c
733a = a() and (b)() or c.d
734a = "foo" and "bar"
735a = true or false
736a = {} and {} or {}
737a = (1) and ("foo") or (nil)
738a = function() end == function() end
739a = function() end or function() end
740 --------------------------------------------------------------------
741 TESTS: constructors
742 --------------------------------------------------------------------
743 -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}'
744 -- fieldsep -> ',' | ';'
745 -- field -> recfield | listfield
746 -- recfield -> ( NAME | '[' exp1 ']' ) = exp1
747 -- listfield -> expr
748 --------------------------------------------------------------------
749a = { -- FAIL
750a = {}
751a = {,} -- FAIL
752a = {;} -- FAIL
753a = {,,} -- FAIL
754a = {;;} -- FAIL
755a = {{ -- FAIL
756a = {{{}}}
757a = {{},{},{{}},}
758a = { 1 }
759a = { 1, }
760a = { 1; }
761a = { 1, 2 }
762a = { a, b, c, }
763a = { true; false, nil; }
764a = { a.b, a[b]; a:c(), }
765a = { 1 + 2, a > b, "a" or "b" }
766a = { a=1, }
767a = { a=1, b="foo", c=nil }
768a = { a -- FAIL
769a = { a= -- FAIL
770a = { a=, -- FAIL
771a = { a=; -- FAIL
772a = { 1, a="foo" -- FAIL
773a = { 1, a="foo"; b={}, d=true; }
774a = { [ -- FAIL
775a = { [1 -- FAIL
776a = { [1] -- FAIL
777a = { [a]= -- FAIL
778a = { ["foo"]="bar" }
779a = { [1]=a, [2]=b, }
780a = { true, a=1; ["foo"]="bar", }
781]=]
782
783-- end of script
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua
new file mode 100644
index 0000000..53a3ae3
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.0.lua
@@ -0,0 +1,158 @@
1--[[--------------------------------------------------------------------
2
3 test_scripts-5.0.lua
4 Compile and compare Lua files
5 This file is part of Yueliang.
6
7 Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15--[[--------------------------------------------------------------------
16-- NOTE
17-- * use the argument ALL to pull in additional personal Lua scripts
18-- for testing, e.g. lua test_scripts.lua ALL
19----------------------------------------------------------------------]]
20
21------------------------------------------------------------------------
22-- reads in a list of files to crunch from a text file
23------------------------------------------------------------------------
24
25local function loadlist(fname, flist)
26 local inf = io.open(fname, "r")
27 if not inf then error("cannot open "..fname.." for reading") end
28 while true do
29 local d = inf:read("*l")
30 if not d then break end
31 if string.find(d, "^%s*$") or string.find(d, "^#") then
32 -- comments and empty lines are ignored
33 else
34 table.insert(flist, d)
35 end
36 end
37 inf:close()
38end
39
40------------------------------------------------------------------------
41-- read in list of files to test
42------------------------------------------------------------------------
43
44local files = {}
45
46loadlist("files-lua-5.0.txt", files)
47loadlist("files-yueliang-5.0.txt", files)
48
49-- pull in personal scripts to test if user specifies "ALL"
50if arg[1] == "ALL" then
51 loadlist("files-other-5.0.txt", files)
52end
53
54-- if you want to specify files in this script itself (not recommended)
55-- you can add them using the following
56--[[
57for v in string.gfind([[
58]], "[^%s]+") do
59 table.insert(files, v)
60end
61--]]
62
63total = 0 -- sum of sizes
64fsize = 0 -- current file size
65
66------------------------------------------------------------------------
67-- initialize
68------------------------------------------------------------------------
69
70require("../orig-5.0.3/lzio")
71require("../orig-5.0.3/llex")
72require("../orig-5.0.3/lopcodes")
73require("../orig-5.0.3/ldump")
74require("../orig-5.0.3/lcode")
75require("../orig-5.0.3/lparser")
76
77function lua_assert(test)
78 if not test then error("assertion failed!") end
79end
80
81luaX:init()
82
83io.stdout:write("\n\n")
84
85------------------------------------------------------------------------
86-- * basic comparison for now; do it properly later
87------------------------------------------------------------------------
88
89local LuaState = {}
90
91------------------------------------------------------------------------
92-- dump binary chunks to a file if something goes wrong
93------------------------------------------------------------------------
94local function Dump(data, filename)
95 h = io.open(filename, "wb")
96 if not h then error("failed to open "..filename.." for writing") end
97 h:write(data)
98 h:close()
99end
100
101------------------------------------------------------------------------
102-- create custom chunk reader (sums up file sizes)
103------------------------------------------------------------------------
104function make_getF(filename)
105 local h = io.open(filename, "r")
106 if not h then return nil end
107 fsize = h:seek("end")
108 h:seek("set")
109 total = total + fsize
110 return function() -- chunk reader anonymous function here
111 if not h then return nil end
112 local buff = h:read(512)
113 if not buff then h:close() end
114 return buff
115 end
116end
117
118------------------------------------------------------------------------
119-- attempt to compile Lua source files
120------------------------------------------------------------------------
121for i, filename in ipairs(files) do
122 -- compile a source file
123 local zio = luaZ:init(make_getF(filename), nil, "@"..filename)
124 if not zio then
125 error("could not initialize zio stream for "..filename)
126 end
127 io.stdout:write(filename.."("..fsize.."): ")
128 local Func = luaY:parser(LuaState, zio, nil)
129 local Writer, Buff = luaU:make_setS()
130 luaU:dump(LuaState, Func, Writer, Buff)
131 local bc1 = Buff.data -- Yueliang's output
132
133 local f = loadfile(filename)
134 local bc2 = string.dump(f) -- Lua's output
135
136 -- compare outputs
137 if string.len(bc1) ~= string.len(bc2) then
138 Dump(bc1, "bc1.out")
139 Dump(bc2, "bc2.out")
140 error("binary chunk sizes different")
141 elseif bc1 ~= bc2 then
142 Dump(bc1, "bc1.out")
143 Dump(bc2, "bc2.out")
144 error("binary chunks different")
145 else
146 io.stdout:write("CORRECT\n")
147 end
148 local x, y = gcinfo()
149 -- memory usage isn't really a problem for the straight port
150 -- string handling in Lua that follows the original C closely is more
151 -- of a problem, but this will be fixed elsewhere, not in this tree
152 --io.stdout:write("gcinfo: "..x.." "..y.."\n")
153end
154
155-- summaries here
156io.stdout:write("\nTotal file sizes: "..total.."\n")
157
158-- end
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua
new file mode 100644
index 0000000..4d84055
--- /dev/null
+++ b/LuaSL/testLua/yueliang-0.4.1/test_lua/test_scripts-5.1.lua
@@ -0,0 +1,158 @@
1--[[--------------------------------------------------------------------
2
3 test_scripts-5.1.lua
4 Compile and compare Lua files
5 This file is part of Yueliang.
6
7 Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15--[[--------------------------------------------------------------------
16-- NOTE
17-- * use the argument ALL to pull in additional personal Lua scripts
18-- for testing, e.g. lua test_scripts.lua ALL
19----------------------------------------------------------------------]]
20
21------------------------------------------------------------------------
22-- reads in a list of files to crunch from a text file
23------------------------------------------------------------------------
24
25local function loadlist(fname, flist)
26 local inf = io.open(fname, "r")
27 if not inf then error("cannot open "..fname.." for reading") end
28 while true do
29 local d = inf:read("*l")
30 if not d then break end
31 if string.match(d, "^%s*$") or string.match(d, "^#") then
32 -- comments and empty lines are ignored
33 else
34 flist[#flist+1] = d
35 end
36 end
37 inf:close()
38end
39
40------------------------------------------------------------------------
41-- read in list of files to test
42------------------------------------------------------------------------
43
44local files = {}
45
46loadlist("files-lua-5.1.txt", files)
47loadlist("files-yueliang-5.1.txt", files)
48
49-- pull in personal scripts to test if user specifies "ALL"
50if arg[1] == "ALL" then
51 loadlist("files-other-5.1.txt", files)
52end
53
54-- if you want to specify files in this script itself (not recommended)
55-- you can add them using the following
56--[=[
57for v in string.gmatch([[
58]], "[^%s]+") do
59 table.insert(files, v)
60end
61--]=]
62
63total = 0 -- sum of sizes
64fsize = 0 -- current file size
65
66------------------------------------------------------------------------
67-- initialize
68------------------------------------------------------------------------
69
70dofile("../orig-5.1.2/lzio.lua")
71dofile("../orig-5.1.2/llex.lua")
72dofile("../orig-5.1.2/lopcodes.lua")
73dofile("../orig-5.1.2/ldump.lua")
74dofile("../orig-5.1.2/lcode.lua")
75dofile("../orig-5.1.2/lparser.lua")
76
77function lua_assert(test)
78 if not test then error("assertion failed!") end
79end
80
81luaX:init()
82
83io.stdout:write("\n\n")
84
85------------------------------------------------------------------------
86-- * basic comparison for now; do it properly later
87------------------------------------------------------------------------
88
89local LuaState = {}
90
91------------------------------------------------------------------------
92-- dump binary chunks to a file if something goes wrong
93------------------------------------------------------------------------
94local function Dump(data, filename)
95 h = io.open(filename, "wb")
96 if not h then error("failed to open "..filename.." for writing") end
97 h:write(data)
98 h:close()
99end
100
101------------------------------------------------------------------------
102-- create custom chunk reader (sums up file sizes)
103------------------------------------------------------------------------
104function make_getF(filename)
105 local h = io.open(filename, "r")
106 if not h then return nil end
107 fsize = h:seek("end")
108 h:seek("set")
109 total = total + fsize
110 return function() -- chunk reader anonymous function here
111 if not h then return nil end
112 local buff = h:read(512)
113 if not buff then h:close() end
114 return buff
115 end
116end
117
118------------------------------------------------------------------------
119-- attempt to compile Lua source files
120------------------------------------------------------------------------
121for i, filename in ipairs(files) do
122 -- compile a source file
123 local zio = luaZ:init(make_getF(filename), nil)
124 if not zio then
125 error("could not initialize zio stream for "..filename)
126 end
127 io.stdout:write(filename.."("..fsize.."): ")
128 local Func = luaY:parser(LuaState, zio, nil, "@"..filename)
129 local Writer, Buff = luaU:make_setS()
130 luaU:dump(LuaState, Func, Writer, Buff)
131 local bc1 = Buff.data -- Yueliang's output
132
133 local f = loadfile(filename)
134 local bc2 = string.dump(f) -- Lua's output
135
136 -- compare outputs
137 if #bc1 ~= #bc2 then
138 Dump(bc1, "bc1.out")
139 Dump(bc2, "bc2.out")
140 error("binary chunk sizes different")
141 elseif bc1 ~= bc2 then
142 Dump(bc1, "bc1.out")
143 Dump(bc2, "bc2.out")
144 error("binary chunks different")
145 else
146 io.stdout:write("CORRECT\n")
147 end
148 local x = collectgarbage("count")
149 -- memory usage isn't really a problem for the straight port
150 -- string handling in Lua that follows the original C closely is more
151 -- of a problem, but this will be fixed elsewhere, not in this tree
152 --io.stdout:write("collectgarbage: "..x.."\n")
153end
154
155-- summaries here
156io.stdout:write("\nTotal file sizes: "..total.."\n")
157
158-- end