From 9621add2918cc4943e6693b74ae85d51dd264fcf Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 21 Apr 2014 20:59:39 +1000 Subject: We don't need the testlua directory any more. --- LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/README | 122 --- .../testLua/yueliang-0.4.1/nat-5.0.3/llex_mk2.lua | 309 ------ .../testLua/yueliang-0.4.1/nat-5.0.3/llex_mk3.lua | 266 ----- .../testLua/yueliang-0.4.1/nat-5.0.3/llex_mk4.lua | 285 ----- .../yueliang-0.4.1/nat-5.0.3/lparser_mk3.lua | 1027 ------------------ .../yueliang-0.4.1/nat-5.0.3/lparser_mk3b.lua | 1121 -------------------- .../testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua | 106 -- .../testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua | 82 -- .../nat-5.0.3/test/bench_llex_mk2.lua | 94 -- .../nat-5.0.3/test/bench_llex_mk3.lua | 92 -- .../nat-5.0.3/test/bench_llex_mk4.lua | 94 -- .../nat-5.0.3/test/parser_log/sample_01.lua | 9 - .../nat-5.0.3/test/parser_log/sample_02.lua | 10 - .../nat-5.0.3/test/parser_log/sample_03.lua | 21 - .../nat-5.0.3/test/parser_log/sample_04.lua | 31 - .../nat-5.0.3/test/parser_log/sample_05.lua | 129 --- .../nat-5.0.3/test/parser_log/sample_06.lua | 132 --- .../nat-5.0.3/test/parser_log/sample_07.lua | 147 --- .../nat-5.0.3/test/parser_log/sample_08.lua | 66 -- .../nat-5.0.3/test/parser_log/sample_09.lua | 97 -- .../nat-5.0.3/test/parser_log/sample_10.lua | 106 -- .../nat-5.0.3/test/parser_log/sample_11.lua | 175 --- .../nat-5.0.3/test/parser_log/sample_12.lua | 46 - .../nat-5.0.3/test/parser_log/sample_13.lua | 99 -- .../nat-5.0.3/test/parser_log/sample_14.lua | 107 -- .../nat-5.0.3/test/parser_log/sample_15.lua | 135 --- .../nat-5.0.3/test/parser_log/sample_16.lua | 87 -- .../nat-5.0.3/test/parser_log/sample_17.lua | 110 -- .../nat-5.0.3/test/parser_log/sample_b_01.lua | 26 - .../nat-5.0.3/test/parser_log/sample_b_02.lua | 35 - .../nat-5.0.3/test/parser_log/sample_b_03.lua | 64 -- .../nat-5.0.3/test/parser_log/sample_b_04.lua | 77 -- .../nat-5.0.3/test/parser_log/sample_b_05.lua | 43 - .../nat-5.0.3/test/parser_log/sample_b_06.lua | 70 -- .../nat-5.0.3/test/parser_log/sample_b_07.lua | 84 -- .../nat-5.0.3/test/parser_log/sample_b_08.lua | 159 --- .../nat-5.0.3/test/parser_log/sample_b_09.lua | 53 - .../nat-5.0.3/test/parser_log/sample_b_10.lua | 49 - .../nat-5.0.3/test/parser_log/sample_b_11.lua | 79 -- .../nat-5.0.3/test/parser_log/sample_b_12.lua | 94 -- .../nat-5.0.3/test/parser_log/sample_b_13.lua | 117 -- .../nat-5.0.3/test/parser_log/sample_b_14.lua | 125 --- .../yueliang-0.4.1/nat-5.0.3/test/sample.lua | 3 - .../nat-5.0.3/test/test_llex_mk2.lua | 499 --------- .../nat-5.0.3/test/test_llex_mk3.lua | 500 --------- .../nat-5.0.3/test/test_llex_mk4.lua | 499 --------- .../nat-5.0.3/test/test_lparser_mk3.lua | 218 ---- .../nat-5.0.3/test/test_lparser_mk3_2.lua | 158 --- .../nat-5.0.3/test/test_lparser_mk3b.lua | 188 ---- .../nat-5.0.3/test/test_lparser_mk3b_2.lua | 158 --- .../nat-5.0.3/test/test_lzio_mk2.lua | 53 - 51 files changed, 8456 deletions(-) delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/README delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk2.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk3.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk4.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3b.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk2.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk4.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_01.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_02.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_03.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_04.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_05.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_06.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_07.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_08.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_09.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_10.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_11.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_12.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_13.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_14.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_15.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_16.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_17.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_01.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_02.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_03.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_04.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_05.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_06.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_07.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_08.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_09.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_10.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_11.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_12.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_13.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_14.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/sample.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk2.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk3.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3_2.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b_2.lua delete mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lzio_mk2.lua (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.0.3') diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/README b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/README deleted file mode 100644 index b6a65d2..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/README +++ /dev/null @@ -1,122 +0,0 @@ -nat-5.0.3 - -This directory contains versions of front end files that are rewritten -to be more "native" to Lua. These files should be considered as -exercises in exploring ways to write the front end, for example, to -write a front end that is optimized for size, etc. See also file size -data further below. - -The following are the different versions available (mk2 == "mark 2", -this is commonly used in the UK, e.g. for aeroplanes during WWII): - -Lexers ------- - -WARNING: Theses lexer may or may not exhibit exact behaviour when lexing -strings or long strings with embedded CRLF newlines. The CRLF sequence -may be translated into LF (the reference manual is unclear on this.) The -user is advised to stick to LF line endings exclusively. - -llex_mk2 Rewritten from original ported code to become more - Lua-like. Still uses a stream-based input interface. - MK2 still scans using a per-character function that - is pretty inefficient. - - Status: TESTED - -llex_mk3 A rewritten version of MK2 that needs input to be - entered as a single string. Unless an application's - need is very unusual, this should not be a problem. - It will not work for per-line interaction, though. - MK3 no longer needs stream input functions. This - version is also heavily optimized for size. MK3 scans - using find functions and doesn't create many strings. - - Status: TESTED - -llex_mk4 A rewritten version of MK3 that is line-oriented. - This allows a command-line version that works in the - usual way to be written. - - Status: TESTED - -The following is a comparison of file sizes (as of 20061111): - - lzio llex TOTAL Speed (2) - (bytes) (bytes) (bytes) (KB/s) ----------------------------------------------- -Binary (Mingw) 416 5312 5728 N/A ----------------------------------------------- -(in orig-5.0.3:) ----------------------------------------------- -normal 2219 12639 14585 404.9 -stripped 1292 7618 8910 ----------------------------------------------- -(in nat-5.0.3:) ----------------------------------------------- -mk2 1995 7628 9623 469.5 -mk2-stripped 1195 4003 5298 ----------------------------------------------- -mk3 (1) - 6552 6552 1870.8 -mk3-stripped - 3286 3286 ----------------------------------------------- -mk4 1337 6956 8293 802.9 -mk4-stripped 798 3457 4225 ----------------------------------------------- - -(1) mk3 does not have a file input streaming function - -(2) Speed was benchmarked using a Sempron 3000+. Benchmark scripts are -in the test directories. Best of first three figures quoted. This is a -measurement of raw lexer speed, i.e. tokens are read but no processing -is done. All files are read in entirely before running the lexer. - -The performance of the orig-5.0.3 parser is probably a whole magnitude -less than the orig-5.0.3 lexer performance. - -Parsers -------- - -lparser_mk3 Written for the simplified lexer interface of llex_mk3+. - (Should be compatible with llex_mk4 too, but untested.) - This is a lexer skeleton, stripped of codegen code. See - the comments in the source code for more information. - Without logging messages and comments, it's under 600 LOC. - - Sample output of the parser message logger can be found - in the test/parser_log subdirectory. - - Tested with test_parser-5.0.lua, the Lua 5.0.x parser test - cases in the test_lua/ directory, appears to be fine. - - Status: SNIPPETS APPEAR TO WORK - -lparser_mk3b As above, with variable management code added. In order - to use the parser usefully, variable management code is - a big step forward, allowing the parser to differentiate - locals, upvalues and globals. The number of added lines - is around 100 LOC. A binary chunk of lparser_mk3b - (stripped) is 18076 bytes. - - Sample output of the parser message logger can be found - in the test/parser_log subdirectory. - - Tested with test_parser-5.0.lua, the Lua 5.0.x parser test - cases in the test_lua/ directory, appears to be fine. - - Status: SNIPPETS APPEAR TO WORK - -There will be no further development beyond lparser_mk3b. Further work -will focus on a 5.1.x equivalent, for which both a parser skeleton and a -parser with full code generation using nicely commented code is planned. - -Other notes: ------------- - -For Lua 5.0.2, see Yueliang 0.1.3, which was the last release of Lua -5.0.2 material. - -Test scripts for the lexer should probably be consolidated, but it's a -little difficult because not all lexers give the same error messages or -use the same token names or format. - diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk2.lua deleted file mode 100644 index 955f229..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk2.lua +++ /dev/null @@ -1,309 +0,0 @@ ---[[-------------------------------------------------------------------- - - llex.lua - Lua 5 lexical analyzer in Lua - This file is part of Yueliang. - - Copyright (c) 2005-2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * parser to implement luaX_syntaxerror, call errorline with 2 parms -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- local lex_init = require("llex.lua") --- local llex = lex_init(z, source) --- llex:chunkid() --- * returns formatted name of chunk id --- llex:errorline(s, token, line) --- * throws an error with a formatted message --- llex:lex() --- * returns next lexical element (token, seminfo) -----------------------------------------------------------------------]] - -return -function(z, source) ---[[-------------------------------------------------------------------- --- lexer initialization -----------------------------------------------------------------------]] - -------------------------------------------------------------------- - -- initialize variables - -------------------------------------------------------------------- - local string = string - local EOF = "" - local z = z - local luaX = {source = source, lineno = 1,} - local curr, buff - -------------------------------------------------------------------- - -- initialize keyword list - -------------------------------------------------------------------- - local kw = {} - for v in string.gfind([[ -and break do else elseif end false for function if in -local nil not or repeat return then true until while]], "%S+") do - kw[v] = true - end ---[[-------------------------------------------------------------------- --- support functions -----------------------------------------------------------------------]] - -------------------------------------------------------------------- - -- returns a chunk name or id - -------------------------------------------------------------------- - function luaX:chunkid() - local sub = string.sub - local first = sub(source, 1, 1) - if first == "=" or first == "@" then - return sub(source, 2) -- remove first char - end - return "[string]" - end - -------------------------------------------------------------------- - -- formats error message and throws error - -------------------------------------------------------------------- - function luaX:errorline(s, token, line) - if not line then line = self.lineno end - error(string.format("%s:%d: %s near '%s'", self:chunkid(), line, s, token)) - end - -------------------------------------------------------------------- - -- throws a lexer error - -------------------------------------------------------------------- - local function lexerror(s, token) - if not token then token = buff end - luaX:errorline(s, token) - end - -------------------------------------------------------------------- - -- gets the next character and returns it - -------------------------------------------------------------------- - local function nextc() - local c = z:getc() - curr = c - return c - end - -------------------------------------------------------------------- - -- save current character into token buffer, grabs next character - -- * save(c) merged into this and elsewhere to save space - -------------------------------------------------------------------- - local function save_next() - buff = buff..curr - return nextc() - end - -------------------------------------------------------------------- - -- move on to next line - -------------------------------------------------------------------- - local function nextline() - local luaX = luaX - nextc() -- skip '\n' - luaX.lineno = luaX.lineno + 1 - end ---[[-------------------------------------------------------------------- --- reads a number (LUA_NUMBER) -----------------------------------------------------------------------]] - local function read_numeral(comma) - buff = "" - local find = string.find - if comma then buff = "." end - ------------------------------------------------------------------ - while find(curr, "%d") do save_next() end - if curr == "." then - if save_next() == "." then - save_next() - lexerror("ambiguous syntax (dots follows digits)") - end - end - ------------------------------------------------------------------ - while find(curr, "%d") do save_next() end - if find(curr, "^[eE]$") then - save_next() -- read 'E' and optional exponent sign - if find(curr, "^[+-]$") then save_next() end - while find(curr, "%d") do save_next() end - end - c = tonumber(buff) - if c then return c end - lexerror("malformed number") - end ---[[-------------------------------------------------------------------- --- reads a long string or long comment -----------------------------------------------------------------------]] - local function read_long(is_str) - local cont = 0 - buff = "" - nextc() -- pass the '[[' - if curr == "\n" then -- string starts with a newline? - nextline() -- skip it - end - while true do - local c = curr - ---------------------------------------------------------------- - if c == "EOZ" then - lexerror(is_str and "unfinished long string" or - "unfinished long comment", EOF) - ---------------------------------------------------------------- - elseif c == "[" then - if save_next() == "[" then - cont = cont + 1; save_next() - end - ---------------------------------------------------------------- - elseif c == "]" then - if save_next() == "]" then - if cont == 0 then break end - cont = cont - 1; save_next() - end - ---------------------------------------------------------------- - elseif c == "\n" then - buff = buff.."\n"; nextline() - if not is_str then buff = "" end -- avoid wasting space - ---------------------------------------------------------------- - else - save_next() - ---------------------------------------------------------------- - end--if c - end--while - nextc() -- skip second ']' - return string.sub(buff, 1, -2) - end ---[[-------------------------------------------------------------------- --- reads a string -----------------------------------------------------------------------]] - local function read_string(del) - local find = string.find - buff = "" - save_next() -- save delimiter - while curr ~= del do - local c = curr - ---------------------------------------------------------------- - -- end-of-file, newline - ---------------------------------------------------------------- - if c == "EOZ" then - lexerror("unfinished string", EOF) - elseif c == "\n" then - lexerror("unfinished string") - ---------------------------------------------------------------- - -- escapes - ---------------------------------------------------------------- - elseif c == "\\" then - c = nextc() -- do not save the '\' - if c ~= "EOZ" then -- will raise an error next loop iteration - local d = find("\nabfnrtv", c, 1, 1) - if d then - buff = buff..string.sub("\n\a\b\f\n\r\t\v", d, d) - if d == 1 then nextline() else nextc() end - elseif find(c, "%D") then - save_next() -- handles \\, \", \', and \? - else -- \xxx - c, d = 0, 0 - repeat - c = 10 * c + curr; d = d + 1; nextc() - until d >= 3 or find(curr, "%D") - if c > 255 then -- UCHAR_MAX - lexerror("escape sequence too large") - end - buff = buff..string.char(c) - end - end - ---------------------------------------------------------------- - -- a regular character - ---------------------------------------------------------------- - else - save_next() - ---------------------------------------------------------------- - end--if c - end--while - nextc() -- skip delimiter - return string.sub(buff, 2) - end ---[[-------------------------------------------------------------------- --- main lexer function -----------------------------------------------------------------------]] - function luaX:lex() - local find = string.find - while true do - local c = curr - ---------------------------------------------------------------- - -- operators, numbers - ---------------------------------------------------------------- - local d = find("=<>~\"'-[.\n", c, 1, 1) - if d then - ------------------------------------------------------------ - if d <= 4 then -- "=<>~" (relational operators) - if nextc() ~= "=" then return c end - nextc(); return c.."=" - ------------------------------------------------------------ - elseif d <= 6 then -- "\"" or "'" (string) - return "", read_string(c) - ------------------------------------------------------------ - elseif c == "-" then -- "-" ("-", comment, or long comment) - if nextc() ~= "-" then return "-" end - c = nextc() -- otherwise it is a comment - if c == "[" and nextc() == "[" then - read_long() -- long comment - else -- short comment - while c ~= "\n" and c ~= "EOZ" do c = nextc() end - end - ------------------------------------------------------------ - elseif c == "[" then -- "[" ("[" or long string) - if nextc() ~= "[" then return c end - return "", read_long(true) - ------------------------------------------------------------ - elseif c == "." then -- "." (".", concatenation, or dots) - buff = "" - c = save_next() - if c == "." then -- interpret 2 or 3 dots - if save_next() == "." then save_next() end - return buff - end - if find(c, "%d") then - return "", read_numeral(true) - end - return "." - ------------------------------------------------------------ - else-- c == "\n" then -- "\n" (newline) - nextline() - ------------------------------------------------------------ - end--if d/c - ---------------------------------------------------------------- - -- number, end-of-file, identifier or reserved word - ---------------------------------------------------------------- - elseif find(c, "%d") then -- number - return "", read_numeral(false) - ---------------------------------------------------------------- - elseif find(c, "[_%a]") then -- reads a name - if c == "EOZ" then return EOF end -- end-of-file - buff = "" - repeat - c = save_next() - until c == "EOZ" or find(c, "[^_%w]") - c = buff - if kw[c] then return c end -- reserved word - return "", c - ---------------------------------------------------------------- - -- whitespace, other characters, control characters - ---------------------------------------------------------------- - elseif find(c, "%s") then -- whitespace - nextc() - ---------------------------------------------------------------- - elseif find(c, "%c") then -- control characters - lexerror("invalid control char", "char("..string.byte(c)..")") - ---------------------------------------------------------------- - else -- single-char tokens (+ - / etc.) - nextc(); return c - ---------------------------------------------------------------- - end--if d/c - end--while - end ---[[-------------------------------------------------------------------- --- initial processing (shbang handling) -----------------------------------------------------------------------]] - nextc() -- read first char - if cur == "#" then -- skip first line - repeat nextc() until curr == "\n" or curr == "EOZ" - end - return luaX ---[[------------------------------------------------------------------]] -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk3.lua deleted file mode 100644 index 1cd22b5..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk3.lua +++ /dev/null @@ -1,266 +0,0 @@ ---[[-------------------------------------------------------------------- - - llex.lua - Lua 5 lexical analyzer in Lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * takes in the entire source at once --- * code is heavily optimized for size --- --- local lex_init = require("llex.lua") --- local llex = lex_init(z, source) --- llex:chunkid() --- * returns formatted name of chunk id --- llex:errorline(s, line) --- * throws an error with a formatted message --- llex:lex() --- * returns next lexical element (token, seminfo) --- llex.ln --- * line number -----------------------------------------------------------------------]] - -return -function(z, source) - -------------------------------------------------------------------- - -- initialize variables - -- * I is the upvalue, i is the local version for space/efficiency - -------------------------------------------------------------------- - local string = string - local find, sub = string.find, string.sub - local EOF = "" - local luaX = { ln = 1 } - local I = 1 - -------------------------------------------------------------------- - -- initialize keyword list - -------------------------------------------------------------------- - local kw = {} - for v in string.gfind([[ -and break do else elseif end false for function if in -local nil not or repeat return then true until while]], "%S+") do - kw[v] = true - end - -------------------------------------------------------------------- - -- returns a chunk name or id - -------------------------------------------------------------------- - function luaX:chunkid() - if find(source, "^[=@]") then - return sub(source, 2) -- remove first char - end - return "[string]" - end - -------------------------------------------------------------------- - -- formats error message and throws error - -- * a simplified version, does not report what token was responsible - -------------------------------------------------------------------- - function luaX:errorline(s, line) - error(string.format("%s:%d: %s", self:chunkid(), line or self.ln, s)) - end - ---------------------------------------------------------------------- - -- reads a long string or long comment - ---------------------------------------------------------------------- - local function read_long(i, is_str) - local luaX = luaX - local string = string - local cont = 1 - if sub(z, i, i) == "\n" then - i = i + 1 - luaX.ln = luaX.ln + 1 - end - local j = i - while true do - local p, q, r = find(z, "([\n%[%]])", i) -- (long range) - if not p then - luaX:errorline(is_str and "unfinished long string" or - "unfinished long comment") - end - i = p + 1 - if r == "\n" then - luaX.ln = luaX.ln + 1 - elseif sub(z, i, i) == r then -- only [[ or ]] - i = i + 1 - if r == "[" then - cont = cont + 1 - else-- r == "]" then - if cont == 1 then break end -- last ]] found - cont = cont - 1 - end - end - end--while - I = i - return sub(z, j, i - 3) - end - ---------------------------------------------------------------------- - -- reads a string - ---------------------------------------------------------------------- - local function read_string(i, del) - local luaX = luaX - local string = string - local buff = "" - while true do - local p, q, r = find(z, "([\n\\\"\'])", i) -- (long range) - if p then - if r == "\n" then - luaX:errorline("unfinished string") - end - buff = buff..sub(z, i, p - 1) -- normal portions - i = p - if r == "\\" then -- handle escapes - i = i + 1 - r = sub(z, i, i) - if r == "" then break end -- (error) - p = find("\nabfnrtv", r, 1, 1) - ------------------------------------------------------ - if p then -- special escapes - r = sub("\n\a\b\f\n\r\t\v", p, p) - if p == 1 then luaX.ln = luaX.ln + 1 end - i = i + 1 - ------------------------------------------------------ - elseif find(r, "%D") then -- other non-digits - i = i + 1 - ------------------------------------------------------ - else -- \xxx sequence - local p, q, s = find(z, "^(%d%d?%d?)", i) - i = q + 1 - if s + 1 > 256 then -- UCHAR_MAX - luaX:errorline("escape sequence too large") - end - r = string.char(s) - ------------------------------------------------------ - end--if p - else - i = i + 1 - if r == del then - I = i - return buff -- ending delimiter - end - end--if r - buff = buff..r - else - break -- (error) - end--if p - end--while - luaX:errorline("unfinished string") - end - ---------------------------------------------------------------------- - -- main lexer function - ---------------------------------------------------------------------- - function luaX:lex() - local string = string - local find, len = find, string.len - while true do--outer - local i = I - -- inner loop allows break to be used to nicely section tests - while true do--inner - ---------------------------------------------------------------- - local p, _, r = find(z, "^([_%a][_%w]*)", i) - if p then - I = i + len(r) - if kw[r] then return r end -- keyword - return "", r -- identifier - end - ---------------------------------------------------------------- - local p, q, r = find(z, "^(%.?)%d", i) - if p then -- numeral - if r == "." then i = i + 1 end - local _, n, r, s = find(z, "^%d*(%.?%.?)%d*([eE]?)", i) - q = n - i = q + 1 - if len(r) == 2 then - self:errorline("ambiguous syntax (dots follows digits)") - end - if len(s) == 1 then -- optional exponent - local _, n = find(z, "^[%+%-]?%d*", i) -- optional sign - q = n - i = q + 1 - end - r = tonumber(sub(z, p, q)) - I = i - if not r then self:errorline("malformed number") end - return "", r - end - ---------------------------------------------------------------- - local p, q, r = find(z, "^(%s)[ \t]*", i) - if p then - if r == "\n" then -- newline - self.ln = self.ln + 1 - I = i + 1 - else - I = q + 1 -- whitespace - end - break -- (continue) - end - ---------------------------------------------------------------- - local p, _, r = find(z, "^(%p)", i) -- symbols/punctuation - if p then - local q = find("-[\"\'.=<>~", r, 1, 1) - if q then -- further processing for more complex symbols - ---------------------------------------------------- - if q <= 2 then - if q == 1 then -- minus - if find(z, "^%-%-", i) then - i = i + 2 - if find(z, "^%[%[", i) then -- long comment - read_long(i + 2) - else -- short comment - I = find(z, "\n", i) or (len(z) + 1) - end - break -- (continue) - end - -- (fall through for "-") - elseif q == 2 then -- [ or long string - if find(z, "^%[%[", i) then - return "", read_long(i + 2, true) - end - -- (fall through for "[") - end - ---------------------------------------------------- - elseif q <= 5 then - if q < 5 then -- strings - return "", read_string(i + 1, r) - end - local _, _, s = find(z, "^(%.%.?%.?)", i) -- dots - r = s - -- (fall through) - ---------------------------------------------------- - else -- relational/logic - local _, _, s = find(z, "^(%p=?)", i) - r = s - -- (fall through) - end - end - I = i + len(r); return r -- for other symbols, fall through - end - ---------------------------------------------------------------- - local r = sub(z, i, i) - if r ~= "" then - if find(r, "%c") then -- invalid control char - self:errorline("invalid control char("..string.byte(r)..")") - end - I = i + 1; return r -- other single-char tokens - end - return EOF -- end of stream - ---------------------------------------------------------------- - end--while inner - end--while outer - end - -------------------------------------------------------------------- - -- initial processing (shbang handling) - -------------------------------------------------------------------- - local p, q, r = find(z, "^#[^\n]*(\n?)") - if p then -- skip first line - I = q + 1 - if r == "\n" then luaX.ln = luaX.ln + 1 end - end - return luaX - -------------------------------------------------------------------- -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk4.lua deleted file mode 100644 index 42559a3..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/llex_mk4.lua +++ /dev/null @@ -1,285 +0,0 @@ ---[[-------------------------------------------------------------------- - - llex.lua - Lua 5 lexical analyzer in Lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * a line-oriented version of mk3 --- --- local lex_init = require("llex.lua") --- local llex = lex_init(z, source) --- llex:chunkid() --- * returns formatted name of chunk id --- llex:errorline(s, line) --- * throws an error with a formatted message --- llex:lex() --- * returns next lexical element (token, seminfo) --- llex.ln --- * line number -----------------------------------------------------------------------]] - -return -function(zio, source) - -------------------------------------------------------------------- - -- initialize variables - -- * I is the upvalue, i is the local version for space/efficiency - -------------------------------------------------------------------- - local string = string - local find, sub = string.find, string.sub - local EOF = "" - local luaX = { ln = 0 } - local I, z - -------------------------------------------------------------------- - -- initialize keyword list - -------------------------------------------------------------------- - local kw = {} - for v in string.gfind([[ -and break do else elseif end false for function if in -local nil not or repeat return then true until while]], "%S+") do - kw[v] = true - end - -------------------------------------------------------------------- - -- returns a chunk name or id - -------------------------------------------------------------------- - function luaX:chunkid() - if find(source, "^[=@]") then - return sub(source, 2) -- remove first char - end - return "[string]" - end - -------------------------------------------------------------------- - -- formats error message and throws error - -- * a simplified version, does not report what token was responsible - -------------------------------------------------------------------- - function luaX:errorline(s, line) - error(string.format("%s:%d: %s", self:chunkid(), line or self.ln, s)) - end - -------------------------------------------------------------------- - -- move on to next line - -------------------------------------------------------------------- - local function nextln() - local luaX = luaX - luaX.ln = luaX.ln + 1 - z = zio:getln() - I = 1 - end - ---------------------------------------------------------------------- - -- reads a long string or long comment - ---------------------------------------------------------------------- - local function read_long(i, is_str) - local luaX = luaX - local string = string - local buff = "" - local cont = 1 - if sub(z, i, i) == "\n" then - nextln(); i = 1 - end - while true do - local p, q, r = find(z, "([\n%[%]])", i) -- (long range) - if not p then - luaX:errorline(is_str and "unfinished long string" or - "unfinished long comment") - end - buff = buff..string.sub(z, i, p - 1) -- add a portion - i = p + 1 - if sub(z, i, i) == r then -- only [[ or ]] - i = i + 1 - if r == "[" then - cont = cont + 1 - else-- r == "]" then - if cont == 1 then break end -- last ]] found - cont = cont - 1 - end - buff = buff..r..r - else -- [ or ] or \n - buff = buff..r - if r == "\n" then - nextln(); i = 1 - end - end - end--while - I = i - return buff - end - ---------------------------------------------------------------------- - -- reads a string - ---------------------------------------------------------------------- - local function read_string(i, del) - local luaX = luaX - local string = string - local buff = "" - while true do - local p, q, r = find(z, "([\n\\\"\'])", i) -- (long range) - if p then - if r == "\n" then - luaX:errorline("unfinished string") - end - buff = buff..sub(z, i, p - 1) -- normal portions - i = p - if r == "\\" then -- handle escapes - i = i + 1 - r = sub(z, i, i) - if r == "" then break end -- (error) - p = find("\nabfnrtv", r, 1, 1) - ------------------------------------------------------ - if p then -- special escapes - r = sub("\n\a\b\f\n\r\t\v", p, p) - if p == 1 then - nextln(); i = 1 - else - i = i + 1 - end - ------------------------------------------------------ - elseif find(r, "%D") then -- other non-digits - i = i + 1 - ------------------------------------------------------ - else -- \xxx sequence - local p, q, s = find(z, "^(%d%d?%d?)", i) - i = q + 1 - if s + 1 > 256 then -- UCHAR_MAX - luaX:errorline("escape sequence too large") - end - r = string.char(s) - ------------------------------------------------------ - end--if p - else - i = i + 1 - if r == del then - I = i - return buff -- ending delimiter - end - end--if r - buff = buff..r - else - break -- (error) - end--if p - end--while - luaX:errorline("unfinished string") - end - ---------------------------------------------------------------------- - -- main lexer function - ---------------------------------------------------------------------- - function luaX:lex() - local string = string - local find, len = find, string.len - while true do--outer - local i = I - -- inner loop allows break to be used to nicely section tests - while true do--inner - ---------------------------------------------------------------- - local p, _, r = find(z, "^([_%a][_%w]*)", i) - if p then - I = i + len(r) - if kw[r] then return r end -- keyword - return "", r -- identifier - end - ---------------------------------------------------------------- - local p, q, r = find(z, "^(%.?)%d", i) - if p then -- numeral - if r == "." then i = i + 1 end - local _, n, r, s = find(z, "^%d*(%.?%.?)%d*([eE]?)", i) - q = n - i = q + 1 - if len(r) == 2 then - self:errorline("ambiguous syntax (dots follows digits)") - end - if len(s) == 1 then -- optional exponent - local _, n = find(z, "^[%+%-]?%d*", i) -- optional sign - q = n - i = q + 1 - end - r = tonumber(sub(z, p, q)) - I = i - if not r then self:errorline("malformed number") end - return "", r - end - ---------------------------------------------------------------- - local p, q, r = find(z, "^(%s)[ \t]*", i) - if p then - if r == "\n" then -- newline - nextln() - else - I = q + 1 -- whitespace - end - break -- (continue) - end - ---------------------------------------------------------------- - local p, _, r = find(z, "^(%p)", i) -- symbols/punctuation - if p then - local q = find("-[\"\'.=<>~", r, 1, 1) - if q then -- further processing for more complex symbols - ---------------------------------------------------- - if q <= 2 then - if q == 1 then -- minus - if find(z, "^%-%-", i) then - i = i + 2 - if find(z, "^%[%[", i) then -- long comment - read_long(i + 2) - else -- short comment - if find(z, "\n", i) then - nextln() - else - I = len(z) + 1 - end - end - break -- (continue) - end - -- (fall through for "-") - elseif q == 2 then -- [ or long string - if find(z, "^%[%[", i) then - return "", read_long(i + 2, true) - end - -- (fall through for "[") - end - ---------------------------------------------------- - elseif q <= 5 then - if q < 5 then -- strings - return "", read_string(i + 1, r) - end - local _, _, s = find(z, "^(%.%.?%.?)", i) -- dots - r = s - -- (fall through) - ---------------------------------------------------- - else -- relational/logic - local _, _, s = find(z, "^(%p=?)", i) - r = s - -- (fall through) - end - end - I = i + len(r); return r -- for other symbols, fall through - end - ---------------------------------------------------------------- - local r = sub(z, i, i) - if r ~= "" then - if find(r, "%c") then -- invalid control char - self:errorline("invalid control char("..string.byte(r)..")") - end - I = i + 1; return r -- other single-char tokens - end - return EOF -- end of stream - ---------------------------------------------------------------- - end--while inner - end--while outer - end - -------------------------------------------------------------------- - -- initial processing (shbang handling) - -------------------------------------------------------------------- - nextln() - local p, q, r = find(z, "^#[^\n]*(\n?)") - if p then -- skip first line - I = q + 1 - if r == "\n" then nextln() end - end - return luaX - -------------------------------------------------------------------- -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3.lua deleted file mode 100644 index 17d6f64..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3.lua +++ /dev/null @@ -1,1027 +0,0 @@ ---[[-------------------------------------------------------------------- - - lparser.lua - Lua 5 parser in Lua - This file is part of Yueliang. - - Copyright (c) 2008 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * this is a Lua 5.0.x parser skeleton, for llex_mk3.lua lexer --- * written as a module factory with recognizable lparser.c roots --- * builds some data, performs logging for educational purposes --- * target is to have relatively efficient and clear code --- * needs one parameter, a lexer module that implements: --- luaX:lex() - returns appropriate [token, semantic info] pairs --- luaX.ln - current line number --- luaX:errorline(s, [line]) - dies with error message --- --- Usage example: --- lex_init = require("llex_mk3.lua") --- parser_init = require("lparser_mk3.lua") --- local luaX = lex_init(chunk, "=string") --- local luaY = parser_init(luaX) --- local fs = luaY:parser() --- --- Development notes: --- * see test_parser-5.0.lua for grammar elements based on lparser.c --- * lparser has a few extra items to help parsing/syntax checking --- (a) line number (error reporting), lookahead token storage --- (b) per-prototype states needs a storage list --- (c) 'break' needs a per-block flag in a stack --- (d) 'kind' (v.k) testing needed in expr_stat() and assignment() --- for disambiguation, thus v.k manipulation is retained --- (e) one line # var (lastln) for ambiguous (split line) function --- call checking --- (f) most line number function call args retained for future use --- (g) Lua 4 compatibility code completely removed --- (h) no variable management code! singlevar() always returns VLOCAL --- * parsing starts from the end of this file in luaY:parser() --- -----------------------------------------------------------------------]] - -return -function(luaX) ---[[-------------------------------------------------------------------- --- structures and data initialization -----------------------------------------------------------------------]] - - local line -- start line # for error messages - local lastln -- last line # for ambiguous syntax chk - local tok, seminfo -- token, semantic info pair - local peek_tok, peek_sem -- ditto, for lookahead - local fs -- function state - local top_fs = {} -- top-level function state - local luaY = {} - -------------------------------------------------------------------- - local block_follow = {} -- lookahead check in chunk(), returnstat() - for v in string.gfind("else elseif end until ", "%S+") do - block_follow[v] = true - end - -------------------------------------------------------------------- - local stat_call = {} -- lookup for calls in stat() - for v in string.gfind("if while do for repeat function local return break", "%S+") do - stat_call[v] = v.."_stat" - end - -------------------------------------------------------------------- - local binopr_left = {} -- binary operators, left priority - local binopr_right = {} -- binary operators, right priority - for op, lt, rt in string.gfind([[ -{+ 6 6}{- 6 6}{* 7 7}{/ 7 7}{^ 10 9}{.. 5 4} -{~= 3 3}{== 3 3}{< 3 3}{<= 3 3}{> 3 3}{>= 3 3} -{and 2 2}{or 1 1} -]], "{(%S+)%s(%d+)%s(%d+)}") do - binopr_left[op] = lt + 0 - binopr_right[op] = rt + 0 - end - local unopr = { ["not"] = true, ["-"] = true, } -- unary operators - ---[[-------------------------------------------------------------------- --- logging: this logging function is for educational purposes --- * logged data can be retrieved from the returned data structure --- * or, replace self:log() instances with your custom code... -----------------------------------------------------------------------]] - - function luaY:log(msg) - local log = top_fs.log - if not log then log = {}; top_fs.log = log end - table.insert(top_fs.log, msg) - end - ---[[-------------------------------------------------------------------- --- support functions -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- reads in next token - -------------------------------------------------------------------- - function luaY:next() - lastln = luaX.ln - if peek_tok then -- is there a look-ahead token? if yes, use it - tok, seminfo = peek_tok, peek_sem - peek_tok = nil - else - tok, seminfo = luaX:lex() -- read next token - end - end - -------------------------------------------------------------------- - -- peek at next token (single lookahead for table constructor) - -------------------------------------------------------------------- - function luaY:lookahead() - peek_tok, peek_sem = luaX:lex() - return peek_tok - end - - ------------------------------------------------------------------------ - -- throws a syntax error - ------------------------------------------------------------------------ - function luaY:syntaxerror(msg) - local tok = tok - if tok ~= "" and tok ~= "" then - if tok == "" then tok = seminfo end - tok = "'"..tok.."'" - end - luaX:errorline(msg.." near "..tok) - end - -------------------------------------------------------------------- - -- throws a syntax error if token expected is not there - -------------------------------------------------------------------- - function luaY:error_expected(token) - self:syntaxerror("'"..token.."' expected") - end - - -------------------------------------------------------------------- - -- verifies token conditions are met or else throw error - -------------------------------------------------------------------- - function luaY:check_match(what, who, where) - if not self:testnext(what) then - if where == luaX.ln then - self:error_expected(what) - else - self:syntaxerror("'"..what.."' expected (to close '"..who.."' at line "..where..")") - end - end - end - -------------------------------------------------------------------- - -- tests for a token, returns outcome - -- * return value changed to boolean - -------------------------------------------------------------------- - function luaY:testnext(c) - if tok == c then self:next(); return true end - end - -------------------------------------------------------------------- - -- throws error if condition not matched - -------------------------------------------------------------------- - function luaY:check_condition(c, msg) - if not c then self:syntaxerror(msg) end - end - -------------------------------------------------------------------- - -- check for existence of a token, throws error if not found - -------------------------------------------------------------------- - function luaY:check(c) - if not self:testnext(c) then self:error_expected(c) end - end - - -------------------------------------------------------------------- - -- expect that token is a name, return the name - -------------------------------------------------------------------- - function luaY:str_checkname() - self:check_condition(tok == "", " expected") - local ts = seminfo - self:next() - self:log(" str_checkname: '"..ts.."'") - return ts - end - -------------------------------------------------------------------- - -- adds given string s in string pool, sets e as VK - -------------------------------------------------------------------- - function luaY:codestring(e, s) - e.k = "VK" - self:log(" codestring: "..string.format("%q", s)) - end - -------------------------------------------------------------------- - -- consume a name token, adds it to string pool - -------------------------------------------------------------------- - function luaY:checkname(e) - self:log(" checkname:") - self:codestring(e, self:str_checkname()) - end - ---[[-------------------------------------------------------------------- --- state management functions with open/close pairs -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- enters a code unit, initializes elements - -------------------------------------------------------------------- - function luaY:enterblock(isbreakable) - local bl = {} -- per-block state - bl.isbreakable = isbreakable - bl.prev = fs.bl - fs.bl = bl - self:log(">> enterblock(isbreakable="..tostring(isbreakable)..")") - end - -------------------------------------------------------------------- - -- leaves a code unit, close any upvalues - -------------------------------------------------------------------- - function luaY:leaveblock() - local bl = fs.bl - fs.bl = bl.prev - self:log("<< leaveblock") - end - -------------------------------------------------------------------- - -- opening of a function - -------------------------------------------------------------------- - function luaY:open_func() - local new_fs -- per-function state - if not fs then -- top_fs is created early - new_fs = top_fs - else - new_fs = {} - end - new_fs.prev = fs -- linked list of function states - new_fs.bl = nil - fs = new_fs - self:log(">> open_func") - end - -------------------------------------------------------------------- - -- closing of a function - -------------------------------------------------------------------- - function luaY:close_func() - fs = fs.prev - self:log("<< close_func") - end - ---[[-------------------------------------------------------------------- --- variable (global|local|upvalue) handling --- * does nothing for now, always returns "VLOCAL" -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- consume a name token, creates a variable (global|local|upvalue) - -- * used in prefixexp(), funcname() - -------------------------------------------------------------------- - function luaY:singlevar(v) - local varname = self:str_checkname() - v.k = "VLOCAL" - self:log(" singlevar: name='"..varname.."'") - end - ---[[-------------------------------------------------------------------- --- other parsing functions --- * for table constructor, parameter list, argument list -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- parse a function name suffix, for function call specifications - -- * used in primaryexp(), funcname() - -------------------------------------------------------------------- - function luaY:field(v) - -- field -> ['.' | ':'] NAME - local key = {} - self:log(" field: operator="..tok) - self:next() -- skip the dot or colon - self:checkname(key) - v.k = "VINDEXED" - end - -------------------------------------------------------------------- - -- parse a table indexing suffix, for constructors, expressions - -- * used in recfield(), primaryexp() - -------------------------------------------------------------------- - function luaY:index(v) - -- index -> '[' expr ']' - self:log(">> index: begin '['") - self:next() -- skip the '[' - self:expr(v) - self:check("]") - self:log("<< index: end ']'") - end - -------------------------------------------------------------------- - -- parse a table record (hash) field - -- * used in constructor() - -------------------------------------------------------------------- - function luaY:recfield(cc) - -- recfield -> (NAME | '['exp1']') = exp1 - local key, val = {}, {} - if tok == "" then - self:log("recfield: name") - self:checkname(key) - else-- tok == '[' - self:log("recfield: [ exp1 ]") - self:index(key) - end - self:check("=") - self:expr(val) - end - -------------------------------------------------------------------- - -- emit a set list instruction if enough elements (LFIELDS_PER_FLUSH) - -- * note: retained in this skeleton because it modifies cc.v.k - -- * used in constructor() - -------------------------------------------------------------------- - function luaY:closelistfield(cc) - if cc.v.k == "VVOID" then return end -- there is no list item - cc.v.k = "VVOID" - end - -------------------------------------------------------------------- - -- parse a table list (array) field - -- * used in constructor() - -------------------------------------------------------------------- - function luaY:listfield(cc) - self:log("listfield: expr") - self:expr(cc.v) - end - -------------------------------------------------------------------- - -- parse a table constructor - -- * used in funcargs(), simpleexp() - -------------------------------------------------------------------- - function luaY:constructor(t) - -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}' - -- field -> recfield | listfield - -- fieldsep -> ',' | ';' - self:log(">> constructor: begin") - local line = luaX.ln - local cc = {} - cc.v = {} - cc.t = t - t.k = "VRELOCABLE" - cc.v.k = "VVOID" - self:check("{") - repeat - self:testnext(";") -- compatibility only - if tok == "}" then break end - -- closelistfield(cc) here - local c = tok - if c == "" then -- may be listfields or recfields - if self:lookahead() ~= "=" then -- look ahead: expression? - self:listfield(cc) - else - self:recfield(cc) - end - elseif c == "[" then -- constructor_item -> recfield - self:recfield(cc) - else -- constructor_part -> listfield - self:listfield(cc) - end - until not self:testnext(",") and not self:testnext(";") - self:check_match("}", "{", line) - -- lastlistfield(cc) here - self:log("<< constructor: end") - end - -------------------------------------------------------------------- - -- parse the arguments (parameters) of a function declaration - -- * used in body() - -------------------------------------------------------------------- - function luaY:parlist() - -- parlist -> [ param { ',' param } ] - self:log(">> parlist: begin") - local dots = false - if tok ~= ")" then -- is 'parlist' not empty? - repeat - local c = tok - if c == "..." then - self:log("parlist: ... (dots)") - dots = true - self:next() - elseif c == "" then - local str = self:str_checkname() - else - self:syntaxerror(" or '...' expected") - end - until dots or not self:testnext(",") - end - self:log("<< parlist: end") - end - -------------------------------------------------------------------- - -- parse the parameters of a function call - -- * contrast with parlist(), used in function declarations - -- * used in primaryexp() - -------------------------------------------------------------------- - function luaY:funcargs(f) - local args = {} - local line = luaX.ln - local c = tok - if c == "(" then -- funcargs -> '(' [ explist1 ] ')' - self:log(">> funcargs: begin '('") - if line ~= lastln then - self:syntaxerror("ambiguous syntax (function call x new statement)") - end - self:next() - if tok == ")" then -- arg list is empty? - args.k = "VVOID" - else - self:explist1(args) - end - self:check_match(")", "(", line) - elseif c == "{" then -- funcargs -> constructor - self:log(">> funcargs: begin '{'") - self:constructor(args) - elseif c == "" then -- funcargs -> STRING - self:log(">> funcargs: begin ") - self:codestring(args, seminfo) - self:next() -- must use 'seminfo' before 'next' - else - self:syntaxerror("function arguments expected") - return - end--if c - f.k = "VCALL" - self:log("<< funcargs: end -- expr is a VCALL") - end - ---[[-------------------------------------------------------------------- --- mostly expression functions -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- parses an expression in parentheses or a single variable - -- * used in primaryexp() - -------------------------------------------------------------------- - function luaY:prefixexp(v) - -- prefixexp -> NAME | '(' expr ')' - local c = tok - if c == "(" then - self:log(">> prefixexp: begin ( expr ) ") - local line = self.ln - self:next() - self:expr(v) - self:check_match(")", "(", line) - self:log("<< prefixexp: end ( expr ) ") - elseif c == "" then - self:log("prefixexp: ") - self:singlevar(v) - else - self:syntaxerror("unexpected symbol") - end--if c - end - -------------------------------------------------------------------- - -- parses a prefixexp (an expression in parentheses or a single - -- variable) or a function call specification - -- * used in simpleexp(), assignment(), expr_stat() - -------------------------------------------------------------------- - function luaY:primaryexp(v) - -- primaryexp -> - -- prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } - self:prefixexp(v) - while true do - local c = tok - if c == "." then -- field - self:log("primaryexp: '.' field") - self:field(v) - elseif c == "[" then -- '[' exp1 ']' - self:log("primaryexp: [ exp1 ]") - local key = {} - self:index(key) - elseif c == ":" then -- ':' NAME funcargs - self:log("primaryexp: : funcargs") - local key = {} - self:next() - self:checkname(key) - self:funcargs(v) - elseif c == "(" or c == "" or c == "{" then -- funcargs - self:log("primaryexp: "..c.." funcargs") - self:funcargs(v) - else - return - end--if c - end--while - end - -------------------------------------------------------------------- - -- parses general expression types, constants handled here - -- * used in subexpr() - -------------------------------------------------------------------- - function luaY:simpleexp(v) - -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | constructor - -- | FUNCTION body | primaryexp - local c = tok - if c == "" then - self:log("simpleexp: ="..seminfo) - v.k = "VK" - self:next() -- must use 'seminfo' before 'next' - elseif c == "" then - self:log("simpleexp: ="..seminfo) - self:codestring(v, seminfo) - self:next() -- must use 'seminfo' before 'next' - elseif c == "nil" then - self:log("simpleexp: nil") - v.k = "VNIL" - self:next() - elseif c == "true" then - self:log("simpleexp: true") - v.k = "VTRUE" - self:next() - elseif c == "false" then - self:log("simpleexp: false") - v.k = "VFALSE" - self:next() - elseif c == "{" then -- constructor - self:log("simpleexp: constructor") - self:constructor(v) - elseif c == "function" then - self:log("simpleexp: function") - self:next() - self:body(v, false, luaX.ln) - else - self:primaryexp(v) - end--if c - end - ------------------------------------------------------------------------ - -- Parse subexpressions. Includes handling of unary operators and binary - -- operators. A subexpr is given the rhs priority level of the operator - -- immediately left of it, if any (limit is -1 if none,) and if a binop - -- is found, limit is compared with the lhs priority level of the binop - -- in order to determine which executes first. - -- * recursively called - -- * used in expr() - ------------------------------------------------------------------------ - function luaY:subexpr(v, limit) - -- subexpr -> (simpleexp | unop subexpr) { binop subexpr } - -- * where 'binop' is any binary operator with a priority - -- higher than 'limit' - local op = tok - local uop = unopr[op] - if uop then - self:log(" subexpr: uop='"..op.."'") - self:next() - self:subexpr(v, 8) -- UNARY_PRIORITY - else - self:simpleexp(v) - end - -- expand while operators have priorities higher than 'limit' - op = tok - local binop = binopr_left[op] - while binop and binop > limit do - local v2 = {} - self:log(">> subexpr: binop='"..op.."'") - self:next() - -- read sub-expression with higher priority - local nextop = self:subexpr(v2, binopr_right[op]) - self:log("<< subexpr: -- evaluate") - op = nextop - binop = binopr_left[op] - end - return op -- return first untreated operator - end - -------------------------------------------------------------------- - -- Expression parsing starts here. Function subexpr is entered with the - -- left operator (which is non-existent) priority of -1, which is lower - -- than all actual operators. Expr information is returned in parm v. - -- * used in cond(), explist1(), index(), recfield(), listfield(), - -- prefixexp(), while_stat(), exp1() - -------------------------------------------------------------------- - function luaY:expr(v) - -- expr -> subexpr - self:log("expr:") - self:subexpr(v, -1) - end - ---[[-------------------------------------------------------------------- --- third level parsing functions -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- parse a variable assignment sequence - -- * recursively called - -- * used in expr_stat() - -------------------------------------------------------------------- - function luaY:assignment(v) - local e = {} - local c = v.v.k - self:check_condition(c == "VLOCAL" or c == "VUPVAL" or c == "VGLOBAL" - or c == "VINDEXED", "syntax error") - if self:testnext(",") then -- assignment -> ',' primaryexp assignment - local nv = {} -- expdesc - nv.v = {} - self:log("assignment: ',' -- next LHS element") - self:primaryexp(nv.v) - -- lparser.c deals with some register usage conflict here - self:assignment(nv) - else -- assignment -> '=' explist1 - self:check("=") - self:log("assignment: '=' -- RHS elements follows") - self:explist1(e) - return -- avoid default - end - e.k = "VNONRELOC" - end - -------------------------------------------------------------------- - -- parse a for loop body for both versions of the for loop - -- * used in fornum(), forlist() - -------------------------------------------------------------------- - function luaY:forbody(line, isnum) - self:check("do") - self:enterblock(true) -- loop block - self:block() - self:leaveblock() - end - -------------------------------------------------------------------- - -- parse a numerical for loop, calls forbody() - -- * used in for_stat() - -------------------------------------------------------------------- - function luaY:fornum(line) - -- fornum -> NAME = exp1, exp1 [, exp1] DO body - self:log(">> fornum: begin") - self:check("=") - self:log("fornum: index start") - self:exp1() -- initial value - self:check(",") - self:log("fornum: index stop") - self:exp1() -- limit - if self:testnext(",") then - self:log("fornum: index step") - self:exp1() -- optional step - else - -- default step = 1 - end - self:log("fornum: body") - self:forbody(line, true) - self:log("<< fornum: end") - end - -------------------------------------------------------------------- - -- parse a generic for loop, calls forbody() - -- * used in for_stat() - -------------------------------------------------------------------- - function luaY:forlist() - -- forlist -> NAME {, NAME} IN explist1 DO body - self:log(">> forlist: begin") - local e = {} - while self:testnext(",") do - self:str_checkname() - end - self:check("in") - local line = line - self:log("forlist: explist1") - self:explist1(e) - self:log("forlist: body") - self:forbody(line, false) - self:log("<< forlist: end") - end - -------------------------------------------------------------------- - -- parse a function name specification - -- * used in func_stat() - -------------------------------------------------------------------- - function luaY:funcname(v) - -- funcname -> NAME {field} [':' NAME] - self:log(">> funcname: begin") - local needself = false - self:singlevar(v) - while tok == "." do - self:log("funcname: -- '.' field") - self:field(v) - end - if tok == ":" then - self:log("funcname: -- ':' field") - needself = true - self:field(v) - end - self:log("<< funcname: end") - return needself - end - -------------------------------------------------------------------- - -- parse the single expressions needed in numerical for loops - -- * used in fornum() - -------------------------------------------------------------------- - function luaY:exp1() - -- exp1 -> expr - local e = {} - self:log(">> exp1: begin") - self:expr(e) - self:log("<< exp1: end") - end - -------------------------------------------------------------------- - -- parse condition in a repeat statement or an if control structure - -- * used in repeat_stat(), test_then_block() - -------------------------------------------------------------------- - function luaY:cond(v) - -- cond -> expr - self:log(">> cond: begin") - self:expr(v) -- read condition - self:log("<< cond: end") - end - -------------------------------------------------------------------- - -- parse part of an if control structure, including the condition - -- * used in if_stat() - -------------------------------------------------------------------- - function luaY:test_then_block(v) - -- test_then_block -> [IF | ELSEIF] cond THEN block - self:next() -- skip IF or ELSEIF - self:log("test_then_block: test condition") - self:cond(v) - self:check("then") - self:log("test_then_block: then block") - self:block() -- 'then' part - end - -------------------------------------------------------------------- - -- parse a local function statement - -- * used in local_stat() - -------------------------------------------------------------------- - function luaY:localfunc() - -- localfunc -> NAME body - local v, b = {} - self:log("localfunc: begin") - local str = self:str_checkname() - v.k = "VLOCAL" - self:log("localfunc: body") - self:body(b, false, luaX.ln) - self:log("localfunc: end") - end - -------------------------------------------------------------------- - -- parse a local variable declaration statement - -- * used in local_stat() - -------------------------------------------------------------------- - function luaY:localstat() - -- localstat -> NAME {',' NAME} ['=' explist1] - self:log(">> localstat: begin") - local e = {} - repeat - local str = self:str_checkname() - until not self:testnext(",") - if self:testnext("=") then - self:log("localstat: -- assignment") - self:explist1(e) - else - e.k = "VVOID" - end - self:log("<< localstat: end") - end - -------------------------------------------------------------------- - -- parse a list of comma-separated expressions - -- * used in return_stat(), localstat(), funcargs(), assignment(), - -- forlist() - -------------------------------------------------------------------- - function luaY:explist1(e) - -- explist1 -> expr { ',' expr } - self:log(">> explist1: begin") - self:expr(e) - while self:testnext(",") do - self:log("explist1: ',' -- continuation") - self:expr(e) - end - self:log("<< explist1: end") - end - -------------------------------------------------------------------- - -- parse function declaration body - -- * used in simpleexp(), localfunc(), func_stat() - -------------------------------------------------------------------- - function luaY:body(e, needself, line) - -- body -> '(' parlist ')' chunk END - self:open_func() - self:log("body: begin") - self:check("(") - if needself then - -- handle 'self' processing here - end - self:log("body: parlist") - self:parlist() - self:check(")") - self:log("body: chunk") - self:chunk() - self:check_match("end", "function", line) - self:log("body: end") - self:close_func() - end - -------------------------------------------------------------------- - -- parse a code block or unit - -- * used in do_stat(), while_stat(), repeat_stat(), forbody(), - -- test_then_block(), if_stat() - -------------------------------------------------------------------- - function luaY:block() - -- block -> chunk - self:log("block: begin") - self:enterblock(false) - self:chunk() - self:leaveblock() - self:log("block: end") - end - ---[[-------------------------------------------------------------------- --- second level parsing functions, all with '_stat' suffix --- * stat() -> *_stat() -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- initial parsing for a for loop, calls fornum() or forlist() - -- * used in stat() - -------------------------------------------------------------------- - function luaY:for_stat() - -- stat -> for_stat -> fornum | forlist - local line = line - self:log("for_stat: begin") - self:enterblock(false) -- block to control variable scope - self:next() -- skip 'for' - local str = self:str_checkname() -- first variable name - local c = tok - if c == "=" then - self:log("for_stat: numerical loop") - self:fornum(line) - elseif c == "," or c == "in" then - self:log("for_stat: list-based loop") - self:forlist() - else - self:syntaxerror("'=' or 'in' expected") - end - self:check_match("end", "for", line) - self:leaveblock() - self:log("for_stat: end") - end - -------------------------------------------------------------------- - -- parse a while-do control structure, body processed by block() - -- * used in stat() - -------------------------------------------------------------------- - function luaY:while_stat() - -- stat -> while_stat -> WHILE cond DO block END - local line = line - local v = {} - self:next() -- skip WHILE - self:log("while_stat: begin/condition") - self:expr(v) -- parse condition - self:enterblock(true) - self:check("do") - self:log("while_stat: block") - self:block() - self:check_match("end", "while", line) - self:leaveblock() - self:log("while_stat: end") - end - -------------------------------------------------------------------- - -- parse a repeat-until control structure, body parsed by block() - -- * used in stat() - -------------------------------------------------------------------- - function luaY:repeat_stat() - -- stat -> repeat_stat -> REPEAT block UNTIL cond - local line = line - local v = {} - self:log("repeat_stat: begin") - self:enterblock(true) - self:next() - self:block() - self:check_match("until", "repeat", line) - self:log("repeat_stat: condition") - self:cond(v) - self:leaveblock() - self:log("repeat_stat: end") - end - -------------------------------------------------------------------- - -- parse an if control structure - -- * used in stat() - -------------------------------------------------------------------- - function luaY:if_stat() - -- stat -> if_stat -> IF cond THEN block - -- {ELSEIF cond THEN block} [ELSE block] END - local line = line - local v = {} - self:log("if_stat: if...then") - self:test_then_block(v) -- IF cond THEN block - while tok == "elseif" do - self:log("if_stat: elseif...then") - self:test_then_block(v) -- ELSEIF cond THEN block - end - if tok == "else" then - self:log("if_stat: else...") - self:next() -- skip ELSE - self:block() -- 'else' part - end - self:check_match("end", "if", line) - self:log("if_stat: end") - end - -------------------------------------------------------------------- - -- parse a return statement - -- * used in stat() - -------------------------------------------------------------------- - function luaY:return_stat() - -- stat -> return_stat -> RETURN explist - local e = {} - self:next() -- skip RETURN - local c = tok - if block_follow[c] or c == ";" then - -- return no values - self:log("return_stat: no return values") - else - self:log("return_stat: begin") - self:explist1(e) -- optional return values - self:log("return_stat: end") - end - end - -------------------------------------------------------------------- - -- parse a break statement - -- * used in stat() - -------------------------------------------------------------------- - function luaY:break_stat() - -- stat -> break_stat -> BREAK - local bl = fs.bl - self:next() -- skip BREAK - while bl and not bl.isbreakable do -- find a breakable block - bl = bl.prev - end - if not bl then - self:syntaxerror("no loop to break") - end - self:log("break_stat: -- break out of loop") - end - -------------------------------------------------------------------- - -- parse a function call with no returns or an assignment statement - -- * the struct with .prev is used for name searching in lparse.c, - -- so it is retained for now; present in assignment() also - -- * used in stat() - -------------------------------------------------------------------- - function luaY:expr_stat() - -- stat -> expr_stat -> func | assignment - local v = {} - v.v = {} - self:primaryexp(v.v) - if v.v.k == "VCALL" then -- stat -> func - -- call statement uses no results - self:log("expr_stat: function call k='"..v.v.k.."'") - else -- stat -> assignment - self:log("expr_stat: assignment k='"..v.v.k.."'") - v.prev = nil - self:assignment(v) - end - end - -------------------------------------------------------------------- - -- parse a function statement - -- * used in stat() - -------------------------------------------------------------------- - function luaY:function_stat() - -- stat -> function_stat -> FUNCTION funcname body - local line = line - local v, b = {}, {} - self:log("function_stat: begin") - self:next() -- skip FUNCTION - local needself = self:funcname(v) - self:log("function_stat: body needself='"..tostring(needself).."'") - self:body(b, needself, line) - self:log("function_stat: end") - end - -------------------------------------------------------------------- - -- parse a simple block enclosed by a DO..END pair - -- * used in stat() - -------------------------------------------------------------------- - function luaY:do_stat() - -- stat -> do_stat -> DO block END - self:next() -- skip DO - self:log("do_stat: begin") - self:block() - self:log("do_stat: end") - self:check_match("end", "do", line) - end - -------------------------------------------------------------------- - -- parse a statement starting with LOCAL - -- * used in stat() - -------------------------------------------------------------------- - function luaY:local_stat() - -- stat -> local_stat -> LOCAL FUNCTION localfunc - -- -> LOCAL localstat - self:next() -- skip LOCAL - if self:testnext("function") then -- local function? - self:log("local_stat: local function") - self:localfunc() - else - self:log("local_stat: local statement") - self:localstat() - end - end - ---[[-------------------------------------------------------------------- --- main function, top level parsing functions --- * [entry] -> parser() -> chunk() -> stat() -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- initial parsing for statements, calls '_stat' suffixed functions - -- * used in chunk() - -------------------------------------------------------------------- - function luaY:stat() - line = luaX.ln - local c = tok - local fn = stat_call[c] - -- handles: if while do for repeat function local return break - if fn then - self:log("-- STATEMENT: begin '"..c.."' line="..line) - self[fn](self) - self:log("-- STATEMENT: end '"..c.."'") - -- return or break must be last statement - if c == "return" or c == "break" then return true end - else - self:log("-- STATEMENT: begin 'expr' line="..line) - self:expr_stat() - self:log("-- STATEMENT: end 'expr'") - end - self:log("") - return false - end - -------------------------------------------------------------------- - -- parse a chunk, which consists of a bunch of statements - -- * used in parser(), body(), block() - -------------------------------------------------------------------- - function luaY:chunk() - -- chunk -> { stat [';'] } - self:log("chunk:") - local islast = false - while not islast and not block_follow[tok] do - islast = self:stat() - self:testnext(";") - end - end - -------------------------------------------------------------------- - -- performs parsing, returns parsed data structure - -------------------------------------------------------------------- - function luaY:parser() - self:log("-- TOP: begin") - self:open_func() - self:log("") - self:next() -- read first token - self:chunk() - self:check_condition(tok == "", " expected") - self:close_func() - self:log("-- TOP: end") - return top_fs - end - -------------------------------------------------------------------- - return luaY -- return actual module to user, done -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3b.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3b.lua deleted file mode 100644 index a46edc6..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lparser_mk3b.lua +++ /dev/null @@ -1,1121 +0,0 @@ ---[[-------------------------------------------------------------------- - - lparser.lua - Lua 5 parser in Lua - This file is part of Yueliang. - - Copyright (c) 2008 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * this is a Lua 5.0.x parser skeleton, for llex_mk3.lua lexer --- * written as a module factory with recognizable lparser.c roots --- * builds some data, performs logging for educational purposes --- * target is to have relatively efficient and clear code --- * needs one parameter, a lexer module that implements: --- luaX:lex() - returns appropriate [token, semantic info] pairs --- luaX.ln - current line number --- luaX:errorline(s, [line]) - dies with error message --- --- Usage example: --- lex_init = require("llex_mk3.lua") --- parser_init = require("lparser_mk3.lua") --- local luaX = lex_init(chunk, "=string") --- local luaY = parser_init(luaX) --- local fs = luaY:parser() --- --- Development notes: --- * see test_parser-5.0.lua for grammar elements based on lparser.c --- * lparser has a few extra items to help parsing/syntax checking --- (a) line number (error reporting), lookahead token storage --- (b) per-prototype states needs a storage list --- (c) 'break' needs a per-block flag in a stack --- (d) 'kind' (v.k) testing needed in expr_stat() and assignment() --- for disambiguation, thus v.k manipulation is retained --- (e) one line # var (lastln) for ambiguous (split line) function --- call checking --- (f) most line number function call args retained for future use --- (g) Lua 4 compatibility code completely removed --- (h) minimal variable management code to differentiate each type --- * parsing starts from the end of this file in luaY:parser() --- -----------------------------------------------------------------------]] - -return -function(luaX) ---[[-------------------------------------------------------------------- --- structures and data initialization -----------------------------------------------------------------------]] - - local line -- start line # for error messages - local lastln -- last line # for ambiguous syntax chk - local tok, seminfo -- token, semantic info pair - local peek_tok, peek_sem -- ditto, for lookahead - local fs -- function state - local top_fs = {} -- top-level function state - local luaY = {} - -------------------------------------------------------------------- - local block_follow = {} -- lookahead check in chunk(), returnstat() - for v in string.gfind("else elseif end until ", "%S+") do - block_follow[v] = true - end - -------------------------------------------------------------------- - local stat_call = {} -- lookup for calls in stat() - for v in string.gfind("if while do for repeat function local return break", "%S+") do - stat_call[v] = v.."_stat" - end - -------------------------------------------------------------------- - local binopr_left = {} -- binary operators, left priority - local binopr_right = {} -- binary operators, right priority - for op, lt, rt in string.gfind([[ -{+ 6 6}{- 6 6}{* 7 7}{/ 7 7}{^ 10 9}{.. 5 4} -{~= 3 3}{== 3 3}{< 3 3}{<= 3 3}{> 3 3}{>= 3 3} -{and 2 2}{or 1 1} -]], "{(%S+)%s(%d+)%s(%d+)}") do - binopr_left[op] = lt + 0 - binopr_right[op] = rt + 0 - end - local unopr = { ["not"] = true, ["-"] = true, } -- unary operators - ---[[-------------------------------------------------------------------- --- logging: this logging function is for educational purposes --- * logged data can be retrieved from the returned data structure --- * or, replace self:log() instances with your custom code... -----------------------------------------------------------------------]] - - function luaY:log(msg) - local log = top_fs.log - if not log then log = {}; top_fs.log = log end - table.insert(top_fs.log, msg) - end - ---[[-------------------------------------------------------------------- --- support functions -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- reads in next token - -------------------------------------------------------------------- - function luaY:next() - lastln = luaX.ln - if peek_tok then -- is there a look-ahead token? if yes, use it - tok, seminfo = peek_tok, peek_sem - peek_tok = nil - else - tok, seminfo = luaX:lex() -- read next token - end - end - -------------------------------------------------------------------- - -- peek at next token (single lookahead for table constructor) - -------------------------------------------------------------------- - function luaY:lookahead() - peek_tok, peek_sem = luaX:lex() - return peek_tok - end - - ------------------------------------------------------------------------ - -- throws a syntax error - ------------------------------------------------------------------------ - function luaY:syntaxerror(msg) - local tok = tok - if tok ~= "" and tok ~= "" then - if tok == "" then tok = seminfo end - tok = "'"..tok.."'" - end - luaX:errorline(msg.." near "..tok) - end - -------------------------------------------------------------------- - -- throws a syntax error if token expected is not there - -------------------------------------------------------------------- - function luaY:error_expected(token) - self:syntaxerror("'"..token.."' expected") - end - - -------------------------------------------------------------------- - -- verifies token conditions are met or else throw error - -------------------------------------------------------------------- - function luaY:check_match(what, who, where) - if not self:testnext(what) then - if where == luaX.ln then - self:error_expected(what) - else - self:syntaxerror("'"..what.."' expected (to close '"..who.."' at line "..where..")") - end - end - end - -------------------------------------------------------------------- - -- tests for a token, returns outcome - -- * return value changed to boolean - -------------------------------------------------------------------- - function luaY:testnext(c) - if tok == c then self:next(); return true end - end - -------------------------------------------------------------------- - -- throws error if condition not matched - -------------------------------------------------------------------- - function luaY:check_condition(c, msg) - if not c then self:syntaxerror(msg) end - end - -------------------------------------------------------------------- - -- check for existence of a token, throws error if not found - -------------------------------------------------------------------- - function luaY:check(c) - if not self:testnext(c) then self:error_expected(c) end - end - - -------------------------------------------------------------------- - -- expect that token is a name, return the name - -------------------------------------------------------------------- - function luaY:str_checkname() - self:check_condition(tok == "", " expected") - local ts = seminfo - self:next() - self:log(" str_checkname: '"..ts.."'") - return ts - end - -------------------------------------------------------------------- - -- adds given string s in string pool, sets e as VK - -------------------------------------------------------------------- - function luaY:codestring(e, s) - e.k = "VK" - self:log(" codestring: "..string.format("%q", s)) - end - -------------------------------------------------------------------- - -- consume a name token, adds it to string pool - -------------------------------------------------------------------- - function luaY:checkname(e) - self:log(" checkname:") - self:codestring(e, self:str_checkname()) - end - ---[[-------------------------------------------------------------------- --- state management functions with open/close pairs -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- enters a code unit, initializes elements - -------------------------------------------------------------------- - function luaY:enterblock(isbreakable) - local bl = {} -- per-block state - bl.isbreakable = isbreakable - bl.prev = fs.bl - bl.locallist = {} - fs.bl = bl - self:log(">> enterblock(isbreakable="..tostring(isbreakable)..")") - end - -------------------------------------------------------------------- - -- leaves a code unit, close any upvalues - -------------------------------------------------------------------- - function luaY:leaveblock() - local bl = fs.bl - fs.bl = bl.prev - self:log("<< leaveblock") - end - -------------------------------------------------------------------- - -- opening of a function - -------------------------------------------------------------------- - function luaY:open_func() - local new_fs -- per-function state - if not fs then -- top_fs is created early - new_fs = top_fs - else - new_fs = {} - end - new_fs.prev = fs -- linked list of function states - new_fs.bl = nil - new_fs.locallist = {} - fs = new_fs - self:log(">> open_func") - end - -------------------------------------------------------------------- - -- closing of a function - -------------------------------------------------------------------- - function luaY:close_func() - fs = fs.prev - self:log("<< close_func") - end - ---[[-------------------------------------------------------------------- --- variable (global|local|upvalue) handling --- * a pure parser does not really need this, but if we want to produce --- useful output, might as well write minimal code to manage this... --- * entry point is singlevar() for variable lookups --- * three entry points for local variable creation, in order to keep --- to original C calls, but the extra arguments such as positioning --- are removed as we are not allocating registers -- we are only --- doing simple classification --- * lookup tables (bl.locallist) are maintained awkwardly in the basic --- block data structures, PLUS the function data structure (this is --- an inelegant hack, since bl is nil for the top level of a function) -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- register a local variable, set in active variable list - -- * used in new_localvarstr(), parlist(), fornum(), forlist(), - -- localfunc(), localstat() - -------------------------------------------------------------------- - function luaY:new_localvar(name) - local bl = fs.bl - local locallist - if bl then - locallist = bl.locallist - else - locallist = fs.locallist - end - locallist[name] = true - self:log(" new_localvar: '"..name.."'") - end - -------------------------------------------------------------------- - -- creates a new local variable given a name - -- * used in fornum(), forlist() for loop variables; in create_local() - -------------------------------------------------------------------- - function luaY:new_localvarstr(name) - self:new_localvar(name) - end - -------------------------------------------------------------------- - -- creates a single local variable and activates it - -- * used only in code_params() for "arg", body() for "self" - -------------------------------------------------------------------- - function luaY:create_local(name) - self:new_localvarstr(name) - end - - -------------------------------------------------------------------- - -- search the local variable namespace of the given fs for a match - -- * a simple lookup only, no active variable list kept, so no useful - -- index value can be returned by this function - -- * used only in singlevaraux() - -------------------------------------------------------------------- - function luaY:searchvar(fs, n) - local bl = fs.bl - if bl then - locallist = bl.locallist - while locallist do - if locallist[n] then return 1 end -- found - bl = bl.prev - locallist = bl and bl.locallist - end - end - locallist = fs.locallist - if locallist[n] then return 1 end -- found - return -1 -- not found - end - -------------------------------------------------------------------- - -- handle locals, globals and upvalues and related processing - -- * search mechanism is recursive, calls itself to search parents - -- * used only in singlevar() - -------------------------------------------------------------------- - function luaY:singlevaraux(fs, n, var, base) - if fs == nil then -- no more levels? - var.k = "VGLOBAL" -- default is global variable - else - local v = self:searchvar(fs, n) -- look up at current level - if v >= 0 then - var.k = "VLOCAL" - else -- not found at current level; try upper one - self:singlevaraux(fs.prev, n, var, 0) - if var.k == "VGLOBAL" then - -- handle global var processing here - else -- LOCAL or UPVAL - var.k = "VUPVAL" - end - end--if v - end--if fs - end - -------------------------------------------------------------------- - -- consume a name token, creates a variable (global|local|upvalue) - -- * used in prefixexp(), funcname() - -------------------------------------------------------------------- - function luaY:singlevar(v) - local varname = self:str_checkname() - self:singlevaraux(fs, varname, v, 1) - self:log(" singlevar(kind): '"..v.k.."'") - end - ---[[-------------------------------------------------------------------- --- other parsing functions --- * for table constructor, parameter list, argument list -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- parse a function name suffix, for function call specifications - -- * used in primaryexp(), funcname() - -------------------------------------------------------------------- - function luaY:field(v) - -- field -> ['.' | ':'] NAME - local key = {} - self:log(" field: operator="..tok) - self:next() -- skip the dot or colon - self:checkname(key) - v.k = "VINDEXED" - end - -------------------------------------------------------------------- - -- parse a table indexing suffix, for constructors, expressions - -- * used in recfield(), primaryexp() - -------------------------------------------------------------------- - function luaY:index(v) - -- index -> '[' expr ']' - self:log(">> index: begin '['") - self:next() -- skip the '[' - self:expr(v) - self:check("]") - self:log("<< index: end ']'") - end - -------------------------------------------------------------------- - -- parse a table record (hash) field - -- * used in constructor() - -------------------------------------------------------------------- - function luaY:recfield(cc) - -- recfield -> (NAME | '['exp1']') = exp1 - local key, val = {}, {} - if tok == "" then - self:log("recfield: name") - self:checkname(key) - else-- tok == '[' - self:log("recfield: [ exp1 ]") - self:index(key) - end - self:check("=") - self:expr(val) - end - -------------------------------------------------------------------- - -- emit a set list instruction if enough elements (LFIELDS_PER_FLUSH) - -- * note: retained in this skeleton because it modifies cc.v.k - -- * used in constructor() - -------------------------------------------------------------------- - function luaY:closelistfield(cc) - if cc.v.k == "VVOID" then return end -- there is no list item - cc.v.k = "VVOID" - end - -------------------------------------------------------------------- - -- parse a table list (array) field - -- * used in constructor() - -------------------------------------------------------------------- - function luaY:listfield(cc) - self:log("listfield: expr") - self:expr(cc.v) - end - -------------------------------------------------------------------- - -- parse a table constructor - -- * used in funcargs(), simpleexp() - -------------------------------------------------------------------- - function luaY:constructor(t) - -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}' - -- field -> recfield | listfield - -- fieldsep -> ',' | ';' - self:log(">> constructor: begin") - local line = luaX.ln - local cc = {} - cc.v = {} - cc.t = t - t.k = "VRELOCABLE" - cc.v.k = "VVOID" - self:check("{") - repeat - self:testnext(";") -- compatibility only - if tok == "}" then break end - -- closelistfield(cc) here - local c = tok - if c == "" then -- may be listfields or recfields - if self:lookahead() ~= "=" then -- look ahead: expression? - self:listfield(cc) - else - self:recfield(cc) - end - elseif c == "[" then -- constructor_item -> recfield - self:recfield(cc) - else -- constructor_part -> listfield - self:listfield(cc) - end - until not self:testnext(",") and not self:testnext(";") - self:check_match("}", "{", line) - -- lastlistfield(cc) here - self:log("<< constructor: end") - end - -------------------------------------------------------------------- - -- parse the arguments (parameters) of a function declaration - -- * used in body() - -------------------------------------------------------------------- - function luaY:parlist() - -- parlist -> [ param { ',' param } ] - self:log(">> parlist: begin") - local dots = false - if tok ~= ")" then -- is 'parlist' not empty? - repeat - local c = tok - if c == "..." then - self:log("parlist: ... (dots)") - dots = true - self:next() - elseif c == "" then - self:new_localvar(self:str_checkname()) - else - self:syntaxerror(" or '...' expected") - end - until dots or not self:testnext(",") - end - -- was code_params() - if dots then - self:create_local("arg") - end - self:log("<< parlist: end") - end - -------------------------------------------------------------------- - -- parse the parameters of a function call - -- * contrast with parlist(), used in function declarations - -- * used in primaryexp() - -------------------------------------------------------------------- - function luaY:funcargs(f) - local args = {} - local line = luaX.ln - local c = tok - if c == "(" then -- funcargs -> '(' [ explist1 ] ')' - self:log(">> funcargs: begin '('") - if line ~= lastln then - self:syntaxerror("ambiguous syntax (function call x new statement)") - end - self:next() - if tok == ")" then -- arg list is empty? - args.k = "VVOID" - else - self:explist1(args) - end - self:check_match(")", "(", line) - elseif c == "{" then -- funcargs -> constructor - self:log(">> funcargs: begin '{'") - self:constructor(args) - elseif c == "" then -- funcargs -> STRING - self:log(">> funcargs: begin ") - self:codestring(args, seminfo) - self:next() -- must use 'seminfo' before 'next' - else - self:syntaxerror("function arguments expected") - return - end--if c - f.k = "VCALL" - self:log("<< funcargs: end -- expr is a VCALL") - end - ---[[-------------------------------------------------------------------- --- mostly expression functions -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- parses an expression in parentheses or a single variable - -- * used in primaryexp() - -------------------------------------------------------------------- - function luaY:prefixexp(v) - -- prefixexp -> NAME | '(' expr ')' - local c = tok - if c == "(" then - self:log(">> prefixexp: begin ( expr ) ") - local line = self.ln - self:next() - self:expr(v) - self:check_match(")", "(", line) - self:log("<< prefixexp: end ( expr ) ") - elseif c == "" then - self:log("prefixexp: ") - self:singlevar(v) - else - self:syntaxerror("unexpected symbol") - end--if c - end - -------------------------------------------------------------------- - -- parses a prefixexp (an expression in parentheses or a single - -- variable) or a function call specification - -- * used in simpleexp(), assignment(), expr_stat() - -------------------------------------------------------------------- - function luaY:primaryexp(v) - -- primaryexp -> - -- prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } - self:prefixexp(v) - while true do - local c = tok - if c == "." then -- field - self:log("primaryexp: '.' field") - self:field(v) - elseif c == "[" then -- '[' exp1 ']' - self:log("primaryexp: [ exp1 ]") - local key = {} - self:index(key) - elseif c == ":" then -- ':' NAME funcargs - self:log("primaryexp: : funcargs") - local key = {} - self:next() - self:checkname(key) - self:funcargs(v) - elseif c == "(" or c == "" or c == "{" then -- funcargs - self:log("primaryexp: "..c.." funcargs") - self:funcargs(v) - else - return - end--if c - end--while - end - -------------------------------------------------------------------- - -- parses general expression types, constants handled here - -- * used in subexpr() - -------------------------------------------------------------------- - function luaY:simpleexp(v) - -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | constructor - -- | FUNCTION body | primaryexp - local c = tok - if c == "" then - self:log("simpleexp: ="..seminfo) - v.k = "VK" - self:next() -- must use 'seminfo' before 'next' - elseif c == "" then - self:log("simpleexp: ="..seminfo) - self:codestring(v, seminfo) - self:next() -- must use 'seminfo' before 'next' - elseif c == "nil" then - self:log("simpleexp: nil") - v.k = "VNIL" - self:next() - elseif c == "true" then - self:log("simpleexp: true") - v.k = "VTRUE" - self:next() - elseif c == "false" then - self:log("simpleexp: false") - v.k = "VFALSE" - self:next() - elseif c == "{" then -- constructor - self:log("simpleexp: constructor") - self:constructor(v) - elseif c == "function" then - self:log("simpleexp: function") - self:next() - self:body(v, false, luaX.ln) - else - self:primaryexp(v) - end--if c - end - ------------------------------------------------------------------------ - -- Parse subexpressions. Includes handling of unary operators and binary - -- operators. A subexpr is given the rhs priority level of the operator - -- immediately left of it, if any (limit is -1 if none,) and if a binop - -- is found, limit is compared with the lhs priority level of the binop - -- in order to determine which executes first. - -- * recursively called - -- * used in expr() - ------------------------------------------------------------------------ - function luaY:subexpr(v, limit) - -- subexpr -> (simpleexp | unop subexpr) { binop subexpr } - -- * where 'binop' is any binary operator with a priority - -- higher than 'limit' - local op = tok - local uop = unopr[op] - if uop then - self:log(" subexpr: uop='"..op.."'") - self:next() - self:subexpr(v, 8) -- UNARY_PRIORITY - else - self:simpleexp(v) - end - -- expand while operators have priorities higher than 'limit' - op = tok - local binop = binopr_left[op] - while binop and binop > limit do - local v2 = {} - self:log(">> subexpr: binop='"..op.."'") - self:next() - -- read sub-expression with higher priority - local nextop = self:subexpr(v2, binopr_right[op]) - self:log("<< subexpr: -- evaluate") - op = nextop - binop = binopr_left[op] - end - return op -- return first untreated operator - end - -------------------------------------------------------------------- - -- Expression parsing starts here. Function subexpr is entered with the - -- left operator (which is non-existent) priority of -1, which is lower - -- than all actual operators. Expr information is returned in parm v. - -- * used in cond(), explist1(), index(), recfield(), listfield(), - -- prefixexp(), while_stat(), exp1() - -------------------------------------------------------------------- - function luaY:expr(v) - -- expr -> subexpr - self:log("expr:") - self:subexpr(v, -1) - end - ---[[-------------------------------------------------------------------- --- third level parsing functions -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- parse a variable assignment sequence - -- * recursively called - -- * used in expr_stat() - -------------------------------------------------------------------- - function luaY:assignment(v) - local e = {} - local c = v.v.k - self:check_condition(c == "VLOCAL" or c == "VUPVAL" or c == "VGLOBAL" - or c == "VINDEXED", "syntax error") - if self:testnext(",") then -- assignment -> ',' primaryexp assignment - local nv = {} -- expdesc - nv.v = {} - self:log("assignment: ',' -- next LHS element") - self:primaryexp(nv.v) - -- lparser.c deals with some register usage conflict here - self:assignment(nv) - else -- assignment -> '=' explist1 - self:check("=") - self:log("assignment: '=' -- RHS elements follows") - self:explist1(e) - return -- avoid default - end - e.k = "VNONRELOC" - end - -------------------------------------------------------------------- - -- parse a for loop body for both versions of the for loop - -- * used in fornum(), forlist() - -------------------------------------------------------------------- - function luaY:forbody(line, isnum) - self:check("do") - self:enterblock(true) -- loop block - self:block() - self:leaveblock() - end - -------------------------------------------------------------------- - -- parse a numerical for loop, calls forbody() - -- * used in for_stat() - -------------------------------------------------------------------- - function luaY:fornum(varname, line) - -- fornum -> NAME = exp1, exp1 [, exp1] DO body - self:new_localvar(varname) - self:new_localvarstr("(for limit)") - self:new_localvarstr("(for step)") - self:log(">> fornum: begin") - self:check("=") - self:log("fornum: index start") - self:exp1() -- initial value - self:check(",") - self:log("fornum: index stop") - self:exp1() -- limit - if self:testnext(",") then - self:log("fornum: index step") - self:exp1() -- optional step - else - -- default step = 1 - end - self:log("fornum: body") - self:forbody(line, true) - self:log("<< fornum: end") - end - -------------------------------------------------------------------- - -- parse a generic for loop, calls forbody() - -- * used in for_stat() - -------------------------------------------------------------------- - function luaY:forlist(indexname) - -- forlist -> NAME {, NAME} IN explist1 DO body - self:log(">> forlist: begin") - local e = {} - self:new_localvarstr("(for generator)") - self:new_localvarstr("(for state)") - self:new_localvar(indexname) - while self:testnext(",") do - self:new_localvar(self:str_checkname()) - end - self:check("in") - local line = line - self:log("forlist: explist1") - self:explist1(e) - self:log("forlist: body") - self:forbody(line, false) - self:log("<< forlist: end") - end - -------------------------------------------------------------------- - -- parse a function name specification - -- * used in func_stat() - -------------------------------------------------------------------- - function luaY:funcname(v) - -- funcname -> NAME {field} [':' NAME] - self:log(">> funcname: begin") - local needself = false - self:singlevar(v) - while tok == "." do - self:log("funcname: -- '.' field") - self:field(v) - end - if tok == ":" then - self:log("funcname: -- ':' field") - needself = true - self:field(v) - end - self:log("<< funcname: end") - return needself - end - -------------------------------------------------------------------- - -- parse the single expressions needed in numerical for loops - -- * used in fornum() - -------------------------------------------------------------------- - function luaY:exp1() - -- exp1 -> expr - local e = {} - self:log(">> exp1: begin") - self:expr(e) - self:log("<< exp1: end") - end - -------------------------------------------------------------------- - -- parse condition in a repeat statement or an if control structure - -- * used in repeat_stat(), test_then_block() - -------------------------------------------------------------------- - function luaY:cond(v) - -- cond -> expr - self:log(">> cond: begin") - self:expr(v) -- read condition - self:log("<< cond: end") - end - -------------------------------------------------------------------- - -- parse part of an if control structure, including the condition - -- * used in if_stat() - -------------------------------------------------------------------- - function luaY:test_then_block(v) - -- test_then_block -> [IF | ELSEIF] cond THEN block - self:next() -- skip IF or ELSEIF - self:log("test_then_block: test condition") - self:cond(v) - self:check("then") - self:log("test_then_block: then block") - self:block() -- 'then' part - end - -------------------------------------------------------------------- - -- parse a local function statement - -- * used in local_stat() - -------------------------------------------------------------------- - function luaY:localfunc() - -- localfunc -> NAME body - local v, b = {} - self:log("localfunc: begin") - self:new_localvar(self:str_checkname()) - v.k = "VLOCAL" - self:log("localfunc: body") - self:body(b, false, luaX.ln) - self:log("localfunc: end") - end - -------------------------------------------------------------------- - -- parse a local variable declaration statement - -- * used in local_stat() - -------------------------------------------------------------------- - function luaY:localstat() - -- localstat -> NAME {',' NAME} ['=' explist1] - self:log(">> localstat: begin") - local e = {} - repeat - self:new_localvar(self:str_checkname()) - until not self:testnext(",") - if self:testnext("=") then - self:log("localstat: -- assignment") - self:explist1(e) - else - e.k = "VVOID" - end - self:log("<< localstat: end") - end - -------------------------------------------------------------------- - -- parse a list of comma-separated expressions - -- * used in return_stat(), localstat(), funcargs(), assignment(), - -- forlist() - -------------------------------------------------------------------- - function luaY:explist1(e) - -- explist1 -> expr { ',' expr } - self:log(">> explist1: begin") - self:expr(e) - while self:testnext(",") do - self:log("explist1: ',' -- continuation") - self:expr(e) - end - self:log("<< explist1: end") - end - -------------------------------------------------------------------- - -- parse function declaration body - -- * used in simpleexp(), localfunc(), func_stat() - -------------------------------------------------------------------- - function luaY:body(e, needself, line) - -- body -> '(' parlist ')' chunk END - self:open_func() - self:log("body: begin") - self:check("(") - if needself then - self:create_local("self") - end - self:log("body: parlist") - self:parlist() - self:check(")") - self:log("body: chunk") - self:chunk() - self:check_match("end", "function", line) - self:log("body: end") - self:close_func() - end - -------------------------------------------------------------------- - -- parse a code block or unit - -- * used in do_stat(), while_stat(), repeat_stat(), forbody(), - -- test_then_block(), if_stat() - -------------------------------------------------------------------- - function luaY:block() - -- block -> chunk - self:log("block: begin") - self:enterblock(false) - self:chunk() - self:leaveblock() - self:log("block: end") - end - ---[[-------------------------------------------------------------------- --- second level parsing functions, all with '_stat' suffix --- * stat() -> *_stat() -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- initial parsing for a for loop, calls fornum() or forlist() - -- * used in stat() - -------------------------------------------------------------------- - function luaY:for_stat() - -- stat -> for_stat -> fornum | forlist - local line = line - self:log("for_stat: begin") - self:enterblock(false) -- block to control variable scope - self:next() -- skip 'for' - local varname = self:str_checkname() -- first variable name - local c = tok - if c == "=" then - self:log("for_stat: numerical loop") - self:fornum(varname, line) - elseif c == "," or c == "in" then - self:log("for_stat: list-based loop") - self:forlist(varname) - else - self:syntaxerror("'=' or 'in' expected") - end - self:check_match("end", "for", line) - self:leaveblock() - self:log("for_stat: end") - end - -------------------------------------------------------------------- - -- parse a while-do control structure, body processed by block() - -- * used in stat() - -------------------------------------------------------------------- - function luaY:while_stat() - -- stat -> while_stat -> WHILE cond DO block END - local line = line - local v = {} - self:next() -- skip WHILE - self:log("while_stat: begin/condition") - self:expr(v) -- parse condition - self:enterblock(true) - self:check("do") - self:log("while_stat: block") - self:block() - self:check_match("end", "while", line) - self:leaveblock() - self:log("while_stat: end") - end - -------------------------------------------------------------------- - -- parse a repeat-until control structure, body parsed by block() - -- * used in stat() - -------------------------------------------------------------------- - function luaY:repeat_stat() - -- stat -> repeat_stat -> REPEAT block UNTIL cond - local line = line - local v = {} - self:log("repeat_stat: begin") - self:enterblock(true) - self:next() - self:block() - self:check_match("until", "repeat", line) - self:log("repeat_stat: condition") - self:cond(v) - self:leaveblock() - self:log("repeat_stat: end") - end - -------------------------------------------------------------------- - -- parse an if control structure - -- * used in stat() - -------------------------------------------------------------------- - function luaY:if_stat() - -- stat -> if_stat -> IF cond THEN block - -- {ELSEIF cond THEN block} [ELSE block] END - local line = line - local v = {} - self:log("if_stat: if...then") - self:test_then_block(v) -- IF cond THEN block - while tok == "elseif" do - self:log("if_stat: elseif...then") - self:test_then_block(v) -- ELSEIF cond THEN block - end - if tok == "else" then - self:log("if_stat: else...") - self:next() -- skip ELSE - self:block() -- 'else' part - end - self:check_match("end", "if", line) - self:log("if_stat: end") - end - -------------------------------------------------------------------- - -- parse a return statement - -- * used in stat() - -------------------------------------------------------------------- - function luaY:return_stat() - -- stat -> return_stat -> RETURN explist - local e = {} - self:next() -- skip RETURN - local c = tok - if block_follow[c] or c == ";" then - -- return no values - self:log("return_stat: no return values") - else - self:log("return_stat: begin") - self:explist1(e) -- optional return values - self:log("return_stat: end") - end - end - -------------------------------------------------------------------- - -- parse a break statement - -- * used in stat() - -------------------------------------------------------------------- - function luaY:break_stat() - -- stat -> break_stat -> BREAK - local bl = fs.bl - self:next() -- skip BREAK - while bl and not bl.isbreakable do -- find a breakable block - bl = bl.prev - end - if not bl then - self:syntaxerror("no loop to break") - end - self:log("break_stat: -- break out of loop") - end - -------------------------------------------------------------------- - -- parse a function call with no returns or an assignment statement - -- * the struct with .prev is used for name searching in lparse.c, - -- so it is retained for now; present in assignment() also - -- * used in stat() - -------------------------------------------------------------------- - function luaY:expr_stat() - -- stat -> expr_stat -> func | assignment - local v = {} - v.v = {} - self:primaryexp(v.v) - if v.v.k == "VCALL" then -- stat -> func - -- call statement uses no results - self:log("expr_stat: function call k='"..v.v.k.."'") - else -- stat -> assignment - self:log("expr_stat: assignment k='"..v.v.k.."'") - v.prev = nil - self:assignment(v) - end - end - -------------------------------------------------------------------- - -- parse a function statement - -- * used in stat() - -------------------------------------------------------------------- - function luaY:function_stat() - -- stat -> function_stat -> FUNCTION funcname body - local line = line - local v, b = {}, {} - self:log("function_stat: begin") - self:next() -- skip FUNCTION - local needself = self:funcname(v) - self:log("function_stat: body needself='"..tostring(needself).."'") - self:body(b, needself, line) - self:log("function_stat: end") - end - -------------------------------------------------------------------- - -- parse a simple block enclosed by a DO..END pair - -- * used in stat() - -------------------------------------------------------------------- - function luaY:do_stat() - -- stat -> do_stat -> DO block END - self:next() -- skip DO - self:log("do_stat: begin") - self:block() - self:log("do_stat: end") - self:check_match("end", "do", line) - end - -------------------------------------------------------------------- - -- parse a statement starting with LOCAL - -- * used in stat() - -------------------------------------------------------------------- - function luaY:local_stat() - -- stat -> local_stat -> LOCAL FUNCTION localfunc - -- -> LOCAL localstat - self:next() -- skip LOCAL - if self:testnext("function") then -- local function? - self:log("local_stat: local function") - self:localfunc() - else - self:log("local_stat: local statement") - self:localstat() - end - end - ---[[-------------------------------------------------------------------- --- main function, top level parsing functions --- * [entry] -> parser() -> chunk() -> stat() -----------------------------------------------------------------------]] - - -------------------------------------------------------------------- - -- initial parsing for statements, calls '_stat' suffixed functions - -- * used in chunk() - -------------------------------------------------------------------- - function luaY:stat() - line = luaX.ln - local c = tok - local fn = stat_call[c] - -- handles: if while do for repeat function local return break - if fn then - self:log("-- STATEMENT: begin '"..c.."' line="..line) - self[fn](self) - self:log("-- STATEMENT: end '"..c.."'") - -- return or break must be last statement - if c == "return" or c == "break" then return true end - else - self:log("-- STATEMENT: begin 'expr' line="..line) - self:expr_stat() - self:log("-- STATEMENT: end 'expr'") - end - self:log("") - return false - end - -------------------------------------------------------------------- - -- parse a chunk, which consists of a bunch of statements - -- * used in parser(), body(), block() - -------------------------------------------------------------------- - function luaY:chunk() - -- chunk -> { stat [';'] } - self:log("chunk:") - local islast = false - while not islast and not block_follow[tok] do - islast = self:stat() - self:testnext(";") - end - end - -------------------------------------------------------------------- - -- performs parsing, returns parsed data structure - -------------------------------------------------------------------- - function luaY:parser() - self:log("-- TOP: begin") - self:open_func() - self:log("") - self:next() -- read first token - self:chunk() - self:check_condition(tok == "", " expected") - self:close_func() - self:log("-- TOP: end") - return top_fs - end - -------------------------------------------------------------------- - return luaY -- return actual module to user, done -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua deleted file mode 100644 index 6378366..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua +++ /dev/null @@ -1,106 +0,0 @@ ---[[-------------------------------------------------------------------- - - lzio.lua - Lua 5 buffered streams in Lua - This file is part of Yueliang. - - Copyright (c) 2005-2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- local zio_init = require("lzio.lua") --- local z = zio_init("@") --- local z = zio_init("") --- z:getc() --- * get next character from input stream --- z:fill() --- * fills an empty stream buffer --- z.name --- * name of the chunk, "@" or "=string" -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Format of z structure (ZIO) --- z.n -- bytes still unread --- z.p -- last read position in buffer --- z.reader -- chunk reader function --- z.data -- data buffer --- z.name -- name of stream -----------------------------------------------------------------------]] - -return -function(buff) ---[[-------------------------------------------------------------------- --- initialize reader --- * reader should return a string, or nil if nothing else to parse -----------------------------------------------------------------------]] - local reader - local z = {} - if string.sub(buff, 1, 1) == "@" then - ---------------------------------------------------------------- - -- create a chunk reader function from a source file - ---------------------------------------------------------------- - z.name = buff - local BUFFERSIZE = 512 - local h = io.open(string.sub(buff, 2), "r") - if not h then return nil end - reader = function() - if not h or io.type(h) == "closed file" then return nil end - local buff = h:read(BUFFERSIZE) - if not buff then h:close(); h = nil end - return buff - end - else - ---------------------------------------------------------------- - -- create a chunk reader function from a source string - ---------------------------------------------------------------- - z.name = "=string" - reader = function() - if not buff then return nil end - local data = buff - buff = nil - return data - end - end ---[[-------------------------------------------------------------------- --- fills an empty stream buffer, returns first character -----------------------------------------------------------------------]] - function z:fill() - local data = z.reader() - z.data = data - if not data or data == "" then return "EOZ" end - z.n, z.p = string.len(data) - 1, 1 - return string.sub(data, 1, 1) - end ---[[-------------------------------------------------------------------- --- get next character, fills buffer if characters needed -----------------------------------------------------------------------]] - function z:getc() - local n, p = z.n, z.p + 1 - if n > 0 then - z.n, z.p = n - 1, p - return string.sub(z.data, p, p) - else - return self:fill() - end - end ---[[-------------------------------------------------------------------- --- initialize input stream object -----------------------------------------------------------------------]] - if not reader then return end - z.reader = reader - z.data = "" - z.n, z.p = 0, 0 - return z ---[[------------------------------------------------------------------]] -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua deleted file mode 100644 index d97c795..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua +++ /dev/null @@ -1,82 +0,0 @@ ---[[-------------------------------------------------------------------- - - lzio.lua - Lua 5 buffered streams in Lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * this is a line-based input streamer for the MK4 lexer --- * all EOL (end-of-line) characters are translated to "\n" --- * if last line in a file does not have an EOL character, this --- streamer adds one, the ambiguity is due to "*l" stripping --- * EOF uses an empty string to simplify testing in lexer -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- local zio_init = require("lzio.lua") --- local z = zio_init("@") --- local z = zio_init("") --- z:getln() --- * get next line from input stream --- z.name --- * name of the chunk, "@" or "=string" -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Format of z structure (ZIO) --- z.getln -- chunk reader function, reads line-by-line --- z.name -- name of stream -----------------------------------------------------------------------]] - -return -function(buff) ---[[-------------------------------------------------------------------- --- initialize reader --- * reader should return a string with an EOL character, or an empty --- string if there is nothing else to parse -----------------------------------------------------------------------]] - local reader - local z = {} - if string.sub(buff, 1, 1) == "@" then - ---------------------------------------------------------------- - -- create a chunk reader function from a source file - ---------------------------------------------------------------- - z.name = buff - local h = io.open(string.sub(buff, 2), "r") - if not h then return nil end - reader = function() - if not h or io.type(h) == "closed file" then return nil end - local data = h:read("*l") - if not data then h:close(); return "" end - return data.."\n" - end - else - ---------------------------------------------------------------- - -- create a chunk reader function from a source string - ---------------------------------------------------------------- - z.name = "=string" - reader = function() - if not buff then return nil end - local p, q, data, eol = string.find(buff, "([^\r\n]*)(\r?\n?)") - buff = string.sub(buff, q + 1) - if data == "" and eol == "" then return "" end - return data..eol - end - end ---[[-------------------------------------------------------------------- --- initialize input stream object -----------------------------------------------------------------------]] - if not reader then return end - z.getln = reader - return z ---[[------------------------------------------------------------------]] -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk2.lua deleted file mode 100644 index 873afd1..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk2.lua +++ /dev/null @@ -1,94 +0,0 @@ ---[[-------------------------------------------------------------------- - - bench_llex.lua - Benchmark test for llex.lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - -local zio_init = require("../lzio_mk2") -local lex_init = require("../llex_mk2") - ------------------------------------------------------------------------- --- load in a standard set of sample files --- * file set is 5.0.3 front end set sans luac.lua ------------------------------------------------------------------------- - -local fileset, totalsize = {}, 0 -for fn in string.gfind([[ -../../orig-5.0.3/lcode.lua -../../orig-5.0.3/ldump.lua -../../orig-5.0.3/llex.lua -../../orig-5.0.3/lopcodes.lua -../../orig-5.0.3/lparser.lua -../../orig-5.0.3/lzio.lua -]], "%S+") do - table.insert(fileset, fn) -end - -for i = 1, table.getn(fileset) do - local fn = fileset[i] - local inf = io.open(fn, "rb") - if not inf then - error("failed to open "..fn.." for reading") - end - local data = inf:read("*a") - local data_sz = string.len(data) - inf:close() - if not data or data_sz == 0 then - error("failed to read data from "..fn.." or file is zero-length") - end - totalsize = totalsize + data_sz - fileset[i] = data -end - ------------------------------------------------------------------------- --- benchmark tester ------------------------------------------------------------------------- - -local DURATION = 5 -- how long the benchmark should run - -local time = os.time -local lexedsize = 0 -local tnow, elapsed = time(), 0 - -while time() == tnow do end -- wait for second to click over -tnow = time() - -while true do - for i = 1, table.getn(fileset) do - ------------------------------------------------------------ - local chunk = fileset[i] - local z = zio_init(chunk) - local luaX = lex_init(z, "=string") - while true do - local tok, seminfo = luaX:lex() - if tok == "" then break end - end - ------------------------------------------------------------ - lexedsize = lexedsize + string.len(chunk) - if time() > tnow then - tnow = time() - elapsed = elapsed + 1 - if elapsed >= DURATION then - -- report performance of lexer - lexedsize = lexedsize / 1024 - local speed = lexedsize / DURATION - print("Lexer performance:") - print("Size of data lexed (KB): "..string.format("%.1f", lexedsize)) - print("Speed of lexer (KB/s): "..string.format("%.1f", speed)) - -- repeat until user breaks program - elapsed = 0 - end - end - ------------------------------------------------------------ - end--for -end--while - --- end of script diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua deleted file mode 100644 index 6b2a4a6..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua +++ /dev/null @@ -1,92 +0,0 @@ ---[[-------------------------------------------------------------------- - - bench_llex.lua - Benchmark test for llex.lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - -local lex_init = require("../llex_mk3") - ------------------------------------------------------------------------- --- load in a standard set of sample files --- * file set is 5.0.3 front end set sans luac.lua ------------------------------------------------------------------------- - -local fileset, totalsize = {}, 0 -for fn in string.gfind([[ -../../orig-5.0.3/lcode.lua -../../orig-5.0.3/ldump.lua -../../orig-5.0.3/llex.lua -../../orig-5.0.3/lopcodes.lua -../../orig-5.0.3/lparser.lua -../../orig-5.0.3/lzio.lua -]], "%S+") do - table.insert(fileset, fn) -end - -for i = 1, table.getn(fileset) do - local fn = fileset[i] - local inf = io.open(fn, "rb") - if not inf then - error("failed to open "..fn.." for reading") - end - local data = inf:read("*a") - local data_sz = string.len(data) - inf:close() - if not data or data_sz == 0 then - error("failed to read data from "..fn.." or file is zero-length") - end - totalsize = totalsize + data_sz - fileset[i] = data -end - ------------------------------------------------------------------------- --- benchmark tester ------------------------------------------------------------------------- - -local DURATION = 5 -- how long the benchmark should run - -local time = os.time -local lexedsize = 0 -local tnow, elapsed = time(), 0 - -while time() == tnow do end -- wait for second to click over -tnow = time() - -while true do - for i = 1, table.getn(fileset) do - ------------------------------------------------------------ - local chunk = fileset[i] - local luaX = lex_init(chunk, "=string") - while true do - local tok, seminfo = luaX:lex() - if tok == "" then break end - end - ------------------------------------------------------------ - lexedsize = lexedsize + string.len(chunk) - if time() > tnow then - tnow = time() - elapsed = elapsed + 1 - if elapsed >= DURATION then - -- report performance of lexer - lexedsize = lexedsize / 1024 - local speed = lexedsize / DURATION - print("Lexer performance:") - print("Size of data lexed (KB): "..string.format("%.1f", lexedsize)) - print("Speed of lexer (KB/s): "..string.format("%.1f", speed)) - -- repeat until user breaks program - elapsed = 0 - end - end - ------------------------------------------------------------ - end--for -end--while - --- end of script diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk4.lua deleted file mode 100644 index b94386b..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk4.lua +++ /dev/null @@ -1,94 +0,0 @@ ---[[-------------------------------------------------------------------- - - bench_llex.lua - Benchmark test for llex.lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - -local zio_init = require("../lzio_mk4") -local lex_init = require("../llex_mk4") - ------------------------------------------------------------------------- --- load in a standard set of sample files --- * file set is 5.0.3 front end set sans luac.lua ------------------------------------------------------------------------- - -local fileset, totalsize = {}, 0 -for fn in string.gfind([[ -../../orig-5.0.3/lcode.lua -../../orig-5.0.3/ldump.lua -../../orig-5.0.3/llex.lua -../../orig-5.0.3/lopcodes.lua -../../orig-5.0.3/lparser.lua -../../orig-5.0.3/lzio.lua -]], "%S+") do - table.insert(fileset, fn) -end - -for i = 1, table.getn(fileset) do - local fn = fileset[i] - local inf = io.open(fn, "rb") - if not inf then - error("failed to open "..fn.." for reading") - end - local data = inf:read("*a") - local data_sz = string.len(data) - inf:close() - if not data or data_sz == 0 then - error("failed to read data from "..fn.." or file is zero-length") - end - totalsize = totalsize + data_sz - fileset[i] = data -end - ------------------------------------------------------------------------- --- benchmark tester ------------------------------------------------------------------------- - -local DURATION = 5 -- how long the benchmark should run - -local time = os.time -local lexedsize = 0 -local tnow, elapsed = time(), 0 - -while time() == tnow do end -- wait for second to click over -tnow = time() - -while true do - for i = 1, table.getn(fileset) do - ------------------------------------------------------------ - local chunk = fileset[i] - local z = zio_init(chunk) - local luaX = lex_init(z, "=string") - while true do - local tok, seminfo = luaX:lex() - if tok == "" then break end - end - ------------------------------------------------------------ - lexedsize = lexedsize + string.len(chunk) - if time() > tnow then - tnow = time() - elapsed = elapsed + 1 - if elapsed >= DURATION then - -- report performance of lexer - lexedsize = lexedsize / 1024 - local speed = lexedsize / DURATION - print("Lexer performance:") - print("Size of data lexed (KB): "..string.format("%.1f", lexedsize)) - print("Speed of lexer (KB/s): "..string.format("%.1f", speed)) - -- repeat until user breaks program - elapsed = 0 - end - end - ------------------------------------------------------------ - end--for -end--while - --- end of script diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_01.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_01.lua deleted file mode 100644 index 379cc9d..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_01.lua +++ /dev/null @@ -1,9 +0,0 @@ --- START OF SOURCE -- --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_02.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_02.lua deleted file mode 100644 index 13eb2e6..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_02.lua +++ /dev/null @@ -1,10 +0,0 @@ --- START OF SOURCE -- --- foobar --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_03.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_03.lua deleted file mode 100644 index 33df29c..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_03.lua +++ /dev/null @@ -1,21 +0,0 @@ --- START OF SOURCE -- -do -end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'do' line=1 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_04.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_04.lua deleted file mode 100644 index d0fefbc..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_04.lua +++ /dev/null @@ -1,31 +0,0 @@ --- START OF SOURCE -- -do end -do end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'do' line=1 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - -- STATEMENT: begin 'do' line=2 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_05.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_05.lua deleted file mode 100644 index 8d6f962..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_05.lua +++ /dev/null @@ -1,129 +0,0 @@ --- START OF SOURCE -- -foo() -foo{} -foo"" -foo:bar() -foo=false -foo.bar=true -foo[true]=nil -foo,bar=1,"a" --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - primaryexp: ( funcargs - funcargs: begin '(' - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - primaryexp: { funcargs - funcargs: begin '{' - constructor: begin - constructor: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - primaryexp: funcargs - funcargs: begin - codestring: "" - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=4 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - primaryexp: : funcargs - checkname: - str_checkname: 'bar' - codestring: "bar" - funcargs: begin '(' - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: false - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=6 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - primaryexp: '.' field - field: operator=. - checkname: - str_checkname: 'bar' - codestring: "bar" - expr_stat: assignment k='VINDEXED' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: true - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=7 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - primaryexp: [ exp1 ] - index: begin '[' - expr: - simpleexp: true - index: end ']' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: nil - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=8 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: ',' -- next LHS element - prefixexp: - str_checkname: 'bar' - singlevar: name='bar' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1 - explist1: ',' -- continuation - expr: - simpleexp: =a - codestring: "a" - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_06.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_06.lua deleted file mode 100644 index ca7776e..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_06.lua +++ /dev/null @@ -1,132 +0,0 @@ --- START OF SOURCE -- -foo=true -foo=false -foo=nil -foo=1.23e45 -foo=-1 -foo=(0) -foo=1+2 -foo=1+2*3-4/5 --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: true - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: false - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: nil - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=4 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1.23e+45 - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - subexpr: uop='-' - simpleexp: =1 - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=6 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: begin ( expr ) - expr: - simpleexp: =0 - prefixexp: end ( expr ) - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=7 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1 - subexpr: binop='+' - simpleexp: =2 - subexpr: -- evaluate - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=8 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1 - subexpr: binop='+' - simpleexp: =2 - subexpr: binop='*' - simpleexp: =3 - subexpr: -- evaluate - subexpr: -- evaluate - subexpr: binop='-' - simpleexp: =4 - subexpr: binop='/' - simpleexp: =5 - subexpr: -- evaluate - subexpr: -- evaluate - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_07.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_07.lua deleted file mode 100644 index 8c0a738..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_07.lua +++ /dev/null @@ -1,147 +0,0 @@ --- START OF SOURCE -- -if foo then foo=1 end -if foo then foo=1 else foo=0 end -if foo then foo=1 elseif not foo then foo=0 end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'if' line=1 - if_stat: if...then - test_then_block: test condition - cond: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - cond: end - test_then_block: then block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - if_stat: end - -- STATEMENT: end 'if' - - -- STATEMENT: begin 'if' line=2 - if_stat: if...then - test_then_block: test condition - cond: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - cond: end - test_then_block: then block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - if_stat: else... - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =0 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - if_stat: end - -- STATEMENT: end 'if' - - -- STATEMENT: begin 'if' line=3 - if_stat: if...then - test_then_block: test condition - cond: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - cond: end - test_then_block: then block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =1 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - if_stat: elseif...then - test_then_block: test condition - cond: begin - expr: - subexpr: uop='not' - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - cond: end - test_then_block: then block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =0 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - if_stat: end - -- STATEMENT: end 'if' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_08.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_08.lua deleted file mode 100644 index d086c98..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_08.lua +++ /dev/null @@ -1,66 +0,0 @@ --- START OF SOURCE -- -do return end -do return 123 end -do return "foo","bar" end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'do' line=1 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'return' line=1 - return_stat: no return values - -- STATEMENT: end 'return' - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - -- STATEMENT: begin 'do' line=2 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'return' line=2 - return_stat: begin - explist1: begin - expr: - simpleexp: =123 - explist1: end - return_stat: end - -- STATEMENT: end 'return' - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - -- STATEMENT: begin 'do' line=3 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'return' line=3 - return_stat: begin - explist1: begin - expr: - simpleexp: =foo - codestring: "foo" - explist1: ',' -- continuation - expr: - simpleexp: =bar - codestring: "bar" - explist1: end - return_stat: end - -- STATEMENT: end 'return' - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_09.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_09.lua deleted file mode 100644 index 2236388..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_09.lua +++ /dev/null @@ -1,97 +0,0 @@ --- START OF SOURCE -- -while true do foo=not foo end -while foo~=42 do foo=foo-1 end -while true do break end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'while' line=1 - while_stat: begin/condition - expr: - simpleexp: true - enterblock(isbreakable=true) - while_stat: block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - subexpr: uop='not' - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - while_stat: end - -- STATEMENT: end 'while' - - -- STATEMENT: begin 'while' line=2 - while_stat: begin/condition - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - subexpr: binop='~=' - simpleexp: =42 - subexpr: -- evaluate - enterblock(isbreakable=true) - while_stat: block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - subexpr: binop='-' - simpleexp: =1 - subexpr: -- evaluate - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - while_stat: end - -- STATEMENT: end 'while' - - -- STATEMENT: begin 'while' line=3 - while_stat: begin/condition - expr: - simpleexp: true - enterblock(isbreakable=true) - while_stat: block - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'break' line=3 - break_stat: -- break out of loop - -- STATEMENT: end 'break' - leaveblock - block: end - leaveblock - while_stat: end - -- STATEMENT: end 'while' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_10.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_10.lua deleted file mode 100644 index 72f7ae3..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_10.lua +++ /dev/null @@ -1,106 +0,0 @@ --- START OF SOURCE -- -repeat foo=foo.."bar" until false -repeat foo=foo/2 until foo<1 -repeat break until false --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'repeat' line=1 - repeat_stat: begin - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - subexpr: binop='..' - simpleexp: =bar - codestring: "bar" - subexpr: -- evaluate - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - repeat_stat: condition - cond: begin - expr: - simpleexp: false - cond: end - leaveblock - repeat_stat: end - -- STATEMENT: end 'repeat' - - -- STATEMENT: begin 'repeat' line=2 - repeat_stat: begin - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - subexpr: binop='/' - simpleexp: =2 - subexpr: -- evaluate - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - repeat_stat: condition - cond: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - subexpr: binop='<' - simpleexp: =1 - subexpr: -- evaluate - cond: end - leaveblock - repeat_stat: end - -- STATEMENT: end 'repeat' - - -- STATEMENT: begin 'repeat' line=3 - repeat_stat: begin - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'break' line=3 - break_stat: -- break out of loop - -- STATEMENT: end 'break' - leaveblock - block: end - repeat_stat: condition - cond: begin - expr: - simpleexp: false - cond: end - leaveblock - repeat_stat: end - -- STATEMENT: end 'repeat' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_11.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_11.lua deleted file mode 100644 index 8af611b..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_11.lua +++ /dev/null @@ -1,175 +0,0 @@ --- START OF SOURCE -- -for i=1,10 do foo=i end -for i=1,10,2 do break end -for i in foo do bar=0 end -for i,j in foo,bar do baz=0 end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'for' line=1 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'i' - for_stat: numerical loop - fornum: begin - fornum: index start - exp1: begin - expr: - simpleexp: =1 - exp1: end - fornum: index stop - exp1: begin - expr: - simpleexp: =10 - exp1: end - fornum: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'i' - singlevar: name='i' - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - fornum: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - -- STATEMENT: begin 'for' line=2 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'i' - for_stat: numerical loop - fornum: begin - fornum: index start - exp1: begin - expr: - simpleexp: =1 - exp1: end - fornum: index stop - exp1: begin - expr: - simpleexp: =10 - exp1: end - fornum: index step - exp1: begin - expr: - simpleexp: =2 - exp1: end - fornum: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'break' line=2 - break_stat: -- break out of loop - -- STATEMENT: end 'break' - leaveblock - block: end - leaveblock - fornum: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - -- STATEMENT: begin 'for' line=3 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'i' - for_stat: list-based loop - forlist: begin - forlist: explist1 - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - explist1: end - forlist: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'bar' - singlevar: name='bar' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =0 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - forlist: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - -- STATEMENT: begin 'for' line=4 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'i' - for_stat: list-based loop - forlist: begin - str_checkname: 'j' - forlist: explist1 - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'bar' - singlevar: name='bar' - explist1: end - forlist: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=4 - prefixexp: - str_checkname: 'baz' - singlevar: name='baz' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: =0 - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - forlist: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_12.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_12.lua deleted file mode 100644 index 916fc7f..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_12.lua +++ /dev/null @@ -1,46 +0,0 @@ --- START OF SOURCE -- -local foo -local foo,bar,baz -local foo,bar="foo","bar" --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local statement - localstat: begin - str_checkname: 'foo' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=2 - local_stat: local statement - localstat: begin - str_checkname: 'foo' - str_checkname: 'bar' - str_checkname: 'baz' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=3 - local_stat: local statement - localstat: begin - str_checkname: 'foo' - str_checkname: 'bar' - localstat: -- assignment - explist1: begin - expr: - simpleexp: =foo - codestring: "foo" - explist1: ',' -- continuation - expr: - simpleexp: =bar - codestring: "bar" - explist1: end - localstat: end - -- STATEMENT: end 'local' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_13.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_13.lua deleted file mode 100644 index 8ddd3ea..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_13.lua +++ /dev/null @@ -1,99 +0,0 @@ --- START OF SOURCE -- -local function foo() return end -local function foo(a) return end -local function foo(x,y,z) return end -local function foo(x,...) return end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local function - localfunc: begin - str_checkname: 'foo' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=1 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=2 - local_stat: local function - localfunc: begin - str_checkname: 'foo' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'a' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=2 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=3 - local_stat: local function - localfunc: begin - str_checkname: 'foo' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'x' - str_checkname: 'y' - str_checkname: 'z' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=3 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=4 - local_stat: local function - localfunc: begin - str_checkname: 'foo' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'x' - parlist: ... (dots) - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=4 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_14.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_14.lua deleted file mode 100644 index aa0069a..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_14.lua +++ /dev/null @@ -1,107 +0,0 @@ --- START OF SOURCE -- -function foo() return end -function foo(a) return end -function foo(x,y,z) return end -function foo(x,...) return end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'function' line=1 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=1 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - -- STATEMENT: begin 'function' line=2 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'a' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=2 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - -- STATEMENT: begin 'function' line=3 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'x' - str_checkname: 'y' - str_checkname: 'z' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=3 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - -- STATEMENT: begin 'function' line=4 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'x' - parlist: ... (dots) - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=4 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_15.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_15.lua deleted file mode 100644 index 73cdac3..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_15.lua +++ /dev/null @@ -1,135 +0,0 @@ --- START OF SOURCE -- -function foo.bar(p) return end -function foo.bar.baz(p) return end -function foo:bar(p) return end -function foo.bar.baz(p) return end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'function' line=1 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: -- '.' field - field: operator=. - checkname: - str_checkname: 'bar' - codestring: "bar" - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'p' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=1 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - -- STATEMENT: begin 'function' line=2 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: -- '.' field - field: operator=. - checkname: - str_checkname: 'bar' - codestring: "bar" - funcname: -- '.' field - field: operator=. - checkname: - str_checkname: 'baz' - codestring: "baz" - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'p' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=2 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - -- STATEMENT: begin 'function' line=3 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: -- ':' field - field: operator=: - checkname: - str_checkname: 'bar' - codestring: "bar" - funcname: end - function_stat: body needself='true' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'p' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=3 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - -- STATEMENT: begin 'function' line=4 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar: name='foo' - funcname: -- '.' field - field: operator=. - checkname: - str_checkname: 'bar' - codestring: "bar" - funcname: -- '.' field - field: operator=. - checkname: - str_checkname: 'baz' - codestring: "baz" - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'p' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=4 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_16.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_16.lua deleted file mode 100644 index b53b2fb..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_16.lua +++ /dev/null @@ -1,87 +0,0 @@ --- START OF SOURCE -- -foo = function() return end -foo = function(x,y) return end -foo = function(...) return end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: function - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=1 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: function - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'x' - str_checkname: 'y' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=2 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: function - open_func - body: begin - body: parlist - parlist: begin - parlist: ... (dots) - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'return' line=3 - return_stat: no return values - -- STATEMENT: end 'return' - body: end - close_func - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_17.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_17.lua deleted file mode 100644 index 87634d3..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_17.lua +++ /dev/null @@ -1,110 +0,0 @@ --- START OF SOURCE -- -foo = {} -foo = { 1,2,3; "foo"; } -foo = { bar=77, baz=88, } -foo = { ["bar"]=77, ["baz"]=88, } --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: constructor - constructor: begin - constructor: end - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: constructor - constructor: begin - listfield: expr - expr: - simpleexp: =1 - listfield: expr - expr: - simpleexp: =2 - listfield: expr - expr: - simpleexp: =3 - listfield: expr - expr: - simpleexp: =foo - codestring: "foo" - constructor: end - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: constructor - constructor: begin - recfield: name - checkname: - str_checkname: 'bar' - codestring: "bar" - expr: - simpleexp: =77 - recfield: name - checkname: - str_checkname: 'baz' - codestring: "baz" - expr: - simpleexp: =88 - constructor: end - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=4 - prefixexp: - str_checkname: 'foo' - singlevar: name='foo' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: constructor - constructor: begin - recfield: [ exp1 ] - index: begin '[' - expr: - simpleexp: =bar - codestring: "bar" - index: end ']' - expr: - simpleexp: =77 - recfield: [ exp1 ] - index: begin '[' - expr: - simpleexp: =baz - codestring: "baz" - index: end ']' - expr: - simpleexp: =88 - constructor: end - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_01.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_01.lua deleted file mode 100644 index 732b4d6..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_01.lua +++ /dev/null @@ -1,26 +0,0 @@ --- START OF SOURCE -- - print(a) --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'expr' line=1 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'a' - singlevar(kind): 'VGLOBAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_02.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_02.lua deleted file mode 100644 index 9863b4a..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_02.lua +++ /dev/null @@ -1,35 +0,0 @@ --- START OF SOURCE -- - local a - print(a) --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local statement - localstat: begin - str_checkname: 'a' - new_localvar: 'a' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'a' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_03.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_03.lua deleted file mode 100644 index bc37280..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_03.lua +++ /dev/null @@ -1,64 +0,0 @@ --- START OF SOURCE -- - do - local a - print(a) - end - print(a) --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'do' line=1 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'local' line=2 - local_stat: local statement - localstat: begin - str_checkname: 'a' - new_localvar: 'a' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'a' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'a' - singlevar(kind): 'VGLOBAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_04.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_04.lua deleted file mode 100644 index b2bac4b..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_04.lua +++ /dev/null @@ -1,77 +0,0 @@ --- START OF SOURCE -- - local a,b,c - do - local b - print(b) - end - print(b) --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local statement - localstat: begin - str_checkname: 'a' - new_localvar: 'a' - str_checkname: 'b' - new_localvar: 'b' - str_checkname: 'c' - new_localvar: 'c' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'do' line=2 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'local' line=3 - local_stat: local statement - localstat: begin - str_checkname: 'b' - new_localvar: 'b' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=4 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'b' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - -- STATEMENT: begin 'expr' line=6 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'b' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_05.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_05.lua deleted file mode 100644 index 6885f01..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_05.lua +++ /dev/null @@ -1,43 +0,0 @@ --- START OF SOURCE -- - local function foo() end - bar = foo --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local function - localfunc: begin - str_checkname: 'foo' - new_localvar: 'foo' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VGLOBAL' - expr_stat: assignment k='VGLOBAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_06.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_06.lua deleted file mode 100644 index eb658ed..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_06.lua +++ /dev/null @@ -1,70 +0,0 @@ --- START OF SOURCE -- - do - local function foo() end - bar = foo - end - baz = foo --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'do' line=1 - do_stat: begin - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'local' line=2 - local_stat: local function - localfunc: begin - str_checkname: 'foo' - new_localvar: 'foo' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VGLOBAL' - expr_stat: assignment k='VGLOBAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - explist1: end - -- STATEMENT: end 'expr' - - leaveblock - block: end - do_stat: end - -- STATEMENT: end 'do' - - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'baz' - singlevar(kind): 'VGLOBAL' - expr_stat: assignment k='VGLOBAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VGLOBAL' - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_07.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_07.lua deleted file mode 100644 index 6403234..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_07.lua +++ /dev/null @@ -1,84 +0,0 @@ --- START OF SOURCE -- - local foo - local function bar() - baz = nil - foo = bar() - end - foo = bar --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local statement - localstat: begin - str_checkname: 'foo' - new_localvar: 'foo' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=2 - local_stat: local function - localfunc: begin - str_checkname: 'bar' - new_localvar: 'bar' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'baz' - singlevar(kind): 'VGLOBAL' - expr_stat: assignment k='VGLOBAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - simpleexp: nil - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=4 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VUPVAL' - expr_stat: assignment k='VUPVAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VUPVAL' - primaryexp: ( funcargs - funcargs: begin '(' - funcargs: end -- expr is a VCALL - explist1: end - -- STATEMENT: end 'expr' - - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=6 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VLOCAL' - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_08.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_08.lua deleted file mode 100644 index 594e267..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_08.lua +++ /dev/null @@ -1,159 +0,0 @@ --- START OF SOURCE -- - local foo - local function bar() - local function baz() - local foo, bar - foo = bar - foo = baz - end - foo = bar - foo = baz - end - foo = bar - foo = baz --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local statement - localstat: begin - str_checkname: 'foo' - new_localvar: 'foo' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'local' line=2 - local_stat: local function - localfunc: begin - str_checkname: 'bar' - new_localvar: 'bar' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'local' line=3 - local_stat: local function - localfunc: begin - str_checkname: 'baz' - new_localvar: 'baz' - localfunc: body - open_func - body: begin - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'local' line=4 - local_stat: local statement - localstat: begin - str_checkname: 'foo' - new_localvar: 'foo' - str_checkname: 'bar' - new_localvar: 'bar' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VLOCAL' - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=6 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'baz' - singlevar(kind): 'VUPVAL' - explist1: end - -- STATEMENT: end 'expr' - - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=8 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VUPVAL' - expr_stat: assignment k='VUPVAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VUPVAL' - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=9 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VUPVAL' - expr_stat: assignment k='VUPVAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'baz' - singlevar(kind): 'VLOCAL' - explist1: end - -- STATEMENT: end 'expr' - - body: end - close_func - localfunc: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'expr' line=11 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VLOCAL' - explist1: end - -- STATEMENT: end 'expr' - - -- STATEMENT: begin 'expr' line=12 - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - expr_stat: assignment k='VLOCAL' - assignment: '=' -- RHS elements follows - explist1: begin - expr: - prefixexp: - str_checkname: 'baz' - singlevar(kind): 'VGLOBAL' - explist1: end - -- STATEMENT: end 'expr' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_09.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_09.lua deleted file mode 100644 index bfa3920..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_09.lua +++ /dev/null @@ -1,53 +0,0 @@ --- START OF SOURCE -- - function foo:bar() - print(self) - end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'function' line=1 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar(kind): 'VGLOBAL' - funcname: -- ':' field - field: operator=: - checkname: - str_checkname: 'bar' - codestring: "bar" - funcname: end - function_stat: body needself='true' - open_func - body: begin - new_localvar: 'self' - body: parlist - parlist: begin - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'self' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_10.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_10.lua deleted file mode 100644 index 9a38883..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_10.lua +++ /dev/null @@ -1,49 +0,0 @@ --- START OF SOURCE -- - function foo(...) - print(arg) - end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'function' line=1 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar(kind): 'VGLOBAL' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - parlist: ... (dots) - new_localvar: 'arg' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'arg' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_11.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_11.lua deleted file mode 100644 index e4c9e21..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_11.lua +++ /dev/null @@ -1,79 +0,0 @@ --- START OF SOURCE -- - local c,d - function foo(a,b,c) - print(a,c,d,e) - end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'local' line=1 - local_stat: local statement - localstat: begin - str_checkname: 'c' - new_localvar: 'c' - str_checkname: 'd' - new_localvar: 'd' - localstat: end - -- STATEMENT: end 'local' - - -- STATEMENT: begin 'function' line=2 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar(kind): 'VGLOBAL' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'a' - new_localvar: 'a' - str_checkname: 'b' - new_localvar: 'b' - str_checkname: 'c' - new_localvar: 'c' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'a' - singlevar(kind): 'VLOCAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'c' - singlevar(kind): 'VLOCAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'd' - singlevar(kind): 'VUPVAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'e' - singlevar(kind): 'VGLOBAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_12.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_12.lua deleted file mode 100644 index b278ba2..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_12.lua +++ /dev/null @@ -1,94 +0,0 @@ --- START OF SOURCE -- - function foo(a,b) - local bar = function(c,d) - print(a,b,c,d) - end - end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'function' line=1 - function_stat: begin - funcname: begin - str_checkname: 'foo' - singlevar(kind): 'VGLOBAL' - funcname: end - function_stat: body needself='false' - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'a' - new_localvar: 'a' - str_checkname: 'b' - new_localvar: 'b' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'local' line=2 - local_stat: local statement - localstat: begin - str_checkname: 'bar' - new_localvar: 'bar' - localstat: -- assignment - explist1: begin - expr: - simpleexp: function - open_func - body: begin - body: parlist - parlist: begin - str_checkname: 'c' - new_localvar: 'c' - str_checkname: 'd' - new_localvar: 'd' - parlist: end - body: chunk - chunk: - -- STATEMENT: begin 'expr' line=3 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'a' - singlevar(kind): 'VUPVAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'b' - singlevar(kind): 'VUPVAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'c' - singlevar(kind): 'VLOCAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'd' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - body: end - close_func - explist1: end - localstat: end - -- STATEMENT: end 'local' - - body: end - close_func - function_stat: end - -- STATEMENT: end 'function' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_13.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_13.lua deleted file mode 100644 index 6e4850c..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_13.lua +++ /dev/null @@ -1,117 +0,0 @@ --- START OF SOURCE -- - for i = 1,10 do - print(i) - end - for i = 1,10,-2 do - print(i) - end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'for' line=1 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'i' - for_stat: numerical loop - new_localvar: 'i' - new_localvar: '(for limit)' - new_localvar: '(for step)' - fornum: begin - fornum: index start - exp1: begin - expr: - simpleexp: =1 - exp1: end - fornum: index stop - exp1: begin - expr: - simpleexp: =10 - exp1: end - fornum: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'i' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - fornum: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - -- STATEMENT: begin 'for' line=4 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'i' - for_stat: numerical loop - new_localvar: 'i' - new_localvar: '(for limit)' - new_localvar: '(for step)' - fornum: begin - fornum: index start - exp1: begin - expr: - simpleexp: =1 - exp1: end - fornum: index stop - exp1: begin - expr: - simpleexp: =10 - exp1: end - fornum: index step - exp1: begin - expr: - subexpr: uop='-' - simpleexp: =2 - exp1: end - fornum: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'i' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - fornum: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_14.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_14.lua deleted file mode 100644 index f80c33f..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/parser_log/sample_b_14.lua +++ /dev/null @@ -1,125 +0,0 @@ --- START OF SOURCE -- - for foo in bar() do - print(foo) - end - for foo,bar,baz in spring() do - print(foo,bar,baz) - end --- END OF SOURCE -- - --- TOP: begin - open_func - - chunk: - -- STATEMENT: begin 'for' line=1 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'foo' - for_stat: list-based loop - forlist: begin - new_localvar: '(for generator)' - new_localvar: '(for state)' - new_localvar: 'foo' - forlist: explist1 - explist1: begin - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - funcargs: end -- expr is a VCALL - explist1: end - forlist: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=2 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - forlist: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - -- STATEMENT: begin 'for' line=4 - for_stat: begin - enterblock(isbreakable=false) - str_checkname: 'foo' - for_stat: list-based loop - forlist: begin - new_localvar: '(for generator)' - new_localvar: '(for state)' - new_localvar: 'foo' - str_checkname: 'bar' - new_localvar: 'bar' - str_checkname: 'baz' - new_localvar: 'baz' - forlist: explist1 - explist1: begin - expr: - prefixexp: - str_checkname: 'spring' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - funcargs: end -- expr is a VCALL - explist1: end - forlist: body - enterblock(isbreakable=true) - block: begin - enterblock(isbreakable=false) - chunk: - -- STATEMENT: begin 'expr' line=5 - prefixexp: - str_checkname: 'print' - singlevar(kind): 'VGLOBAL' - primaryexp: ( funcargs - funcargs: begin '(' - explist1: begin - expr: - prefixexp: - str_checkname: 'foo' - singlevar(kind): 'VLOCAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'bar' - singlevar(kind): 'VLOCAL' - explist1: ',' -- continuation - expr: - prefixexp: - str_checkname: 'baz' - singlevar(kind): 'VLOCAL' - explist1: end - funcargs: end -- expr is a VCALL - expr_stat: function call k='VCALL' - -- STATEMENT: end 'expr' - - leaveblock - block: end - leaveblock - forlist: end - leaveblock - for_stat: end - -- STATEMENT: end 'for' - - close_func --- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/sample.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/sample.lua deleted file mode 100644 index dc6eaee..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/sample.lua +++ /dev/null @@ -1,3 +0,0 @@ -local a = 47 -local b = "hello, world!" -print(a, b) diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk2.lua deleted file mode 100644 index ff8cec5..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk2.lua +++ /dev/null @@ -1,499 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_llex.lua - Test for llex.lua - This file is part of Yueliang. - - Copyright (c) 2005-2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ------------------------------------------------------------------------- --- if BRIEF is not set to false, auto-test will silently succeed ------------------------------------------------------------------------- -BRIEF = true -- if set to true, messages are less verbose - -local zio_init = require("../lzio_mk2") -local lex_init = require("../llex_mk2") - ------------------------------------------------------------------------- --- simple manual tests ------------------------------------------------------------------------- - ---[[ -local function dump(z, source) - local luaX = lex_init(z, source) - while true do - local tok, seminfo = luaX:lex() - if tok == "" then - seminfo = " "..seminfo - elseif tok == "" then - seminfo = " "..seminfo - elseif tok == "" then - seminfo = " '"..seminfo.."'" - else - seminfo = "" - end - io.stdout:write(tok..seminfo.."\n") - if tok == "" then break end - end -end - -local function try_string(chunk) - dump(zio_init(chunk), "=string") -end -local function try_file(filename) - local f = "@"..filename - dump(zio_init(f), f) -end - -z = try_string("local c = z:getc()") -z = try_file("test_lzio_mk2.lua") -z = try_file("test_llex_mk2.lua") -os.exit() ---]] - ------------------------------------------------------------------------- --- auto-testing of simple test cases to validate lexer behaviour: --- * NOTE coverage has not been checked; not comprehensive --- * only test cases with non-empty comments are processed --- * if no result, then the output is displayed for manual decision --- (output may be used to set expected success or fail text) --- * cases expected to be successful may be a partial match --- * cases expected to fail may also be a partial match ------------------------------------------------------------------------- - --- [[ -local function auto_test() - local PASS, FAIL = true, false - ------------------------------------------------------------------ - -- table of test cases - ------------------------------------------------------------------ - local test_cases = - { - ------------------------------------------------------------- - --{ "comment", -- comment about the test - -- "chunk", -- chunk to test - -- PASS, -- PASS or FAIL outcome - -- "output", -- output to compare against - --}, - ------------------------------------------------------------- - { "empty chunk string, test EOS", - "", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "line number counting", - "\n\n\r\n", - PASS, "4 ", - }, - ------------------------------------------------------------- - { "various whitespaces", - " \n\t\t\n \t \t \n\n", - PASS, "5 ", - }, - ------------------------------------------------------------- - { "short comment ending in EOS", - "-- moo moo", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "short comment ending in newline", - "-- moo moo\n", - PASS, "2 ", - }, - ------------------------------------------------------------- - { "several lines of short comments", - "--moo\n-- moo moo\n\n--\tmoo\n", - PASS, "5 ", - }, - ------------------------------------------------------------- - { "basic block comment", - "--[[bovine]]", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "unterminated block comment 1", - "--[[bovine", - FAIL, ":1: unfinished long comment near ''", - }, - ------------------------------------------------------------- - { "unterminated block comment 2", - "--[[bovine]", - FAIL, ":1: unfinished long comment near ''", - }, - ------------------------------------------------------------- - { "unterminated block comment 3", - "--[[bovine\nmoo moo\nwoof", - FAIL, ":3: unfinished long comment near ''", - }, - ------------------------------------------------------------- - { "basic long string", - "\n[[bovine]]\n", - PASS, "2 = bovine\n3 ", - }, - ------------------------------------------------------------- - { "first newline consumed in long string", - "[[\nmoo]]", - PASS, "2 = moo\n2 ", - }, - ------------------------------------------------------------- - { "multiline long string", - "[[moo\nmoo moo\n]]", - PASS, "3 = moo\nmoo moo\n\n3 ", - }, - ------------------------------------------------------------- - { "unterminated long string 1", - "\n[[\nbovine", - FAIL, ":3: unfinished long string near ''", - }, - ------------------------------------------------------------- - { "unterminated long string 2", - "[[bovine]", - FAIL, ":1: unfinished long string near ''", - }, - ------------------------------------------------------------- - { "unterminated long string 3", - "[[[[ \n", - FAIL, ":2: unfinished long string near ''", - }, - ------------------------------------------------------------- - { "nested long string 1", - "[[moo[[moo]]moo]]", - PASS, "moo[[moo]]moo", - }, - ------------------------------------------------------------- - { "nested long string 2", - "[[moo[[moo[[[[]]]]moo]]moo]]", - PASS, "moo[[moo[[[[]]]]moo]]moo", - }, - ------------------------------------------------------------- - { "nested long string 3", - "[[[[[[]]]][[[[]]]]]]", - PASS, "[[[[]]]][[[[]]]]", - }, - ------------------------------------------------------------- - { "brackets in long strings 1", - "[[moo[moo]]", - PASS, "moo[moo", - }, - ------------------------------------------------------------- - { "brackets in long strings 2", - "[[moo[[moo]moo]]moo]]", - PASS, "moo[[moo]moo]]moo", - }, - ------------------------------------------------------------- - { "unprocessed escapes in long strings", - [[ [[\a\b\f\n\r\t\v\123]] ]], - PASS, [[\a\b\f\n\r\t\v\123]], - }, - ------------------------------------------------------------- - { "unbalanced long string", - "[[moo]]moo]]", - PASS, "1 = moo\n1 = moo\n1 CHAR = ']'\n1 CHAR = ']'\n1 ", - }, - ------------------------------------------------------------- - { "keywords 1", - "and break do else", - PASS, "1 and\n1 break\n1 do\n1 else\n1 ", - }, - ------------------------------------------------------------- - { "keywords 2", - "elseif end false for", - PASS, "1 elseif\n1 end\n1 false\n1 for\n1 ", - }, - ------------------------------------------------------------- - { "keywords 3", - "function if in local nil", - PASS, "1 function\n1 if\n1 in\n1 local\n1 nil\n1 ", - }, - ------------------------------------------------------------- - { "keywords 4", - "not or repeat return", - PASS, "1 not\n1 or\n1 repeat\n1 return\n1 ", - }, - ------------------------------------------------------------- - { "keywords 5", - "then true until while", - PASS, "1 then\n1 true\n1 until\n1 while\n1 ", - }, - ------------------------------------------------------------- - { "concat and dots", - ".. ...", - PASS, "1 ..\n1 ...\n1 ", - }, - ------------------------------------------------------------- - { "shbang handling 1", - "#blahblah", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "shbang handling 2", - "#blahblah\nmoo moo\n", - PASS, "2 = moo\n2 = moo\n3 ", - }, - ------------------------------------------------------------- - { "empty string", - [['']], - PASS, "1 = \n1 ", - }, - ------------------------------------------------------------- - { "single-quoted string", - [['bovine']], - PASS, "1 = bovine\n1 ", - }, - ------------------------------------------------------------- - { "double-quoted string", - [["bovine"]], - PASS, "1 = bovine\n1 ", - }, - ------------------------------------------------------------- - { "unterminated string 1", - [['moo ]], - FAIL, ":1: unfinished string near ''", - }, - ------------------------------------------------------------- - { "unterminated string 2", - [["moo \n]], - FAIL, ":1: unfinished string near ''", - }, - ------------------------------------------------------------- - { "escaped newline in string, line number counted", - "\"moo\\\nmoo\\\nmoo\"", - PASS, "3 = moo\nmoo\nmoo\n3 ", - }, - ------------------------------------------------------------- - { "escaped characters in string 1", - [["moo\amoo"]], - PASS, "1 = moo\amoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 2", - [["moo\bmoo"]], - PASS, "1 = moo\bmoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 3", - [["moo\f\n\r\t\vmoo"]], - PASS, "1 = moo\f\n\r\t\vmoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 4", - [["\\ \" \' \? \[ \]"]], - PASS, "1 = \\ \" \' \? \[ \]", - }, - ------------------------------------------------------------- - { "escaped characters in string 5", - [["\z \k \: \;"]], - PASS, "1 = z k : ;", - }, - ------------------------------------------------------------- - { "escaped characters in string 6", - [["\8 \65 \160 \180K \097097"]], - PASS, "1 = \8 \65 \160 \180K \097097\n", - }, - ------------------------------------------------------------- - { "escaped characters in string 7", - [["\666"]], - FAIL, ":1: escape sequence too large near '\"'", - }, - ------------------------------------------------------------- - { "simple numbers", - "123 123+", - PASS, "1 = 123\n1 = 123\n1 CHAR = '+'\n1 ", - }, - ------------------------------------------------------------- - { "longer numbers", - "1234567890 12345678901234567890", - PASS, "1 = 1234567890\n1 = 1.2345678901235e+19\n", - }, - ------------------------------------------------------------- - { "fractional numbers", - ".123 .12345678901234567890", - PASS, "1 = 0.123\n1 = 0.12345678901235\n", - }, - ------------------------------------------------------------- - { "more numbers with decimal points", - "12345.67890 1.1.", - PASS, "1 = 12345.6789\n1 = 1.1\n1 CHAR = '.'\n", - }, - ------------------------------------------------------------- - { "double decimal points", - ".1.1", - FAIL, ":1: malformed number near '.1.1'", - }, - ------------------------------------------------------------- - { "double dots within numbers", - "1..1", - FAIL, ":1: ambiguous syntax (dots follows digits) near '1..'", - }, - ------------------------------------------------------------- - { "incomplete exponential numbers", - "123e", - FAIL, ":1: malformed number near '123e'", - }, - ------------------------------------------------------------- - { "exponential numbers 1", - "1234e5 1234e5.", - PASS, "1 = 123400000\n1 = 123400000\n1 CHAR = '.'", - }, - ------------------------------------------------------------- - { "exponential numbers 2", - "1234e56 1.23e123", - PASS, "1 = 1.234e+59\n1 = 1.23e+123\n", - }, - ------------------------------------------------------------- - { "exponential numbers 3", - "12.34e+", - FAIL, ":1: malformed number near '12.34e+'", - }, - ------------------------------------------------------------- - { "exponential numbers 4", - "12.34e+5 123.4e-5 1234.E+5", - PASS, "1 = 1234000\n1 = 0.001234\n1 = 123400000\n", - }, - ------------------------------------------------------------- - { "single character symbols 1", - "= > < ~", - PASS, "1 CHAR = '='\n1 CHAR = '>'\n1 CHAR = '<'\n1 CHAR = '~'\n", - }, - ------------------------------------------------------------- - { "double character symbols", - "== >= <= ~=", - PASS, "1 ==\n1 >=\n1 <=\n1 ~=\n", - }, - ------------------------------------------------------------- - { "simple identifiers", - "abc ABC", - PASS, "1 = abc\n1 = ABC\n1 ", - }, - ------------------------------------------------------------- - { "more identifiers", - "_abc _ABC", - PASS, "1 = _abc\n1 = _ABC\n1 ", - }, - ------------------------------------------------------------- - { "still more identifiers", - "_aB_ _123", - PASS, "1 = _aB_\n1 = _123\n1 ", - }, - ------------------------------------------------------------- - { "invalid control character", - "\4", - FAIL, ":1: invalid control char near 'char(4)'", - }, - ------------------------------------------------------------- - { "single character symbols 2", - "` ! @ $ %", - PASS, "1 CHAR = '`'\n1 CHAR = '!'\n1 CHAR = '@'\n1 CHAR = '$'\n1 CHAR = '%'\n", - }, - ------------------------------------------------------------- - { "single character symbols 3", - "^ & * ( )", - PASS, "1 CHAR = '^'\n1 CHAR = '&'\n1 CHAR = '*'\n1 CHAR = '('\n1 CHAR = ')'\n", - }, - ------------------------------------------------------------- - { "single character symbols 4", - "_ - + \\ |", - PASS, "1 = _\n1 CHAR = '-'\n1 CHAR = '+'\n1 CHAR = '\\'\n1 CHAR = '|'\n", - }, - ------------------------------------------------------------- - { "single character symbols 5", - "{ } [ ] :", - PASS, "1 CHAR = '{'\n1 CHAR = '}'\n1 CHAR = '['\n1 CHAR = ']'\n1 CHAR = ':'\n", - }, - ------------------------------------------------------------- - { "single character symbols 6", - "; , . / ?", - PASS, "1 CHAR = ';'\n1 CHAR = ','\n1 CHAR = '.'\n1 CHAR = '/'\n1 CHAR = '?'\n", - }, - ------------------------------------------------------------- - } - ------------------------------------------------------------------ - -- perform a test case - ------------------------------------------------------------------ - function do_test_case(count, test_case) - if comment == "" then return end -- skip empty entries - local comment, chunk, outcome, matcher = unpack(test_case) - local result = PASS - local output = "" - -- initialize lexer - local z = zio_init(chunk) - local luaX = lex_init(z, "=test") - -- lexer test loop - local status, token, seminfo - repeat - -- protected call - status, token, seminfo = pcall(luaX.lex, luaX) - output = output..luaX.lineno.." " - if status then - -- successful call - if string.len(token) > 1 then - if token == "" - or token == "" - or token == "" then - token = token.." = "..seminfo - end - elseif string.byte(token) >= 32 then -- displayable chars - token = "CHAR = '"..token.."'" - else -- control characters - token = "CHAR = (".. string.byte(token)..")" - end - output = output..token.."\n" - else - -- failed call - output = output..token -- token is the error message - result = FAIL - break - end - until token == "" - -- decision making and reporting - local head = "Test "..count..": "..comment - if matcher == "" then - -- nothing to check against, display for manual check - print(head.."\nMANUAL please check manually".. - "\n--chunk---------------------------------\n"..chunk.. - "\n--actual--------------------------------\n"..output.. - "\n\n") - return - else - if outcome == PASS then - -- success expected, may be a partial match - if string.find(output, matcher, 1, 1) and result == PASS then - if not BRIEF then print(head.."\nOK expected success\n") end - return - end - else - -- failure expected, may be a partial match - if string.find(output, matcher, 1, 1) and result == FAIL then - if not BRIEF then print(head.."\nOK expected failure\n") end - return - end - end - -- failed because of unmatched string or boolean result - local function passfail(status) - if status == PASS then return "PASS" else return "FAIL" end - end - print(head.." *FAILED*".. - "\noutcome="..passfail(outcome).. - "\nactual= "..passfail(result).. - "\n--chunk---------------------------------\n"..chunk.. - "\n--expected------------------------------\n"..matcher.. - "\n--actual--------------------------------\n"..output.. - "\n\n") - end - end - ------------------------------------------------------------------ - -- perform auto testing - ------------------------------------------------------------------ - for i,test_case in ipairs(test_cases) do - do_test_case(i, test_case) - end -end - -auto_test() ---]] diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk3.lua deleted file mode 100644 index 8b0eec9..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk3.lua +++ /dev/null @@ -1,500 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_llex.lua - Test for llex.lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ------------------------------------------------------------------------- --- if BRIEF is not set to false, auto-test will silently succeed ------------------------------------------------------------------------- -BRIEF = true -- if set to true, messages are less verbose - -local lex_init = require("../llex_mk3") - ------------------------------------------------------------------------- --- simple manual tests ------------------------------------------------------------------------- - ---[[ -local function dump(z, source) - local luaX = lex_init(z, source) - while true do - local tok, seminfo = luaX:lex() - if tok == "" then - seminfo = " "..seminfo - elseif tok == "" then - seminfo = " "..seminfo - elseif tok == "" then - seminfo = " '"..seminfo.."'" - else - seminfo = "" - end - io.stdout:write(tok..seminfo.."\n") - if tok == "" then break end - end -end - -local function try_string(chunk) - dump(chunk, "=string") -end -local function try_file(filename) - local inf = io.open(filename, "r") - if not inf then error("file not found") end - local data = inf:read("*a") - inf:close() - dump(data, "@"..filename) -end - -z = try_string("local c = z:getc()") -z = try_file("test_lzio_mk2.lua") -z = try_file("test_llex_mk2.lua") -os.exit() ---]] - ------------------------------------------------------------------------- --- auto-testing of simple test cases to validate lexer behaviour: --- * NOTE coverage has not been checked; not comprehensive --- * only test cases with non-empty comments are processed --- * if no result, then the output is displayed for manual decision --- (output may be used to set expected success or fail text) --- * cases expected to be successful may be a partial match --- * cases expected to fail may also be a partial match ------------------------------------------------------------------------- - --- [[ -local function auto_test() - local PASS, FAIL = true, false - ------------------------------------------------------------------ - -- table of test cases - ------------------------------------------------------------------ - local test_cases = - { - ------------------------------------------------------------- - --{ "comment", -- comment about the test - -- "chunk", -- chunk to test - -- PASS, -- PASS or FAIL outcome - -- "output", -- output to compare against - --}, - ------------------------------------------------------------- - { "empty chunk string, test EOS", - "", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "line number counting", - "\n\n\r\n", - PASS, "4 ", - }, - ------------------------------------------------------------- - { "various whitespaces", - " \n\t\t\n \t \t \n\n", - PASS, "5 ", - }, - ------------------------------------------------------------- - { "short comment ending in EOS", - "-- moo moo", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "short comment ending in newline", - "-- moo moo\n", - PASS, "2 ", - }, - ------------------------------------------------------------- - { "several lines of short comments", - "--moo\n-- moo moo\n\n--\tmoo\n", - PASS, "5 ", - }, - ------------------------------------------------------------- - { "basic block comment", - "--[[bovine]]", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "unterminated block comment 1", - "--[[bovine", - FAIL, ":1: unfinished long comment", - }, - ------------------------------------------------------------- - { "unterminated block comment 2", - "--[[bovine]", - FAIL, ":1: unfinished long comment", - }, - ------------------------------------------------------------- - { "unterminated block comment 3", - "--[[bovine\nmoo moo\nwoof", - FAIL, ":3: unfinished long comment", - }, - ------------------------------------------------------------- - { "basic long string", - "\n[[bovine]]\n", - PASS, "2 = bovine\n3 ", - }, - ------------------------------------------------------------- - { "first newline consumed in long string", - "[[\nmoo]]", - PASS, "2 = moo\n2 ", - }, - ------------------------------------------------------------- - { "multiline long string", - "[[moo\nmoo moo\n]]", - PASS, "3 = moo\nmoo moo\n\n3 ", - }, - ------------------------------------------------------------- - { "unterminated long string 1", - "\n[[\nbovine", - FAIL, ":3: unfinished long string", - }, - ------------------------------------------------------------- - { "unterminated long string 2", - "[[bovine]", - FAIL, ":1: unfinished long string", - }, - ------------------------------------------------------------- - { "unterminated long string 3", - "[[[[ \n", - FAIL, ":2: unfinished long string", - }, - ------------------------------------------------------------- - { "nested long string 1", - "[[moo[[moo]]moo]]", - PASS, "moo[[moo]]moo", - }, - ------------------------------------------------------------- - { "nested long string 2", - "[[moo[[moo[[[[]]]]moo]]moo]]", - PASS, "moo[[moo[[[[]]]]moo]]moo", - }, - ------------------------------------------------------------- - { "nested long string 3", - "[[[[[[]]]][[[[]]]]]]", - PASS, "[[[[]]]][[[[]]]]", - }, - ------------------------------------------------------------- - { "brackets in long strings 1", - "[[moo[moo]]", - PASS, "moo[moo", - }, - ------------------------------------------------------------- - { "brackets in long strings 2", - "[[moo[[moo]moo]]moo]]", - PASS, "moo[[moo]moo]]moo", - }, - ------------------------------------------------------------- - { "unprocessed escapes in long strings", - [[ [[\a\b\f\n\r\t\v\123]] ]], - PASS, [[\a\b\f\n\r\t\v\123]], - }, - ------------------------------------------------------------- - { "unbalanced long string", - "[[moo]]moo]]", - PASS, "1 = moo\n1 = moo\n1 CHAR = ']'\n1 CHAR = ']'\n1 ", - }, - ------------------------------------------------------------- - { "keywords 1", - "and break do else", - PASS, "1 and\n1 break\n1 do\n1 else\n1 ", - }, - ------------------------------------------------------------- - { "keywords 2", - "elseif end false for", - PASS, "1 elseif\n1 end\n1 false\n1 for\n1 ", - }, - ------------------------------------------------------------- - { "keywords 3", - "function if in local nil", - PASS, "1 function\n1 if\n1 in\n1 local\n1 nil\n1 ", - }, - ------------------------------------------------------------- - { "keywords 4", - "not or repeat return", - PASS, "1 not\n1 or\n1 repeat\n1 return\n1 ", - }, - ------------------------------------------------------------- - { "keywords 5", - "then true until while", - PASS, "1 then\n1 true\n1 until\n1 while\n1 ", - }, - ------------------------------------------------------------- - { "concat and dots", - ".. ...", - PASS, "1 ..\n1 ...\n1 ", - }, - ------------------------------------------------------------- - { "shbang handling 1", - "#blahblah", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "shbang handling 2", - "#blahblah\nmoo moo\n", - PASS, "2 = moo\n2 = moo\n3 ", - }, - ------------------------------------------------------------- - { "empty string", - [['']], - PASS, "1 = \n1 ", - }, - ------------------------------------------------------------- - { "single-quoted string", - [['bovine']], - PASS, "1 = bovine\n1 ", - }, - ------------------------------------------------------------- - { "double-quoted string", - [["bovine"]], - PASS, "1 = bovine\n1 ", - }, - ------------------------------------------------------------- - { "unterminated string 1", - [['moo ]], - FAIL, ":1: unfinished string", - }, - ------------------------------------------------------------- - { "unterminated string 2", - [["moo \n]], - FAIL, ":1: unfinished string", - }, - ------------------------------------------------------------- - { "escaped newline in string, line number counted", - "\"moo\\\nmoo\\\nmoo\"", - PASS, "3 = moo\nmoo\nmoo\n3 ", - }, - ------------------------------------------------------------- - { "escaped characters in string 1", - [["moo\amoo"]], - PASS, "1 = moo\amoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 2", - [["moo\bmoo"]], - PASS, "1 = moo\bmoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 3", - [["moo\f\n\r\t\vmoo"]], - PASS, "1 = moo\f\n\r\t\vmoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 4", - [["\\ \" \' \? \[ \]"]], - PASS, "1 = \\ \" \' \? \[ \]", - }, - ------------------------------------------------------------- - { "escaped characters in string 5", - [["\z \k \: \;"]], - PASS, "1 = z k : ;", - }, - ------------------------------------------------------------- - { "escaped characters in string 6", - [["\8 \65 \160 \180K \097097"]], - PASS, "1 = \8 \65 \160 \180K \097097\n", - }, - ------------------------------------------------------------- - { "escaped characters in string 7", - [["\666"]], - FAIL, ":1: escape sequence too large", - }, - ------------------------------------------------------------- - { "simple numbers", - "123 123+", - PASS, "1 = 123\n1 = 123\n1 CHAR = '+'\n1 ", - }, - ------------------------------------------------------------- - { "longer numbers", - "1234567890 12345678901234567890", - PASS, "1 = 1234567890\n1 = 1.2345678901235e+19\n", - }, - ------------------------------------------------------------- - { "fractional numbers", - ".123 .12345678901234567890", - PASS, "1 = 0.123\n1 = 0.12345678901235\n", - }, - ------------------------------------------------------------- - { "more numbers with decimal points", - "12345.67890 1.1.", - PASS, "1 = 12345.6789\n1 = 1.1\n1 CHAR = '.'\n", - }, - ------------------------------------------------------------- - { "double decimal points", - ".1.1", - FAIL, ":1: malformed number", - }, - ------------------------------------------------------------- - { "double dots within numbers", - "1..1", - FAIL, ":1: ambiguous syntax (dots follows digits)", - }, - ------------------------------------------------------------- - { "incomplete exponential numbers", - "123e", - FAIL, ":1: malformed number", - }, - ------------------------------------------------------------- - { "exponential numbers 1", - "1234e5 1234e5.", - PASS, "1 = 123400000\n1 = 123400000\n1 CHAR = '.'", - }, - ------------------------------------------------------------- - { "exponential numbers 2", - "1234e56 1.23e123", - PASS, "1 = 1.234e+59\n1 = 1.23e+123\n", - }, - ------------------------------------------------------------- - { "exponential numbers 3", - "12.34e+", - FAIL, ":1: malformed number", - }, - ------------------------------------------------------------- - { "exponential numbers 4", - "12.34e+5 123.4e-5 1234.E+5", - PASS, "1 = 1234000\n1 = 0.001234\n1 = 123400000\n", - }, - ------------------------------------------------------------- - { "single character symbols 1", - "= > < ~", - PASS, "1 CHAR = '='\n1 CHAR = '>'\n1 CHAR = '<'\n1 CHAR = '~'\n", - }, - ------------------------------------------------------------- - { "double character symbols", - "== >= <= ~=", - PASS, "1 ==\n1 >=\n1 <=\n1 ~=\n", - }, - ------------------------------------------------------------- - { "simple identifiers", - "abc ABC", - PASS, "1 = abc\n1 = ABC\n1 ", - }, - ------------------------------------------------------------- - { "more identifiers", - "_abc _ABC", - PASS, "1 = _abc\n1 = _ABC\n1 ", - }, - ------------------------------------------------------------- - { "still more identifiers", - "_aB_ _123", - PASS, "1 = _aB_\n1 = _123\n1 ", - }, - ------------------------------------------------------------- - { "invalid control character", - "\4", - FAIL, ":1: invalid control char", - }, - ------------------------------------------------------------- - { "single character symbols 2", - "` ! @ $ %", - PASS, "1 CHAR = '`'\n1 CHAR = '!'\n1 CHAR = '@'\n1 CHAR = '$'\n1 CHAR = '%'\n", - }, - ------------------------------------------------------------- - { "single character symbols 3", - "^ & * ( )", - PASS, "1 CHAR = '^'\n1 CHAR = '&'\n1 CHAR = '*'\n1 CHAR = '('\n1 CHAR = ')'\n", - }, - ------------------------------------------------------------- - { "single character symbols 4", - "_ - + \\ |", - PASS, "1 = _\n1 CHAR = '-'\n1 CHAR = '+'\n1 CHAR = '\\'\n1 CHAR = '|'\n", - }, - ------------------------------------------------------------- - { "single character symbols 5", - "{ } [ ] :", - PASS, "1 CHAR = '{'\n1 CHAR = '}'\n1 CHAR = '['\n1 CHAR = ']'\n1 CHAR = ':'\n", - }, - ------------------------------------------------------------- - { "single character symbols 6", - "; , . / ?", - PASS, "1 CHAR = ';'\n1 CHAR = ','\n1 CHAR = '.'\n1 CHAR = '/'\n1 CHAR = '?'\n", - }, - ------------------------------------------------------------- - } - ------------------------------------------------------------------ - -- perform a test case - ------------------------------------------------------------------ - function do_test_case(count, test_case) - if comment == "" then return end -- skip empty entries - local comment, chunk, outcome, matcher = unpack(test_case) - local result = PASS - local output = "" - -- initialize lexer - local luaX = lex_init(chunk, "=test") - -- lexer test loop - local status, token, seminfo - repeat - -- protected call - status, token, seminfo = pcall(luaX.lex, luaX) - output = output..luaX.ln.." " - if status then - -- successful call - if string.len(token) > 1 then - if token == "" - or token == "" - or token == "" then - token = token.." = "..seminfo - end - elseif string.byte(token) >= 32 then -- displayable chars - token = "CHAR = '"..token.."'" - else -- control characters - token = "CHAR = (".. string.byte(token)..")" - end - output = output..token.."\n" - else - -- failed call - output = output..token -- token is the error message - result = FAIL - break - end - until token == "" - -- decision making and reporting - local head = "Test "..count..": "..comment - if matcher == "" then - -- nothing to check against, display for manual check - print(head.."\nMANUAL please check manually".. - "\n--chunk---------------------------------\n"..chunk.. - "\n--actual--------------------------------\n"..output.. - "\n\n") - return - else - if outcome == PASS then - -- success expected, may be a partial match - if string.find(output, matcher, 1, 1) and result == PASS then - if not BRIEF then print(head.."\nOK expected success\n") end - return - end - else - -- failure expected, may be a partial match - if string.find(output, matcher, 1, 1) and result == FAIL then - if not BRIEF then print(head.."\nOK expected failure\n") end - return - end - end - -- failed because of unmatched string or boolean result - local function passfail(status) - if status == PASS then return "PASS" else return "FAIL" end - end - print(head.." *FAILED*".. - "\noutcome="..passfail(outcome).. - "\nactual= "..passfail(result).. - "\n--chunk---------------------------------\n"..chunk.. - "\n--expected------------------------------\n"..matcher.. - "\n--actual--------------------------------\n"..output.. - "\n\n") - end - end - ------------------------------------------------------------------ - -- perform auto testing - ------------------------------------------------------------------ - for i,test_case in ipairs(test_cases) do - do_test_case(i, test_case) - end -end - -auto_test() ---]] diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua deleted file mode 100644 index 316a9bf..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua +++ /dev/null @@ -1,499 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_llex.lua - Test for llex.lua - This file is part of Yueliang. - - Copyright (c) 2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ------------------------------------------------------------------------- --- if BRIEF is not set to false, auto-test will silently succeed ------------------------------------------------------------------------- -BRIEF = true -- if set to true, messages are less verbose - -local zio_init = require("../lzio_mk4") -local lex_init = require("../llex_mk4") - ------------------------------------------------------------------------- --- simple manual tests ------------------------------------------------------------------------- - ---[[ -local function dump(z, source) - local luaX = lex_init(z, source) - while true do - local tok, seminfo = luaX:lex() - if tok == "" then - seminfo = " "..seminfo - elseif tok == "" then - seminfo = " "..seminfo - elseif tok == "" then - seminfo = " '"..seminfo.."'" - else - seminfo = "" - end - io.stdout:write(tok..seminfo.."\n") - if tok == "" then break end - end -end - -local function try_string(chunk) - dump(zio_init(chunk), "=string") -end -local function try_file(filename) - local f = "@"..filename - dump(zio_init(f), f) -end - -z = try_string("local c = z:getc()") -z = try_file("test_lzio_mk2.lua") -z = try_file("test_llex_mk2.lua") -os.exit() ---]] - ------------------------------------------------------------------------- --- auto-testing of simple test cases to validate lexer behaviour: --- * NOTE coverage has not been checked; not comprehensive --- * only test cases with non-empty comments are processed --- * if no result, then the output is displayed for manual decision --- (output may be used to set expected success or fail text) --- * cases expected to be successful may be a partial match --- * cases expected to fail may also be a partial match ------------------------------------------------------------------------- - --- [[ -local function auto_test() - local PASS, FAIL = true, false - ------------------------------------------------------------------ - -- table of test cases - ------------------------------------------------------------------ - local test_cases = - { - ------------------------------------------------------------- - --{ "comment", -- comment about the test - -- "chunk", -- chunk to test - -- PASS, -- PASS or FAIL outcome - -- "output", -- output to compare against - --}, - ------------------------------------------------------------- - { "empty chunk string, test EOS", - "", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "line number counting", - "\n\n\r\n", - PASS, "4 ", - }, - ------------------------------------------------------------- - { "various whitespaces", - " \n\t\t\n \t \t \n\n", - PASS, "5 ", - }, - ------------------------------------------------------------- - { "short comment ending in EOS", - "-- moo moo", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "short comment ending in newline", - "-- moo moo\n", - PASS, "2 ", - }, - ------------------------------------------------------------- - { "several lines of short comments", - "--moo\n-- moo moo\n\n--\tmoo\n", - PASS, "5 ", - }, - ------------------------------------------------------------- - { "basic block comment", - "--[[bovine]]", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "unterminated block comment 1", - "--[[bovine", - FAIL, ":1: unfinished long comment", - }, - ------------------------------------------------------------- - { "unterminated block comment 2", - "--[[bovine]", - FAIL, ":1: unfinished long comment", - }, - ------------------------------------------------------------- - { "unterminated block comment 3", - "--[[bovine\nmoo moo\nwoof", - FAIL, ":3: unfinished long comment", - }, - ------------------------------------------------------------- - { "basic long string", - "\n[[bovine]]\n", - PASS, "2 = bovine\n3 ", - }, - ------------------------------------------------------------- - { "first newline consumed in long string", - "[[\nmoo]]", - PASS, "2 = moo\n2 ", - }, - ------------------------------------------------------------- - { "multiline long string", - "[[moo\nmoo moo\n]]", - PASS, "3 = moo\nmoo moo\n\n3 ", - }, - ------------------------------------------------------------- - { "unterminated long string 1", - "\n[[\nbovine", - FAIL, ":3: unfinished long string", - }, - ------------------------------------------------------------- - { "unterminated long string 2", - "[[bovine]", - FAIL, ":1: unfinished long string", - }, - ------------------------------------------------------------- - { "unterminated long string 3", - "[[[[ \n", - FAIL, ":2: unfinished long string", - }, - ------------------------------------------------------------- - { "nested long string 1", - "[[moo[[moo]]moo]]", - PASS, "moo[[moo]]moo", - }, - ------------------------------------------------------------- - { "nested long string 2", - "[[moo[[moo[[[[]]]]moo]]moo]]", - PASS, "moo[[moo[[[[]]]]moo]]moo", - }, - ------------------------------------------------------------- - { "nested long string 3", - "[[[[[[]]]][[[[]]]]]]", - PASS, "[[[[]]]][[[[]]]]", - }, - ------------------------------------------------------------- - { "brackets in long strings 1", - "[[moo[moo]]", - PASS, "moo[moo", - }, - ------------------------------------------------------------- - { "brackets in long strings 2", - "[[moo[[moo]moo]]moo]]", - PASS, "moo[[moo]moo]]moo", - }, - ------------------------------------------------------------- - { "unprocessed escapes in long strings", - [[ [[\a\b\f\n\r\t\v\123]] ]], - PASS, [[\a\b\f\n\r\t\v\123]], - }, - ------------------------------------------------------------- - { "unbalanced long string", - "[[moo]]moo]]", - PASS, "1 = moo\n1 = moo\n1 CHAR = ']'\n1 CHAR = ']'\n1 ", - }, - ------------------------------------------------------------- - { "keywords 1", - "and break do else", - PASS, "1 and\n1 break\n1 do\n1 else\n1 ", - }, - ------------------------------------------------------------- - { "keywords 2", - "elseif end false for", - PASS, "1 elseif\n1 end\n1 false\n1 for\n1 ", - }, - ------------------------------------------------------------- - { "keywords 3", - "function if in local nil", - PASS, "1 function\n1 if\n1 in\n1 local\n1 nil\n1 ", - }, - ------------------------------------------------------------- - { "keywords 4", - "not or repeat return", - PASS, "1 not\n1 or\n1 repeat\n1 return\n1 ", - }, - ------------------------------------------------------------- - { "keywords 5", - "then true until while", - PASS, "1 then\n1 true\n1 until\n1 while\n1 ", - }, - ------------------------------------------------------------- - { "concat and dots", - ".. ...", - PASS, "1 ..\n1 ...\n1 ", - }, - ------------------------------------------------------------- - { "shbang handling 1", - "#blahblah", - PASS, "1 ", - }, - ------------------------------------------------------------- - { "shbang handling 2", - "#blahblah\nmoo moo\n", - PASS, "2 = moo\n2 = moo\n3 ", - }, - ------------------------------------------------------------- - { "empty string", - [['']], - PASS, "1 = \n1 ", - }, - ------------------------------------------------------------- - { "single-quoted string", - [['bovine']], - PASS, "1 = bovine\n1 ", - }, - ------------------------------------------------------------- - { "double-quoted string", - [["bovine"]], - PASS, "1 = bovine\n1 ", - }, - ------------------------------------------------------------- - { "unterminated string 1", - [['moo ]], - FAIL, ":1: unfinished string", - }, - ------------------------------------------------------------- - { "unterminated string 2", - [["moo \n]], - FAIL, ":1: unfinished string", - }, - ------------------------------------------------------------- - { "escaped newline in string, line number counted", - "\"moo\\\nmoo\\\nmoo\"", - PASS, "3 = moo\nmoo\nmoo\n3 ", - }, - ------------------------------------------------------------- - { "escaped characters in string 1", - [["moo\amoo"]], - PASS, "1 = moo\amoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 2", - [["moo\bmoo"]], - PASS, "1 = moo\bmoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 3", - [["moo\f\n\r\t\vmoo"]], - PASS, "1 = moo\f\n\r\t\vmoo", - }, - ------------------------------------------------------------- - { "escaped characters in string 4", - [["\\ \" \' \? \[ \]"]], - PASS, "1 = \\ \" \' \? \[ \]", - }, - ------------------------------------------------------------- - { "escaped characters in string 5", - [["\z \k \: \;"]], - PASS, "1 = z k : ;", - }, - ------------------------------------------------------------- - { "escaped characters in string 6", - [["\8 \65 \160 \180K \097097"]], - PASS, "1 = \8 \65 \160 \180K \097097\n", - }, - ------------------------------------------------------------- - { "escaped characters in string 7", - [["\666"]], - FAIL, ":1: escape sequence too large", - }, - ------------------------------------------------------------- - { "simple numbers", - "123 123+", - PASS, "1 = 123\n1 = 123\n1 CHAR = '+'\n1 ", - }, - ------------------------------------------------------------- - { "longer numbers", - "1234567890 12345678901234567890", - PASS, "1 = 1234567890\n1 = 1.2345678901235e+19\n", - }, - ------------------------------------------------------------- - { "fractional numbers", - ".123 .12345678901234567890", - PASS, "1 = 0.123\n1 = 0.12345678901235\n", - }, - ------------------------------------------------------------- - { "more numbers with decimal points", - "12345.67890 1.1.", - PASS, "1 = 12345.6789\n1 = 1.1\n1 CHAR = '.'\n", - }, - ------------------------------------------------------------- - { "double decimal points", - ".1.1", - FAIL, ":1: malformed number", - }, - ------------------------------------------------------------- - { "double dots within numbers", - "1..1", - FAIL, ":1: ambiguous syntax (dots follows digits)", - }, - ------------------------------------------------------------- - { "incomplete exponential numbers", - "123e", - FAIL, ":1: malformed number", - }, - ------------------------------------------------------------- - { "exponential numbers 1", - "1234e5 1234e5.", - PASS, "1 = 123400000\n1 = 123400000\n1 CHAR = '.'", - }, - ------------------------------------------------------------- - { "exponential numbers 2", - "1234e56 1.23e123", - PASS, "1 = 1.234e+59\n1 = 1.23e+123\n", - }, - ------------------------------------------------------------- - { "exponential numbers 3", - "12.34e+", - FAIL, ":1: malformed number", - }, - ------------------------------------------------------------- - { "exponential numbers 4", - "12.34e+5 123.4e-5 1234.E+5", - PASS, "1 = 1234000\n1 = 0.001234\n1 = 123400000\n", - }, - ------------------------------------------------------------- - { "single character symbols 1", - "= > < ~", - PASS, "1 CHAR = '='\n1 CHAR = '>'\n1 CHAR = '<'\n1 CHAR = '~'\n", - }, - ------------------------------------------------------------- - { "double character symbols", - "== >= <= ~=", - PASS, "1 ==\n1 >=\n1 <=\n1 ~=\n", - }, - ------------------------------------------------------------- - { "simple identifiers", - "abc ABC", - PASS, "1 = abc\n1 = ABC\n1 ", - }, - ------------------------------------------------------------- - { "more identifiers", - "_abc _ABC", - PASS, "1 = _abc\n1 = _ABC\n1 ", - }, - ------------------------------------------------------------- - { "still more identifiers", - "_aB_ _123", - PASS, "1 = _aB_\n1 = _123\n1 ", - }, - ------------------------------------------------------------- - { "invalid control character", - "\4", - FAIL, ":1: invalid control char", - }, - ------------------------------------------------------------- - { "single character symbols 2", - "` ! @ $ %", - PASS, "1 CHAR = '`'\n1 CHAR = '!'\n1 CHAR = '@'\n1 CHAR = '$'\n1 CHAR = '%'\n", - }, - ------------------------------------------------------------- - { "single character symbols 3", - "^ & * ( )", - PASS, "1 CHAR = '^'\n1 CHAR = '&'\n1 CHAR = '*'\n1 CHAR = '('\n1 CHAR = ')'\n", - }, - ------------------------------------------------------------- - { "single character symbols 4", - "_ - + \\ |", - PASS, "1 = _\n1 CHAR = '-'\n1 CHAR = '+'\n1 CHAR = '\\'\n1 CHAR = '|'\n", - }, - ------------------------------------------------------------- - { "single character symbols 5", - "{ } [ ] :", - PASS, "1 CHAR = '{'\n1 CHAR = '}'\n1 CHAR = '['\n1 CHAR = ']'\n1 CHAR = ':'\n", - }, - ------------------------------------------------------------- - { "single character symbols 6", - "; , . / ?", - PASS, "1 CHAR = ';'\n1 CHAR = ','\n1 CHAR = '.'\n1 CHAR = '/'\n1 CHAR = '?'\n", - }, - ------------------------------------------------------------- - } - ------------------------------------------------------------------ - -- perform a test case - ------------------------------------------------------------------ - function do_test_case(count, test_case) - if comment == "" then return end -- skip empty entries - local comment, chunk, outcome, matcher = unpack(test_case) - local result = PASS - local output = "" - -- initialize lexer - local z = zio_init(chunk) - local luaX = lex_init(z, "=test") - -- lexer test loop - local status, token, seminfo - repeat - -- protected call - status, token, seminfo = pcall(luaX.lex, luaX) - output = output..luaX.ln.." " - if status then - -- successful call - if string.len(token) > 1 then - if token == "" - or token == "" - or token == "" then - token = token.." = "..seminfo - end - elseif string.byte(token) >= 32 then -- displayable chars - token = "CHAR = '"..token.."'" - else -- control characters - token = "CHAR = (".. string.byte(token)..")" - end - output = output..token.."\n" - else - -- failed call - output = output..token -- token is the error message - result = FAIL - break - end - until token == "" - -- decision making and reporting - local head = "Test "..count..": "..comment - if matcher == "" then - -- nothing to check against, display for manual check - print(head.."\nMANUAL please check manually".. - "\n--chunk---------------------------------\n"..chunk.. - "\n--actual--------------------------------\n"..output.. - "\n\n") - return - else - if outcome == PASS then - -- success expected, may be a partial match - if string.find(output, matcher, 1, 1) and result == PASS then - if not BRIEF then print(head.."\nOK expected success\n") end - return - end - else - -- failure expected, may be a partial match - if string.find(output, matcher, 1, 1) and result == FAIL then - if not BRIEF then print(head.."\nOK expected failure\n") end - return - end - end - -- failed because of unmatched string or boolean result - local function passfail(status) - if status == PASS then return "PASS" else return "FAIL" end - end - print(head.." *FAILED*".. - "\noutcome="..passfail(outcome).. - "\nactual= "..passfail(result).. - "\n--chunk---------------------------------\n"..chunk.. - "\n--expected------------------------------\n"..matcher.. - "\n--actual--------------------------------\n"..output.. - "\n\n") - end - end - ------------------------------------------------------------------ - -- perform auto testing - ------------------------------------------------------------------ - for i,test_case in ipairs(test_cases) do - do_test_case(i, test_case) - end -end - -auto_test() ---]] diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua deleted file mode 100644 index 662c826..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua +++ /dev/null @@ -1,218 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_lparser_mk3.lua - Test for lparser_mk3.lua - This file is part of Yueliang. - - Copyright (c) 2008 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ------------------------------------------------------------------------- --- test the whole kaboodle ------------------------------------------------------------------------- - -local lex_init = require("../llex_mk3") -local parser_init = require("../lparser_mk3") - ------------------------------------------------------------------------- --- dump contents of log table ------------------------------------------------------------------------- - -local function dump_log(fs) - local log = fs.log - for i = 1, table.getn(log) do - print(log[i]) - end -end - ------------------------------------------------------------------------- --- try 1 ------------------------------------------------------------------------- - -local luaX = lex_init("local a = 1", "=string") -local luaY = parser_init(luaX) - --- nothing is returned, so hope there is an error if problem occurs -local fs = luaY:parser() ---dump_log(fs) - ------------------------------------------------------------------------- --- try 2 ------------------------------------------------------------------------- - --- llex_mk3.lua cannot load files by itself -local INF = io.open("sample.lua", "rb") -if not INF then error("failed to load test file") end -local sample = INF:read("*a") -INF:close() - -luaX = lex_init(sample, "@sample.lua") -luaY = parser_init(luaX) - --- nothing is returned, so hope there is an error if problem occurs -local fs = luaY:parser() ---dump_log(fs) - ------------------------------------------------------------------------- --- automatic dumper of output log data ------------------------------------------------------------------------- - -local test_case = { --- 1 -[[ -]], --- 2 -[[ --- foobar -]], --- 3 -[[ -do -end -]], --- 4 -[[ -do end -do end -]], --- 5 -[[ -foo() -foo{} -foo"" -foo:bar() -foo=false -foo.bar=true -foo[true]=nil -foo,bar=1,"a" -]], --- 6 -[[ -foo=true -foo=false -foo=nil -foo=1.23e45 -foo=-1 -foo=(0) -foo=1+2 -foo=1+2*3-4/5 -]], --- 7 -[[ -if foo then foo=1 end -if foo then foo=1 else foo=0 end -if foo then foo=1 elseif not foo then foo=0 end -]], --- 8 -[[ -do return end -do return 123 end -do return "foo","bar" end -]], --- 9 -[[ -while true do foo=not foo end -while foo~=42 do foo=foo-1 end -while true do break end -]], --- 10 -[[ -repeat foo=foo.."bar" until false -repeat foo=foo/2 until foo<1 -repeat break until false -]], --- 11 -[[ -for i=1,10 do foo=i end -for i=1,10,2 do break end -for i in foo do bar=0 end -for i,j in foo,bar do baz=0 end -]], --- 12 -[[ -local foo -local foo,bar,baz -local foo,bar="foo","bar" -]], --- 13 -[[ -local function foo() return end -local function foo(a) return end -local function foo(x,y,z) return end -local function foo(x,...) return end -]], --- 14 -[[ -function foo() return end -function foo(a) return end -function foo(x,y,z) return end -function foo(x,...) return end -]], --- 15 -[[ -function foo.bar(p) return end -function foo.bar.baz(p) return end -function foo:bar(p) return end -function foo.bar.baz(p) return end -]], --- 16 -[[ -foo = function() return end -foo = function(x,y) return end -foo = function(...) return end -]], --- 17 -[[ -foo = {} -foo = { 1,2,3; "foo"; } -foo = { bar=77, baz=88, } -foo = { ["bar"]=77, ["baz"]=88, } -]], -} - --- helps to skip old stuff during development of snippets -local do_beg, do_end = 1, table.getn(test_case) - --- loop for all example snippets -for i = do_beg, do_end do - local fname = "parser_log/sample_"..string.format("%02d", i)..".lua" - local src = test_case[i] - local OUTF = io.open(fname, "wb") - if not OUTF then error("failed to write to file '"..fname.."'") end - -- write out actual source for comparison - OUTF:write( - "-- START OF SOURCE --\n".. - src.. - "-- END OF SOURCE --\n".. - "\n" - ) - -- attempt to parse - local luaX = lex_init(src, "=string") - local luaY = parser_init(luaX) - local fs = luaY:parser() - -- grab logged messages and write - local log = fs.log - local indent = 0 - for i = 1, table.getn(log) do - local ln = log[i] - -- handle indentation - local tag = string.sub(ln, 1, 2) - if tag == ">>" or tag == "<<" then - ln = string.sub(ln, 4) - end - if tag == ">>" then - indent = indent + 1 - end - OUTF:write(string.rep(" ", indent)..ln.."\n") - if tag == "<<" then - indent = indent - 1 - end - end - -- we're done - OUTF:close() -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3_2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3_2.lua deleted file mode 100644 index 957ee22..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3_2.lua +++ /dev/null @@ -1,158 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_lparser_mk3_2.lua - Test for lparser_mk3.lua, using the test case file - This file is part of Yueliang. - - Copyright (c) 2006-2008 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * unlike the equivalent in the orig-5.0.3/ directory, this version --- tests only parsing, lparser_mk3 cannot generate binary chunks --- * the test cases are in the test_lua directory (test_parser-5.0.lua) -----------------------------------------------------------------------]] - --- * true if you want an output of all failure cases in native Lua, --- for checking whether test cases fail where you intend them to -local DEBUG_FAILS = false - ------------------------------------------------------------------------- --- test the whole kaboodle ------------------------------------------------------------------------- - -local lex_init = require("../llex_mk3") -local parser_init = require("../lparser_mk3") - ------------------------------------------------------------------------- --- load test cases ------------------------------------------------------------------------- - -require("../../test_lua/test_parser-5.0") - -local test, expect, heading = {}, {}, {} -local total, total_pass, total_fail = 0, 0, 0 - -for ln in string.gfind(tests_source, "([^\n]*)\n") do - if string.find(ln, "^%s*%-%-") then - -- comment, ignore - else - local m, _, head = string.find(ln, "^%s*(TESTS:%s*.*)$") - if m then - heading[total + 1] = head -- informational heading - else - total = total + 1 - local n, _, flag = string.find(ln, "%s*%-%-%s*FAIL%s*$") - if n then -- FAIL test case - ln = string.sub(ln, 1, n - 1) -- remove comment - expect[total] = "FAIL" - total_fail = total_fail + 1 - else -- PASS test case - expect[total] = "PASS" - total_pass = total_pass + 1 - end--n - test[total] = ln - end--m - end--ln -end--for - -print("Tests loaded: "..total.." (total), " - ..total_pass.." (passes), " - ..total_fail.." (fails)") - ------------------------------------------------------------------------- --- verify test cases using native Lua ------------------------------------------------------------------------- - -local last_head = "TESTS: no heading yet" -for i = 1, total do - local test_case, expected, head = test[i], expect[i], heading[i] - -- show progress - if head then - last_head = head - if DEBUG_FAILS then print("\n"..head.."\n") end - end - ------------------------------------------------------------------ - -- perform test - local f, err = loadstring(test_case) - -- look at outcome - ------------------------------------------------------------------ - if f then-- actual PASS - if expected == "FAIL" then - print("\nVerified as PASS but expected to FAIL".. - "\n-------------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - os.exit() - end - ------------------------------------------------------------------ - else-- actual FAIL - if expected == "PASS" then - print("\nVerified as FAIL but expected to PASS".. - "\n-------------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - print("ERROR: "..err) - os.exit() - end - if DEBUG_FAILS then - print("TEST: "..test_case) - print("ERROR: "..err.."\n") - end - ------------------------------------------------------------------ - end--f -end--for - -print("Test cases verified using native Lua, no anomalies.") - ------------------------------------------------------------------------- --- test using Yueliang front end ------------------------------------------------------------------------- - -local last_head = "TESTS: no heading yet" -for i = 1, total do - local test_case, expected, head = test[i], expect[i], heading[i] - -- show progress - if head then last_head = head end - ------------------------------------------------------------------ - -- perform test - luaX = lex_init(test_case, "=test_sample") - luaY = parser_init(luaX) - - local status, func = pcall(luaY.parser, luaY) - -- look at outcome - ------------------------------------------------------------------ - if status then-- actual PASS - if expected == "FAIL" then - print("\nTested as PASS but expected to FAIL".. - "\n-----------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - os.exit() - end - ------------------------------------------------------------------ - else-- actual FAIL - if expected == "PASS" then - print("\nTested as FAIL but expected to PASS".. - "\n-----------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - os.exit() - else - io.stdout:write("-") - end - ------------------------------------------------------------------ - end--status - io.stdout:write("\rTesting ["..i.."]...") -end--for -print(" done.") - -print("Test cases run on Yueliang, no anomalies.") - --- end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua deleted file mode 100644 index d8dc33d..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua +++ /dev/null @@ -1,188 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_lparser_mk3b.lua - Test for lparser_mk3b.lua - This file is part of Yueliang. - - Copyright (c) 2008 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ------------------------------------------------------------------------- --- test the whole kaboodle ------------------------------------------------------------------------- - -local lex_init = require("../llex_mk3") -local parser_init = require("../lparser_mk3b") - ------------------------------------------------------------------------- --- dump contents of log table ------------------------------------------------------------------------- - -local function dump_log(fs) - local log = fs.log - for i = 1, table.getn(log) do - print(log[i]) - end -end - ------------------------------------------------------------------------- --- automatic dumper of output log data ------------------------------------------------------------------------- - -local test_case = { --- 1 -[[ - print(a) -]], --- 2 -[[ - local a - print(a) -]], --- 3 -[[ - do - local a - print(a) - end - print(a) -]], --- 4 -[[ - local a,b,c - do - local b - print(b) - end - print(b) -]], --- 5 -[[ - local function foo() end - bar = foo -]], --- 6 -[[ - do - local function foo() end - bar = foo - end - baz = foo -]], --- 7 -[[ - local foo - local function bar() - baz = nil - foo = bar() - end - foo = bar -]], --- 8 -[[ - local foo - local function bar() - local function baz() - local foo, bar - foo = bar - foo = baz - end - foo = bar - foo = baz - end - foo = bar - foo = baz -]], --- 9 -[[ - function foo:bar() - print(self) - end -]], --- 10 -[[ - function foo(...) - print(arg) - end -]], --- 11 -[[ - local c,d - function foo(a,b,c) - print(a,c,d,e) - end -]], --- 11 -[[ - function foo(a,b) - local bar = function(c,d) - print(a,b,c,d) - end - end -]], --- 12 -[[ - for i = 1,10 do - print(i) - end - for i = 1,10,-2 do - print(i) - end -]], --- 13 -[[ - for foo in bar() do - print(foo) - end - for foo,bar,baz in spring() do - print(foo,bar,baz) - end -]], -} - --- helps to skip old stuff during development of snippets -local do_beg, do_end = 1, table.getn(test_case) - --- loop for all example snippets -for i = do_beg, do_end do - local fname = "parser_log/sample_b_"..string.format("%02d", i)..".lua" - local src = test_case[i] - local OUTF = io.open(fname, "wb") - if not OUTF then error("failed to write to file '"..fname.."'") end - -- write out actual source for comparison - OUTF:write( - "-- START OF SOURCE --\n".. - src.. - "-- END OF SOURCE --\n".. - "\n" - ) - -- attempt to parse - local luaX = lex_init(src, "=string") - local luaY = parser_init(luaX) - local fs = luaY:parser() - -- grab logged messages and write - local log = fs.log - local indent = 0 - for i = 1, table.getn(log) do - local ln = log[i] - -- handle indentation - local tag = string.sub(ln, 1, 2) - if tag == ">>" or tag == "<<" then - ln = string.sub(ln, 4) - end - if tag == ">>" then - indent = indent + 1 - end - OUTF:write(string.rep(" ", indent)..ln.."\n") - if tag == "<<" then - indent = indent - 1 - end - end - -- we're done - OUTF:close() -end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b_2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b_2.lua deleted file mode 100644 index 4d4e8c5..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b_2.lua +++ /dev/null @@ -1,158 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_lparser_mk3b_2.lua - Test for lparser_mk3b.lua, using the test case file - This file is part of Yueliang. - - Copyright (c) 2006-2008 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - ---[[-------------------------------------------------------------------- --- Notes: --- * unlike the equivalent in the orig-5.0.3/ directory, this version --- tests only parsing, lparser_mk3 cannot generate binary chunks --- * the test cases are in the test_lua directory (test_parser-5.0.lua) -----------------------------------------------------------------------]] - --- * true if you want an output of all failure cases in native Lua, --- for checking whether test cases fail where you intend them to -local DEBUG_FAILS = false - ------------------------------------------------------------------------- --- test the whole kaboodle ------------------------------------------------------------------------- - -local lex_init = require("../llex_mk3") -local parser_init = require("../lparser_mk3b") - ------------------------------------------------------------------------- --- load test cases ------------------------------------------------------------------------- - -require("../../test_lua/test_parser-5.0") - -local test, expect, heading = {}, {}, {} -local total, total_pass, total_fail = 0, 0, 0 - -for ln in string.gfind(tests_source, "([^\n]*)\n") do - if string.find(ln, "^%s*%-%-") then - -- comment, ignore - else - local m, _, head = string.find(ln, "^%s*(TESTS:%s*.*)$") - if m then - heading[total + 1] = head -- informational heading - else - total = total + 1 - local n, _, flag = string.find(ln, "%s*%-%-%s*FAIL%s*$") - if n then -- FAIL test case - ln = string.sub(ln, 1, n - 1) -- remove comment - expect[total] = "FAIL" - total_fail = total_fail + 1 - else -- PASS test case - expect[total] = "PASS" - total_pass = total_pass + 1 - end--n - test[total] = ln - end--m - end--ln -end--for - -print("Tests loaded: "..total.." (total), " - ..total_pass.." (passes), " - ..total_fail.." (fails)") - ------------------------------------------------------------------------- --- verify test cases using native Lua ------------------------------------------------------------------------- - -local last_head = "TESTS: no heading yet" -for i = 1, total do - local test_case, expected, head = test[i], expect[i], heading[i] - -- show progress - if head then - last_head = head - if DEBUG_FAILS then print("\n"..head.."\n") end - end - ------------------------------------------------------------------ - -- perform test - local f, err = loadstring(test_case) - -- look at outcome - ------------------------------------------------------------------ - if f then-- actual PASS - if expected == "FAIL" then - print("\nVerified as PASS but expected to FAIL".. - "\n-------------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - os.exit() - end - ------------------------------------------------------------------ - else-- actual FAIL - if expected == "PASS" then - print("\nVerified as FAIL but expected to PASS".. - "\n-------------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - print("ERROR: "..err) - os.exit() - end - if DEBUG_FAILS then - print("TEST: "..test_case) - print("ERROR: "..err.."\n") - end - ------------------------------------------------------------------ - end--f -end--for - -print("Test cases verified using native Lua, no anomalies.") - ------------------------------------------------------------------------- --- test using Yueliang front end ------------------------------------------------------------------------- - -local last_head = "TESTS: no heading yet" -for i = 1, total do - local test_case, expected, head = test[i], expect[i], heading[i] - -- show progress - if head then last_head = head end - ------------------------------------------------------------------ - -- perform test - luaX = lex_init(test_case, "=test_sample") - luaY = parser_init(luaX) - - local status, func = pcall(luaY.parser, luaY) - -- look at outcome - ------------------------------------------------------------------ - if status then-- actual PASS - if expected == "FAIL" then - print("\nTested as PASS but expected to FAIL".. - "\n-----------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - os.exit() - end - ------------------------------------------------------------------ - else-- actual FAIL - if expected == "PASS" then - print("\nTested as FAIL but expected to PASS".. - "\n-----------------------------------") - print("Lastest heading: "..last_head) - print("TEST: "..test_case) - os.exit() - else - io.stdout:write("-") - end - ------------------------------------------------------------------ - end--status - io.stdout:write("\rTesting ["..i.."]...") -end--for -print(" done.") - -print("Test cases run on Yueliang, no anomalies.") - --- end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lzio_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lzio_mk2.lua deleted file mode 100644 index 30259c8..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lzio_mk2.lua +++ /dev/null @@ -1,53 +0,0 @@ ---[[-------------------------------------------------------------------- - - test_lzio.lua - Test for lzio.lua - This file is part of Yueliang. - - Copyright (c) 2005-2006 Kein-Hong Man - The COPYRIGHT file describes the conditions - under which this software may be distributed. - - See the ChangeLog for more information. - -----------------------------------------------------------------------]] - --- manual test for lzio.lua lua-style chunk reader - -local zio_init = require("../lzio_mk2") - -local z -function dump(z) - while true do - local c = z:getc() - io.stdout:write("("..c..")") - if c == "EOZ" then break end - end - io.stdout:write("\n") -end - --- z = zio_init("@") for a file --- z = zio_init("") for a string - --- [[ -z = zio_init("hello, world!") -dump(z) -z = zio_init("line1\nline2\n") -dump(z) -z = zio_init("@test_lzio_mk2.lua") -dump(z) ---]] - --- test read beyond end of file --- bug reported by Adam429 ---[[ -z = zio_init("@test_lzio_mk2.lua") -while true do - local c = z:getc() - io.stdout:write("("..c..")") - if c == "EOZ" then break end -end -print(z:getc()) -print(z:getc()) -io.stdout:write("\n") ---]] -- cgit v1.1