From 2d1df4714e2736dbde7855ddcd76b4c1de822fa5 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 23 Jan 2012 21:58:02 +1000 Subject: Added a big bunch of example lua scripts for testing the speed of lua compiling. --- LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/README | 55 + .../testLua/yueliang-0.4.1/nat-5.1.3/llex_mk2.lua | 314 +++++ .../yueliang-0.4.1/nat-5.1.3/lparser_mk2.lua | 1294 ++++++++++++++++++++ .../nat-5.1.3/test/parser_log/sample_01.lua | 9 + .../nat-5.1.3/test/parser_log/sample_02.lua | 10 + .../nat-5.1.3/test/parser_log/sample_03.lua | 21 + .../nat-5.1.3/test/parser_log/sample_04.lua | 31 + .../nat-5.1.3/test/parser_log/sample_05.lua | 129 ++ .../nat-5.1.3/test/parser_log/sample_06.lua | 132 ++ .../nat-5.1.3/test/parser_log/sample_07.lua | 147 +++ .../nat-5.1.3/test/parser_log/sample_08.lua | 66 + .../nat-5.1.3/test/parser_log/sample_09.lua | 103 ++ .../nat-5.1.3/test/parser_log/sample_10.lua | 100 ++ .../nat-5.1.3/test/parser_log/sample_11.lua | 192 +++ .../nat-5.1.3/test/parser_log/sample_12.lua | 52 + .../nat-5.1.3/test/parser_log/sample_13.lua | 108 ++ .../nat-5.1.3/test/parser_log/sample_14.lua | 112 ++ .../nat-5.1.3/test/parser_log/sample_15.lua | 140 +++ .../nat-5.1.3/test/parser_log/sample_16.lua | 128 ++ .../nat-5.1.3/test/parser_log/sample_17.lua | 110 ++ .../nat-5.1.3/test/parser_log/sample_18.lua | 26 + .../nat-5.1.3/test/parser_log/sample_19.lua | 35 + .../nat-5.1.3/test/parser_log/sample_20.lua | 64 + .../nat-5.1.3/test/parser_log/sample_21.lua | 77 ++ .../nat-5.1.3/test/parser_log/sample_22.lua | 43 + .../nat-5.1.3/test/parser_log/sample_23.lua | 70 ++ .../nat-5.1.3/test/parser_log/sample_24.lua | 84 ++ .../nat-5.1.3/test/parser_log/sample_25.lua | 159 +++ .../nat-5.1.3/test/parser_log/sample_26.lua | 53 + .../nat-5.1.3/test/parser_log/sample_27.lua | 48 + .../nat-5.1.3/test/parser_log/sample_28.lua | 79 ++ .../nat-5.1.3/test/parser_log/sample_29.lua | 94 ++ .../nat-5.1.3/test/parser_log/sample_30.lua | 119 ++ .../nat-5.1.3/test/parser_log/sample_31.lua | 127 ++ .../nat-5.1.3/test/test_llex_mk2.lua | 566 +++++++++ .../nat-5.1.3/test/test_lparser_mk2.lua | 329 +++++ .../nat-5.1.3/test/test_lparser_mk2_2.lua | 159 +++ 37 files changed, 5385 insertions(+) create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/README create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/llex_mk2.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/lparser_mk2.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_01.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_02.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_03.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_04.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_05.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_06.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_07.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_08.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_09.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_10.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_11.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_12.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_13.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_14.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_15.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_16.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_17.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_18.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_19.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_20.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_21.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_22.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_23.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_24.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_25.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_26.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_27.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_28.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_29.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_30.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_31.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.1.3') diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/README b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/README new file mode 100644 index 0000000..215b555 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/README @@ -0,0 +1,55 @@ +nat-5.1.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 +------ + +NOTE: These lexers should behave mostly identically to the original C +lexer. Locale support for non-standard decimal points is missing. Also, +all strings and long strings have line endings normalized to LF. + +llex_mk2 Rewritten from original ported code to become more + Lua-like. 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. This version is also somewhat + optimized for size; its stripped binary chunk size is + 3716 bytes. + + Status: TESTED + +Parsers +------- + +lparser_mk2 Written for the simplified lexer interface of llex_mk2. + This is a lexer skeleton, stripped of codegen code. Has + a minimum of variable management code added, and tracks + the is_vararg flag of a function. See the comments in + the source code for more information. Without logging + messages and comments, it should be under 600 LOC. A + binary chunk of lparser_mk2 (stripped) is 15783 bytes. + + Sample output of the parser message logger can be found + in the test/parser_log subdirectory. + + Tested with test_parser-5.1.lua, the Lua 5.1.x parser test + cases in the test_lua/ directory, appears to be fine. + + Compared to the 5.0.x parser skeleton, the main changes + are: (a) 'arg' not implemented, so it appears as a global, + and (b) '...' recognized as the last function parameter. + + Status: SNIPPETS APPEAR TO WORK + +Other notes: +------------ + +None. diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/llex_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/llex_mk2.lua new file mode 100644 index 0000000..dae57f1 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/llex_mk2.lua @@ -0,0 +1,314 @@ +--[[-------------------------------------------------------------------- + + llex.lua + Lua 5.1 lexical analyzer 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: +-- * takes in the entire source at once +-- * greatly simplified chunkid, error handling +-- * NO shbang handling (it's done elsewhere in Lua 5.1) +-- * NO localized decimal point replacement magic +-- * NO limit to number of lines (MAX_INT = 2147483645) +-- * NO support for compatible long strings (LUA_COMPAT_LSTR) +-- * NO next(), lookahead() because I want next() to set tok and +-- seminfo that are locals, and that can only be done easily in +-- lparser, not llex. lastline would be handled in lparser too. +-- +-- Usage example: +-- local llex = require("llex_mk2") +-- llex.init(source_code, source_code_name) +-- repeat +-- local token, seminfo = llex.llex() +-- until token == "" +-- +----------------------------------------------------------------------]] + +local base = _G +local string = require "string" +module "llex" + +---------------------------------------------------------------------- +-- initialize keyword list +---------------------------------------------------------------------- +local kw = {} +for v in string.gmatch([[ +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 + +---------------------------------------------------------------------- +-- initialize lexer for given source _z and source name _sourceid +---------------------------------------------------------------------- +local z, sourceid, I +local find = string.find +local match = string.match +local sub = string.sub + +function init(_z, _sourceid) + z = _z -- source + sourceid = _sourceid -- name of source + I = 1 -- lexer's position in source + ln = 1 -- line number +end + +---------------------------------------------------------------------- +-- returns a chunk name or id, no truncation for long names +---------------------------------------------------------------------- +function chunkid() + if sourceid and match(sourceid, "^[=@]") then + return sub(sourceid, 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 errorline(s, line) + base.error(string.format("%s:%d: %s", chunkid(), line or ln, s)) +end + +---------------------------------------------------------------------- +-- handles line number incrementation and end-of-line characters +---------------------------------------------------------------------- + +local function inclinenumber(i) + local sub = sub + local old = sub(z, i, i) + i = i + 1 -- skip '\n' or '\r' + local c = sub(z, i, i) + if (c == "\n" or c == "\r") and (c ~= old) then + i = i + 1 -- skip '\n\r' or '\r\n' + end + ln = ln + 1 + I = i + return i +end + +------------------------------------------------------------------------ +-- count separators ("=") in a long string delimiter +------------------------------------------------------------------------ +local function skip_sep(i) + local sub = sub + local s = sub(z, i, i) + i = i + 1 + local count = #match(z, "=*", i) -- note, take the length + i = i + count + I = i + return (sub(z, i, i) == s) and count or (-count) - 1 +end + +---------------------------------------------------------------------- +-- reads a long string or long comment +---------------------------------------------------------------------- + +local function read_long_string(is_str, sep) + local i = I + 1 -- skip 2nd '[' + local sub = sub + local buff = "" + local c = sub(z, i, i) + if c == "\r" or c == "\n" then -- string starts with a newline? + i = inclinenumber(i) -- skip it + end + local j = i + while true do + local p, q, r = find(z, "([\r\n%]])", i) -- (long range) + if not p then + errorline(is_str and "unfinished long string" or + "unfinished long comment") + end + if is_str then + buff = buff..sub(z, i, p - 1) -- save string portions + end + i = p + if r == "]" then -- delimiter test + if skip_sep(i) == sep then + i = I + 1 -- skip 2nd ']' + break + end + buff = buff..sub(z, i, I - 1) + i = I + else -- newline + buff = buff.."\n" + i = inclinenumber(i) + end + end--while + I = i + return buff +end + +---------------------------------------------------------------------- +-- reads a string +---------------------------------------------------------------------- +local function read_string(del) + local i = I + local find = find + local sub = sub + local buff = "" + while true do + local p, q, r = find(z, "([\n\r\\\"\'])", i) -- (long range) + if p then + if r == "\n" or r == "\r" then + 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 -- (EOZ error) + p = find("abfnrtv\n\r", r, 1, true) + ------------------------------------------------------ + if p then -- special escapes + if p > 7 then + r = "\n" + i = inclinenumber(i) + else + r = sub("\a\b\f\n\r\t\v", p, p) + 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 + errorline("escape sequence too large") + end + r = string.char(s) + ------------------------------------------------------ + end--if p + else + i = i + 1 + if r == del then -- ending delimiter + I = i; return buff -- return string + end + end--if r + buff = buff..r -- handled escapes falls through to here + else + break -- (error) + end--if p + end--while + errorline("unfinished string") +end + +------------------------------------------------------------------------ +-- main lexer function +------------------------------------------------------------------------ +function llex() + local find = find + local match = match + 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 + #r + if kw[r] then return r end -- reserved word (keyword) + return "", r -- identifier + end + ---------------------------------------------------------------- + local p, _, r = find(z, "^(%.?)%d", i) + if p then -- numeral + if r == "." then i = i + 1 end + local _, q, r = find(z, "^%d*[%.%d]*([eE]?)", i) + i = q + 1 + if #r == 1 then -- optional exponent + if match(z, "^[%+%-]", i) then -- optional sign + i = i + 1 + end + end + local _, q = find(z, "^[_%w]*", i) + I = q + 1 + local v = base.tonumber(sub(z, p, q)) -- handles hex also + if not v then errorline("malformed number") end + return "", v + end + ---------------------------------------------------------------- + local p, q, r = find(z, "^(%s)[ \t]*", i) + if p then + if r == "\n" or r == "\r" then -- newline + inclinenumber(i) + else + I = q + 1 -- whitespace + end + break -- (continue) + end + ---------------------------------------------------------------- + local r = match(z, "^%p", i) + if r then + local p = find("-[\"\'.=<>~", r, 1, true) + if p then + -- two-level if block for punctuation/symbols + -------------------------------------------------------- + if p <= 2 then + if p == 1 then -- minus + local c = match(z, "^%-%-(%[?)", i) + if c then + i = i + 2 + local sep = -1 + if c == "[" then + sep = skip_sep(i) + end + if sep >= 0 then -- long comment + read_long_string(false, sep) + else -- short comment + I = find(z, "[\n\r]", i) or (#z + 1) + end + break -- (continue) + end + -- (fall through for "-") + else -- [ or long string + local sep = skip_sep(i) + if sep >= 0 then + return "", read_long_string(true, sep) + elseif sep == -1 then + return "[" + else + errorline("invalid long string delimiter") + end + end + -------------------------------------------------------- + elseif p <= 5 then + if p < 5 then -- strings + I = i + 1 + return "", read_string(r) + end + r = match(z, "^%.%.?%.?", i) -- .|..|... dots + -- (fall through) + -------------------------------------------------------- + else -- relational + r = match(z, "^%p=?", i) + -- (fall through) + end + end + I = i + #r; return r -- for other symbols, fall through + end + ---------------------------------------------------------------- + local r = sub(z, i, i) + if r ~= "" then + I = i + 1; return r -- other single-char tokens + end + return "" -- end of stream + ---------------------------------------------------------------- + end--while inner + end--while outer +end + +return base.getfenv() diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/lparser_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/lparser_mk2.lua new file mode 100644 index 0000000..f94fb84 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/lparser_mk2.lua @@ -0,0 +1,1294 @@ +--[[-------------------------------------------------------------------- + + lparser.lua + Lua 5.1 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.1.x parser skeleton, for the llex_mk2.lua lexer +-- * builds some data, performs logging for educational purposes +-- * target is to have relatively efficient and clear code +-- * NO parsing limitations, since it is only a parser skeleton. Some +-- limits set in the default sources (in luaconf.h) are: +-- LUAI_MAXVARS = 200 +-- LUAI_MAXUPVALUES = 60 +-- LUAI_MAXCCALLS = 200 +-- * NO support for 'arg' vararg functions (LUA_COMPAT_VARARG) +-- * init(llex) needs one parameter, a lexer module that implements: +-- llex.lex() - returns appropriate [token, semantic info] pairs +-- llex.ln - current line number +-- llex.errorline(s, [line]) - dies with error message +-- +-- Usage example: +-- local llex = require("llex_mk2") +-- local lparser = require("lparser_mk2") +-- llex.init(source_code, source_code_name) +-- lparser.init(llex) +-- local fs = lparser.parser() +-- +-- Development notes: +-- * see test_parser-5.1.lua for grammar elements based on lparser.c +-- * next() (renamed to nextt) and lookahead() has been moved from llex; +-- it's more convenient to keep tok, seminfo as local variables here +-- * syntaxerror() is from llex, easier to keep here since little token +-- translation needed in preparation of error message +-- * 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) LUA_COMPAT_VARARG compatibility code completely removed +-- * (g) minimal variable management code to differentiate each type +-- * parsing starts from the end of this file in parser() +----------------------------------------------------------------------]] + +local base = _G +local string = require "string" +module "lparser" +local _G = base.getfenv() + +--[[-------------------------------------------------------------------- +-- variable and data structure initialization +----------------------------------------------------------------------]] + +---------------------------------------------------------------------- +-- initialization: main variables +---------------------------------------------------------------------- + +local llex, llex_lex -- references lexer module, function +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 -- current function state +local top_fs -- top-level function state + +-- forward references for local functions +local explist1, expr, block, exp1, body + +---------------------------------------------------------------------- +-- initialization: data structures +---------------------------------------------------------------------- + +local gmatch = string.gmatch + +local block_follow = {} -- lookahead check in chunk(), returnstat() +for v in gmatch("else elseif end until ", "%S+") do + block_follow[v] = true +end + +local stat_call = {} -- lookup for calls in stat() +for v in gmatch("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 gmatch([[ +{+ 6 6}{- 6 6}{* 7 7}{/ 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, + ["#"] = true, } -- unary operators +local UNARY_PRIORITY = 8 -- priority for unary operators + +--[[-------------------------------------------------------------------- +-- logging: this logging function is for educational purposes +-- * logged data can be retrieved from the returned data structure +----------------------------------------------------------------------]] + +local function log(msg) + local log = top_fs.log + if not log then -- initialize message table + log = {}; top_fs.log = log + end + log[#log + 1] = msg +end + +--[[-------------------------------------------------------------------- +-- support functions +----------------------------------------------------------------------]] + +---------------------------------------------------------------------- +-- handles incoming token, semantic information pairs; these two +-- functions are from llex, they are put here because keeping the +-- tok, seminfo variables here as locals is more convenient +-- * NOTE: 'nextt' is named 'next' originally +---------------------------------------------------------------------- + +-- reads in next token +local function nextt() + lastln = llex.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 = llex_lex() -- read next token + end +end + +-- peek at next token (single lookahead for table constructor) +local function lookahead() + peek_tok, peek_sem = llex_lex() + return peek_tok +end + +---------------------------------------------------------------------- +-- throws a syntax error, or if token expected is not there +---------------------------------------------------------------------- + +local function syntaxerror(msg) + local tok = tok + if tok ~= "" and tok ~= "" then + if tok == "" then tok = seminfo end + tok = "'"..tok.."'" + end + llex.errorline(msg.." near "..tok) +end + +local function error_expected(token) + syntaxerror("'"..token.."' expected") +end + +---------------------------------------------------------------------- +-- tests for a token, returns outcome +-- * return value changed to boolean +---------------------------------------------------------------------- + +local function testnext(c) + if tok == c then nextt(); return true end +end + +---------------------------------------------------------------------- +-- check for existence of a token, throws error if not found +---------------------------------------------------------------------- + +local function check(c) + if tok ~= c then error_expected(c) end +end + +---------------------------------------------------------------------- +-- verify existence of a token, then skip it +---------------------------------------------------------------------- + +local function checknext(c) + check(c); nextt() +end + +---------------------------------------------------------------------- +-- throws error if condition not matched +---------------------------------------------------------------------- + +local function check_condition(c, msg) + if not c then syntaxerror(msg) end +end + +---------------------------------------------------------------------- +-- verifies token conditions are met or else throw error +---------------------------------------------------------------------- + +local function check_match(what, who, where) + if not testnext(what) then + if where == llex.ln then + error_expected(what) + else + syntaxerror("'"..what.."' expected (to close '"..who.."' at line "..where..")") + end + end +end + +---------------------------------------------------------------------- +-- expect that token is a name, return the name +---------------------------------------------------------------------- + +local function str_checkname() + check("") + local ts = seminfo + nextt() + log(" str_checkname: '"..ts.."'") + return ts +end + +---------------------------------------------------------------------- +-- adds given string s in string pool, sets e as VK +---------------------------------------------------------------------- + +local function codestring(e, s) + e.k = "VK" + log(" codestring: "..string.format("%q", s)) +end + +---------------------------------------------------------------------- +-- consume a name token, adds it to string pool +---------------------------------------------------------------------- + +local function checkname(e) + log(" checkname:") + codestring(e, str_checkname()) +end + +--[[-------------------------------------------------------------------- +-- state management functions with open/close pairs +----------------------------------------------------------------------]] + +---------------------------------------------------------------------- +-- enters a code unit, initializes elements +---------------------------------------------------------------------- + +local function enterblock(isbreakable) + local bl = {} -- per-block state + bl.isbreakable = isbreakable + bl.prev = fs.bl + bl.locallist = {} + fs.bl = bl + log(">> enterblock(isbreakable="..base.tostring(isbreakable)..")") +end + +---------------------------------------------------------------------- +-- leaves a code unit, close any upvalues +---------------------------------------------------------------------- + +local function leaveblock() + local bl = fs.bl + fs.bl = bl.prev + log("<< leaveblock") +end + +---------------------------------------------------------------------- +-- opening of a function +-- * top_fs is only for anchoring the top fs, so that parser() can +-- return it to the caller function along with useful output +-- * used in parser() and body() +---------------------------------------------------------------------- + +local function 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 + log(">> open_func") +end + +---------------------------------------------------------------------- +-- closing of a function +-- * used in parser() and body() +---------------------------------------------------------------------- + +local function close_func() + fs = fs.prev + 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 +-- * code for a simple lookup only +-- * used in new_localvarliteral(), parlist(), fornum(), forlist(), +-- localfunc(), localstat() +---------------------------------------------------------------------- + +local function new_localvar(name) + local bl = fs.bl + local locallist + if bl then + locallist = bl.locallist + else + locallist = fs.locallist + end + locallist[name] = true + log(" new_localvar: '"..name.."'") +end + +---------------------------------------------------------------------- +-- creates a new local variable given a name +-- * used in fornum(), forlist(), parlist(), body() +---------------------------------------------------------------------- + +local function new_localvarliteral(name) + new_localvar(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() +---------------------------------------------------------------------- + +local function 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() +---------------------------------------------------------------------- + +local function singlevaraux(fs, n, var, base) + if fs == nil then -- no more levels? + var.k = "VGLOBAL" -- default is global variable + return "VGLOBAL" + else + local v = searchvar(fs, n) -- look up at current level + if v >= 0 then + var.k = "VLOCAL" + -- codegen may need to deal with upvalue here + return "VLOCAL" + else -- not found at current level; try upper one + if singlevaraux(fs.prev, n, var, 0) == "VGLOBAL" then + return "VGLOBAL" + end + -- else was LOCAL or UPVAL, handle here + var.k = "VUPVAL" -- upvalue in this level + return "VUPVAL" + end--if v + end--if fs +end + +---------------------------------------------------------------------- +-- consume a name token, creates a variable (global|local|upvalue) +-- * used in prefixexp(), funcname() +---------------------------------------------------------------------- + +local function singlevar(v) + local varname = str_checkname() + singlevaraux(fs, varname, v, 1) + 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() +---------------------------------------------------------------------- + +local function field(v) + -- field -> ['.' | ':'] NAME + local key = {} + log(" field: operator="..tok) + nextt() -- skip the dot or colon + checkname(key) + v.k = "VINDEXED" +end + +---------------------------------------------------------------------- +-- parse a table indexing suffix, for constructors, expressions +-- * used in recfield(), primaryexp() +---------------------------------------------------------------------- + +local function yindex(v) + -- index -> '[' expr ']' + log(">> index: begin '['") + nextt() -- skip the '[' + expr(v) + checknext("]") + log("<< index: end ']'") +end + +---------------------------------------------------------------------- +-- parse a table record (hash) field +-- * used in constructor() +---------------------------------------------------------------------- + +local function recfield(cc) + -- recfield -> (NAME | '['exp1']') = exp1 + local key, val = {}, {} + if tok == "" then + log("recfield: name") + checkname(key) + else-- tok == '[' + log("recfield: [ exp1 ]") + yindex(key) + end + checknext("=") + 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() +---------------------------------------------------------------------- + +local function 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() +---------------------------------------------------------------------- + +local function listfield(cc) + log("listfield: expr") + expr(cc.v) +end + +---------------------------------------------------------------------- +-- parse a table constructor +-- * used in funcargs(), simpleexp() +---------------------------------------------------------------------- + +local function constructor(t) + -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}' + -- field -> recfield | listfield + -- fieldsep -> ',' | ';' + log(">> constructor: begin") + local line = llex.ln + local cc = {} + cc.v = {} + cc.t = t + t.k = "VRELOCABLE" + cc.v.k = "VVOID" + checknext("{") + repeat + if tok == "}" then break end + -- closelistfield(cc) here + local c = tok + if c == "" then -- may be listfields or recfields + if lookahead() ~= "=" then -- look ahead: expression? + listfield(cc) + else + recfield(cc) + end + elseif c == "[" then -- constructor_item -> recfield + recfield(cc) + else -- constructor_part -> listfield + listfield(cc) + end + until not testnext(",") and not testnext(";") + check_match("}", "{", line) + -- lastlistfield(cc) here + log("<< constructor: end") +end + +---------------------------------------------------------------------- +-- parse the arguments (parameters) of a function declaration +-- * used in body() +---------------------------------------------------------------------- + +local function parlist() + -- parlist -> [ param { ',' param } ] + log(">> parlist: begin") + if tok ~= ")" then -- is 'parlist' not empty? + repeat + local c = tok + if c == "" then -- param -> NAME + new_localvar(str_checkname()) + elseif c == "..." then + log("parlist: ... (dots)") + nextt() + fs.is_vararg = true + else + syntaxerror(" or '...' expected") + end + until fs.is_vararg or not testnext(",") + end--if + log("<< parlist: end") +end + +---------------------------------------------------------------------- +-- parse the parameters of a function call +-- * contrast with parlist(), used in function declarations +-- * used in primaryexp() +---------------------------------------------------------------------- + +local function funcargs(f) + local args = {} + local line = llex.ln + local c = tok + if c == "(" then -- funcargs -> '(' [ explist1 ] ')' + log(">> funcargs: begin '('") + if line ~= lastln then + syntaxerror("ambiguous syntax (function call x new statement)") + end + nextt() + if tok == ")" then -- arg list is empty? + args.k = "VVOID" + else + explist1(args) + end + check_match(")", "(", line) + elseif c == "{" then -- funcargs -> constructor + log(">> funcargs: begin '{'") + constructor(args) + elseif c == "" then -- funcargs -> STRING + log(">> funcargs: begin ") + codestring(args, seminfo) + nextt() -- must use 'seminfo' before 'next' + else + syntaxerror("function arguments expected") + return + end--if c + f.k = "VCALL" + log("<< funcargs: end -- expr is a VCALL") +end + +--[[-------------------------------------------------------------------- +-- mostly expression functions +----------------------------------------------------------------------]] + +---------------------------------------------------------------------- +-- parses an expression in parentheses or a single variable +-- * used in primaryexp() +---------------------------------------------------------------------- + +local function prefixexp(v) + -- prefixexp -> NAME | '(' expr ')' + local c = tok + if c == "(" then + log(">> prefixexp: begin ( expr ) ") + local line = llex.ln + nextt() + expr(v) + check_match(")", "(", line) + log("<< prefixexp: end ( expr ) ") + elseif c == "" then + log("prefixexp: ") + singlevar(v) + else + 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() +---------------------------------------------------------------------- + +local function primaryexp(v) + -- primaryexp -> + -- prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } + prefixexp(v) + while true do + local c = tok + if c == "." then -- field + log("primaryexp: '.' field") + field(v) + elseif c == "[" then -- '[' exp1 ']' + log("primaryexp: [ exp1 ]") + local key = {} + yindex(key) + elseif c == ":" then -- ':' NAME funcargs + log("primaryexp: : funcargs") + local key = {} + nextt() + checkname(key) + funcargs(v) + elseif c == "(" or c == "" or c == "{" then -- funcargs + log("primaryexp: "..c.." funcargs") + funcargs(v) + else + return + end--if c + end--while +end + +---------------------------------------------------------------------- +-- parses general expression types, constants handled here +-- * used in subexpr() +---------------------------------------------------------------------- + +local function simpleexp(v) + -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... | + -- constructor | FUNCTION body | primaryexp + local c = tok + if c == "" then + log("simpleexp: ="..seminfo) + v.k = "VKNUM" + elseif c == "" then + log("simpleexp: ="..seminfo) + codestring(v, seminfo) + elseif c == "nil" then + log("simpleexp: nil") + v.k = "VNIL" + elseif c == "true" then + log("simpleexp: true") + v.k = "VTRUE" + elseif c == "false" then + log("simpleexp: false") + v.k = "VFALSE" + elseif c == "..." then -- vararg + check_condition(fs.is_vararg == true, + "cannot use '...' outside a vararg function"); + log("simpleexp: ...") + v.k = "VVARARG" + elseif c == "{" then -- constructor + log("simpleexp: constructor") + constructor(v) + return + elseif c == "function" then + log("simpleexp: function") + nextt() + body(v, false, llex.ln) + return + else + primaryexp(v) + return + end--if c + nextt() +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() +------------------------------------------------------------------------ + +local function 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 + log(" subexpr: uop='"..op.."'") + nextt() + subexpr(v, UNARY_PRIORITY) + else + 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 = {} + log(">> subexpr: binop='"..op.."'") + nextt() + -- read sub-expression with higher priority + local nextop = subexpr(v2, binopr_right[op]) + 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() +---------------------------------------------------------------------- + +-- this is a forward-referenced local +function expr(v) + -- expr -> subexpr + log("expr:") + subexpr(v, 0) +end + +--[[-------------------------------------------------------------------- +-- third level parsing functions +----------------------------------------------------------------------]] + +------------------------------------------------------------------------ +-- parse a variable assignment sequence +-- * recursively called +-- * used in expr_stat() +------------------------------------------------------------------------ + +local function assignment(v) + local e = {} + local c = v.v.k + check_condition(c == "VLOCAL" or c == "VUPVAL" or c == "VGLOBAL" + or c == "VINDEXED", "syntax error") + if testnext(",") then -- assignment -> ',' primaryexp assignment + local nv = {} -- expdesc + nv.v = {} + log("assignment: ',' -- next LHS element") + primaryexp(nv.v) + -- lparser.c deals with some register usage conflict here + assignment(nv) + else -- assignment -> '=' explist1 + checknext("=") + log("assignment: '=' -- RHS elements follows") + 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() +---------------------------------------------------------------------- + +local function forbody(isnum) + -- forbody -> DO block + checknext("do") + enterblock(false) -- scope for declared variables + block() + leaveblock() -- end of scope for declared variables +end + +---------------------------------------------------------------------- +-- parse a numerical for loop, calls forbody() +-- * used in for_stat() +---------------------------------------------------------------------- + +local function fornum(varname) + -- fornum -> NAME = exp1, exp1 [, exp1] DO body + local line = line + new_localvarliteral("(for index)") + new_localvarliteral("(for limit)") + new_localvarliteral("(for step)") + new_localvar(varname) + log(">> fornum: begin") + checknext("=") + log("fornum: index start") + exp1() -- initial value + checknext(",") + log("fornum: index stop") + exp1() -- limit + if testnext(",") then + log("fornum: index step") + exp1() -- optional step + else + -- default step = 1 + end + log("fornum: body") + forbody(true) + log("<< fornum: end") +end + +---------------------------------------------------------------------- +-- parse a generic for loop, calls forbody() +-- * used in for_stat() +---------------------------------------------------------------------- + +local function forlist(indexname) + -- forlist -> NAME {, NAME} IN explist1 DO body + log(">> forlist: begin") + local e = {} + -- create control variables + new_localvarliteral("(for generator)") + new_localvarliteral("(for state)") + new_localvarliteral("(for control)") + -- create declared variables + new_localvar(indexname) + while testnext(",") do + new_localvar(str_checkname()) + end + checknext("in") + local line = line + log("forlist: explist1") + explist1(e) + log("forlist: body") + forbody(false) + log("<< forlist: end") +end + +---------------------------------------------------------------------- +-- parse a function name specification +-- * used in func_stat() +---------------------------------------------------------------------- + +local function funcname(v) + -- funcname -> NAME {field} [':' NAME] + log(">> funcname: begin") + local needself = false + singlevar(v) + while tok == "." do + log("funcname: -- '.' field") + field(v) + end + if tok == ":" then + log("funcname: -- ':' field") + needself = true + field(v) + end + log("<< funcname: end") + return needself +end + +---------------------------------------------------------------------- +-- parse the single expressions needed in numerical for loops +-- * used in fornum() +---------------------------------------------------------------------- + +-- this is a forward-referenced local +function exp1() + -- exp1 -> expr + local e = {} + log(">> exp1: begin") + expr(e) + log("<< exp1: end") +end + +---------------------------------------------------------------------- +-- parse condition in a repeat statement or an if control structure +-- * used in repeat_stat(), test_then_block() +---------------------------------------------------------------------- + +local function cond() + -- cond -> expr + log(">> cond: begin") + local v = {} + expr(v) -- read condition + log("<< cond: end") +end + +---------------------------------------------------------------------- +-- parse part of an if control structure, including the condition +-- * used in if_stat() +---------------------------------------------------------------------- + +local function test_then_block() + -- test_then_block -> [IF | ELSEIF] cond THEN block + nextt() -- skip IF or ELSEIF + log("test_then_block: test condition") + cond() + checknext("then") + log("test_then_block: then block") + block() -- 'then' part +end + +---------------------------------------------------------------------- +-- parse a local function statement +-- * used in local_stat() +---------------------------------------------------------------------- + +local function localfunc() + -- localfunc -> NAME body + local v, b = {} + log("localfunc: begin") + new_localvar(str_checkname()) + v.k = "VLOCAL" + log("localfunc: body") + body(b, false, llex.ln) + log("localfunc: end") +end + +---------------------------------------------------------------------- +-- parse a local variable declaration statement +-- * used in local_stat() +---------------------------------------------------------------------- + +local function localstat() + -- localstat -> NAME {',' NAME} ['=' explist1] + log(">> localstat: begin") + local e = {} + repeat + new_localvar(str_checkname()) + until not testnext(",") + if testnext("=") then + log("localstat: -- assignment") + explist1(e) + else + e.k = "VVOID" + end + log("<< localstat: end") +end + +---------------------------------------------------------------------- +-- parse a list of comma-separated expressions +-- * used in return_stat(), localstat(), funcargs(), assignment(), +-- forlist() +---------------------------------------------------------------------- + +-- this is a forward-referenced local +function explist1(e) + -- explist1 -> expr { ',' expr } + log(">> explist1: begin") + expr(e) + while testnext(",") do + log("explist1: ',' -- continuation") + expr(e) + end + log("<< explist1: end") +end + +---------------------------------------------------------------------- +-- parse function declaration body +-- * used in simpleexp(), localfunc(), func_stat() +---------------------------------------------------------------------- + +-- this is a forward-referenced local +function body(e, needself, line) + -- body -> '(' parlist ')' chunk END + open_func() + log("body: begin") + checknext("(") + if needself then + new_localvarliteral("self") + end + log("body: parlist") + parlist() + checknext(")") + log("body: chunk") + chunk() + check_match("end", "function", line) + log("body: end") + close_func() +end + +---------------------------------------------------------------------- +-- parse a code block or unit +-- * used in do_stat(), while_stat(), forbody(), test_then_block(), +-- if_stat() +---------------------------------------------------------------------- + +-- this is a forward-referenced local +function block() + -- block -> chunk + log("block: begin") + enterblock(false) + chunk() + leaveblock() + log("block: end") +end + +--[[-------------------------------------------------------------------- +-- second level parsing functions, all with '_stat' suffix +-- * since they are called via a table lookup, they cannot be local +-- functions (a lookup table of local functions might be smaller...) +-- * stat() -> *_stat() +----------------------------------------------------------------------]] + +---------------------------------------------------------------------- +-- initial parsing for a for loop, calls fornum() or forlist() +-- * removed 'line' parameter (used to set debug information only) +-- * used in stat() +---------------------------------------------------------------------- + +function for_stat() + -- stat -> for_stat -> FOR (fornum | forlist) END + local line = line + log("for_stat: begin") + enterblock(true) -- scope for loop and control variables + nextt() -- skip 'for' + local varname = str_checkname() -- first variable name + local c = tok + if c == "=" then + log("for_stat: numerical loop") + fornum(varname) + elseif c == "," or c == "in" then + log("for_stat: list-based loop") + forlist(varname) + else + syntaxerror("'=' or 'in' expected") + end + check_match("end", "for", line) + leaveblock() -- loop scope (`break' jumps to this point) + log("for_stat: end") +end + +---------------------------------------------------------------------- +-- parse a while-do control structure, body processed by block() +-- * used in stat() +---------------------------------------------------------------------- + +function while_stat() + -- stat -> while_stat -> WHILE cond DO block END + local line = line + nextt() -- skip WHILE + log("while_stat: begin/condition") + cond() -- parse condition + enterblock(true) + checknext("do") + log("while_stat: block") + block() + check_match("end", "while", line) + leaveblock() + log("while_stat: end") +end + +---------------------------------------------------------------------- +-- parse a repeat-until control structure, body parsed by chunk() +-- * originally, repeatstat() calls breakstat() too if there is an +-- upvalue in the scope block; nothing is actually lexed, it is +-- actually the common code in breakstat() for closing of upvalues +-- * used in stat() +---------------------------------------------------------------------- + +function repeat_stat() + -- stat -> repeat_stat -> REPEAT block UNTIL cond + local line = line + log("repeat_stat: begin") + enterblock(true) -- loop block + enterblock(false) -- scope block + nextt() -- skip REPEAT + chunk() + check_match("until", "repeat", line) + log("repeat_stat: condition") + cond() + -- close upvalues at scope level below + leaveblock() -- finish scope + leaveblock() -- finish loop + log("repeat_stat: end") +end + +---------------------------------------------------------------------- +-- parse an if control structure +-- * used in stat() +---------------------------------------------------------------------- + +function if_stat() + -- stat -> if_stat -> IF cond THEN block + -- {ELSEIF cond THEN block} [ELSE block] END + local line = line + local v = {} + log("if_stat: if...then") + test_then_block() -- IF cond THEN block + while tok == "elseif" do + log("if_stat: elseif...then") + test_then_block() -- ELSEIF cond THEN block + end + if tok == "else" then + log("if_stat: else...") + nextt() -- skip ELSE + block() -- 'else' part + end + check_match("end", "if", line) + log("if_stat: end") +end + +---------------------------------------------------------------------- +-- parse a return statement +-- * used in stat() +---------------------------------------------------------------------- + +function return_stat() + -- stat -> return_stat -> RETURN explist + local e = {} + nextt() -- skip RETURN + local c = tok + if block_follow[c] or c == ";" then + -- return no values + log("return_stat: no return values") + else + log("return_stat: begin") + explist1(e) -- optional return values + log("return_stat: end") + end +end + +---------------------------------------------------------------------- +-- parse a break statement +-- * used in stat() +---------------------------------------------------------------------- + +function break_stat() + -- stat -> break_stat -> BREAK + local bl = fs.bl + nextt() -- skip BREAK + while bl and not bl.isbreakable do -- find a breakable block + bl = bl.prev + end + if not bl then + syntaxerror("no loop to break") + end + 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 expr_stat() + -- stat -> expr_stat -> func | assignment + local v = {} + v.v = {} + primaryexp(v.v) + if v.v.k == "VCALL" then -- stat -> func + -- call statement uses no results + log("expr_stat: function call k='"..v.v.k.."'") + else -- stat -> assignment + log("expr_stat: assignment k='"..v.v.k.."'") + v.prev = nil + assignment(v) + end +end + +---------------------------------------------------------------------- +-- parse a function statement +-- * used in stat() +---------------------------------------------------------------------- + +function function_stat() + -- stat -> function_stat -> FUNCTION funcname body + local line = line + local v, b = {}, {} + log("function_stat: begin") + nextt() -- skip FUNCTION + local needself = funcname(v) + log("function_stat: body needself='"..base.tostring(needself).."'") + body(b, needself, line) + log("function_stat: end") +end + +---------------------------------------------------------------------- +-- parse a simple block enclosed by a DO..END pair +-- * used in stat() +---------------------------------------------------------------------- + +function do_stat() + -- stat -> do_stat -> DO block END + local line = line + nextt() -- skip DO + log("do_stat: begin") + block() + log("do_stat: end") + check_match("end", "do", line) +end + +---------------------------------------------------------------------- +-- parse a statement starting with LOCAL +-- * used in stat() +---------------------------------------------------------------------- + +function local_stat() + -- stat -> local_stat -> LOCAL FUNCTION localfunc + -- -> LOCAL localstat + nextt() -- skip LOCAL + if testnext("function") then -- local function? + log("local_stat: local function") + localfunc() + else + log("local_stat: local statement") + localstat() + end +end + +--[[-------------------------------------------------------------------- +-- main functions, top level parsing functions +-- * accessible functions are: init(lexer), parser() +-- * [entry] -> parser() -> chunk() -> stat() +----------------------------------------------------------------------]] + +---------------------------------------------------------------------- +-- initial parsing for statements, calls '_stat' suffixed functions +-- * used in chunk() +---------------------------------------------------------------------- + +local function stat() + -- stat -> if_stat while_stat do_stat for_stat repeat_stat + -- function_stat local_stat return_stat break_stat + -- expr_stat + line = llex.ln -- may be needed for error messages + local c = tok + local fn = stat_call[c] + -- handles: if while do for repeat function local return break + if fn then + log("-- STATEMENT: begin '"..c.."' line="..line) + _G[fn]() + log("-- STATEMENT: end '"..c.."'") + -- return or break must be last statement + if c == "return" or c == "break" then return true end + else + log("-- STATEMENT: begin 'expr' line="..line) + expr_stat() + log("-- STATEMENT: end 'expr'") + end + log("") + return false +end + +---------------------------------------------------------------------- +-- parse a chunk, which consists of a bunch of statements +-- * used in parser(), body(), block(), repeat_stat() +---------------------------------------------------------------------- + +function chunk() + -- chunk -> { stat [';'] } + log("chunk:") + local islast = false + while not islast and not block_follow[tok] do + islast = stat() + testnext(";") + end +end + +---------------------------------------------------------------------- +-- performs parsing, returns parsed data structure +---------------------------------------------------------------------- + +function parser() + log("-- TOP: begin") + open_func() + fs.is_vararg = true -- main func. is always vararg + log("") + nextt() -- read first token + chunk() + check("") + close_func() + log("-- TOP: end") + return top_fs +end + +---------------------------------------------------------------------- +-- initialization function +---------------------------------------------------------------------- + +function init(lexer) + llex = lexer -- set lexer (assume user-initialized) + llex_lex = llex.llex + top_fs = {} -- reset top level function state +end + +return _G diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_01.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_01.lua new file mode 100644 index 0000000..379cc9d --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_01.lua @@ -0,0 +1,9 @@ +-- 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.1.3/test/parser_log/sample_02.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_02.lua new file mode 100644 index 0000000..13eb2e6 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_02.lua @@ -0,0 +1,10 @@ +-- 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.1.3/test/parser_log/sample_03.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_03.lua new file mode 100644 index 0000000..33df29c --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_03.lua @@ -0,0 +1,21 @@ +-- 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.1.3/test/parser_log/sample_04.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_04.lua new file mode 100644 index 0000000..d0fefbc --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_04.lua @@ -0,0 +1,31 @@ +-- 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.1.3/test/parser_log/sample_05.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_05.lua new file mode 100644 index 0000000..17a9231 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_05.lua @@ -0,0 +1,129 @@ +-- 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(kind): 'VGLOBAL' + 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(kind): 'VGLOBAL' + 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(kind): 'VGLOBAL' + 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(kind): 'VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + simpleexp: false + explist1: end + -- STATEMENT: end 'expr' + + -- STATEMENT: begin 'expr' line=6 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + 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(kind): 'VGLOBAL' + primaryexp: [ exp1 ] + index: begin '[' + expr: + simpleexp: true + index: end ']' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + simpleexp: nil + explist1: end + -- STATEMENT: end 'expr' + + -- STATEMENT: begin 'expr' line=8 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: ',' -- next LHS element + prefixexp: + str_checkname: 'bar' + singlevar(kind): 'VGLOBAL' + 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.1.3/test/parser_log/sample_06.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_06.lua new file mode 100644 index 0000000..29f1703 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_06.lua @@ -0,0 +1,132 @@ +-- 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + simpleexp: true + explist1: end + -- STATEMENT: end 'expr' + + -- STATEMENT: begin 'expr' line=2 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + simpleexp: false + explist1: end + -- STATEMENT: end 'expr' + + -- STATEMENT: begin 'expr' line=3 + prefixexp: + str_checkname: 'foo' + 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): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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.1.3/test/parser_log/sample_07.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_07.lua new file mode 100644 index 0000000..c3a4600 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_07.lua @@ -0,0 +1,147 @@ +-- 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(kind): 'VGLOBAL' + cond: end + test_then_block: then block + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=1 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + cond: end + test_then_block: then block + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=2 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + cond: end + test_then_block: then block + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=3 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + cond: end + test_then_block: then block + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=3 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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.1.3/test/parser_log/sample_08.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_08.lua new file mode 100644 index 0000000..d086c98 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_08.lua @@ -0,0 +1,66 @@ +-- 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.1.3/test/parser_log/sample_09.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_09.lua new file mode 100644 index 0000000..67c6cf3 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_09.lua @@ -0,0 +1,103 @@ +-- 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 + cond: begin + expr: + simpleexp: true + cond: end + enterblock(isbreakable=true) + while_stat: block + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=1 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + subexpr: uop='not' + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + explist1: end + -- STATEMENT: end 'expr' + + leaveblock + block: end + leaveblock + while_stat: end + -- STATEMENT: end 'while' + + -- STATEMENT: begin 'while' line=2 + while_stat: begin/condition + cond: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + subexpr: binop='~=' + simpleexp: =42 + subexpr: -- evaluate + cond: end + enterblock(isbreakable=true) + while_stat: block + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=2 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + 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 + cond: begin + expr: + simpleexp: true + cond: end + 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.1.3/test/parser_log/sample_10.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_10.lua new file mode 100644 index 0000000..b8e7754 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_10.lua @@ -0,0 +1,100 @@ +-- 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) + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=1 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + subexpr: binop='..' + simpleexp: =bar + codestring: "bar" + subexpr: -- evaluate + explist1: end + -- STATEMENT: end 'expr' + + repeat_stat: condition + cond: begin + expr: + simpleexp: false + cond: end + leaveblock + leaveblock + repeat_stat: end + -- STATEMENT: end 'repeat' + + -- STATEMENT: begin 'repeat' line=2 + repeat_stat: begin + enterblock(isbreakable=true) + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=2 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + subexpr: binop='/' + simpleexp: =2 + subexpr: -- evaluate + explist1: end + -- STATEMENT: end 'expr' + + repeat_stat: condition + cond: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + subexpr: binop='<' + simpleexp: =1 + subexpr: -- evaluate + cond: end + leaveblock + leaveblock + repeat_stat: end + -- STATEMENT: end 'repeat' + + -- STATEMENT: begin 'repeat' line=3 + repeat_stat: begin + enterblock(isbreakable=true) + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'break' line=3 + break_stat: -- break out of loop + -- STATEMENT: end 'break' + repeat_stat: condition + cond: begin + expr: + simpleexp: false + cond: end + leaveblock + leaveblock + repeat_stat: end + -- STATEMENT: end 'repeat' + + close_func +-- TOP: end diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_11.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_11.lua new file mode 100644 index 0000000..461ea82 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_11.lua @@ -0,0 +1,192 @@ +-- 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=true) + str_checkname: 'i' + for_stat: numerical loop + new_localvar: '(for index)' + new_localvar: '(for limit)' + new_localvar: '(for step)' + new_localvar: 'i' + 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=false) + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=1 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + prefixexp: + str_checkname: 'i' + singlevar(kind): 'VLOCAL' + 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=true) + str_checkname: 'i' + for_stat: numerical loop + new_localvar: '(for index)' + new_localvar: '(for limit)' + new_localvar: '(for step)' + new_localvar: 'i' + 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=false) + 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=true) + str_checkname: 'i' + for_stat: list-based loop + forlist: begin + new_localvar: '(for generator)' + new_localvar: '(for state)' + new_localvar: '(for control)' + new_localvar: 'i' + forlist: explist1 + explist1: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + explist1: end + forlist: body + enterblock(isbreakable=false) + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=3 + prefixexp: + str_checkname: 'bar' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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=true) + str_checkname: 'i' + for_stat: list-based loop + forlist: begin + new_localvar: '(for generator)' + new_localvar: '(for state)' + new_localvar: '(for control)' + new_localvar: 'i' + str_checkname: 'j' + new_localvar: 'j' + forlist: explist1 + explist1: begin + expr: + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + explist1: ',' -- continuation + expr: + prefixexp: + str_checkname: 'bar' + singlevar(kind): 'VGLOBAL' + explist1: end + forlist: body + enterblock(isbreakable=false) + block: begin + enterblock(isbreakable=false) + chunk: + -- STATEMENT: begin 'expr' line=4 + prefixexp: + str_checkname: 'baz' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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.1.3/test/parser_log/sample_12.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_12.lua new file mode 100644 index 0000000..c423d85 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_12.lua @@ -0,0 +1,52 @@ +-- 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' + new_localvar: 'foo' + localstat: end + -- STATEMENT: end 'local' + + -- STATEMENT: begin 'local' line=2 + local_stat: local statement + localstat: begin + str_checkname: 'foo' + new_localvar: 'foo' + str_checkname: 'bar' + new_localvar: 'bar' + str_checkname: 'baz' + new_localvar: 'baz' + localstat: end + -- STATEMENT: end 'local' + + -- STATEMENT: begin 'local' line=3 + local_stat: local statement + localstat: begin + str_checkname: 'foo' + new_localvar: 'foo' + str_checkname: 'bar' + new_localvar: '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.1.3/test/parser_log/sample_13.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_13.lua new file mode 100644 index 0000000..b5f598a --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_13.lua @@ -0,0 +1,108 @@ +-- 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' + new_localvar: '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' + new_localvar: 'foo' + localfunc: body + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'a' + new_localvar: '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' + new_localvar: 'foo' + localfunc: body + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'x' + new_localvar: 'x' + str_checkname: 'y' + new_localvar: 'y' + str_checkname: 'z' + new_localvar: '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' + new_localvar: 'foo' + localfunc: body + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'x' + new_localvar: '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.1.3/test/parser_log/sample_14.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_14.lua new file mode 100644 index 0000000..a6b9ad0 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_14.lua @@ -0,0 +1,112 @@ +-- 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(kind): 'VGLOBAL' + 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(kind): 'VGLOBAL' + funcname: end + function_stat: body needself='false' + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'a' + new_localvar: '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(kind): 'VGLOBAL' + funcname: end + function_stat: body needself='false' + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'x' + new_localvar: 'x' + str_checkname: 'y' + new_localvar: 'y' + str_checkname: 'z' + new_localvar: '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(kind): 'VGLOBAL' + funcname: end + function_stat: body needself='false' + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'x' + new_localvar: '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.1.3/test/parser_log/sample_15.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_15.lua new file mode 100644 index 0000000..497eeaf --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_15.lua @@ -0,0 +1,140 @@ +-- 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(kind): 'VGLOBAL' + 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' + new_localvar: '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(kind): 'VGLOBAL' + 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' + new_localvar: '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(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 + str_checkname: 'p' + new_localvar: '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(kind): 'VGLOBAL' + 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' + new_localvar: '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.1.3/test/parser_log/sample_16.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_16.lua new file mode 100644 index 0000000..b7907b8 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_16.lua @@ -0,0 +1,128 @@ +-- START OF SOURCE -- +foo = function() return end +foo = function(x,y) return end +foo = function(...) return end +foo = function(...) local bar = ... return end +-- END OF SOURCE -- + +-- TOP: begin + open_func + + chunk: + -- STATEMENT: begin 'expr' line=1 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + assignment: '=' -- RHS elements follows + explist1: begin + expr: + simpleexp: function + open_func + body: begin + body: parlist + parlist: begin + str_checkname: 'x' + new_localvar: 'x' + str_checkname: 'y' + new_localvar: '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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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' + + -- STATEMENT: begin 'expr' line=4 + prefixexp: + str_checkname: 'foo' + singlevar(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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 'local' line=4 + local_stat: local statement + localstat: begin + str_checkname: 'bar' + new_localvar: 'bar' + localstat: -- assignment + explist1: begin + expr: + simpleexp: ... + explist1: end + localstat: end + -- STATEMENT: end 'local' + + -- STATEMENT: begin 'return' line=4 + 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.1.3/test/parser_log/sample_17.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_17.lua new file mode 100644 index 0000000..fadc7f9 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_17.lua @@ -0,0 +1,110 @@ +-- 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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(kind): 'VGLOBAL' + expr_stat: assignment k='VGLOBAL' + 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.1.3/test/parser_log/sample_18.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_18.lua new file mode 100644 index 0000000..732b4d6 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_18.lua @@ -0,0 +1,26 @@ +-- 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.1.3/test/parser_log/sample_19.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_19.lua new file mode 100644 index 0000000..9863b4a --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_19.lua @@ -0,0 +1,35 @@ +-- 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.1.3/test/parser_log/sample_20.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_20.lua new file mode 100644 index 0000000..bc37280 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_20.lua @@ -0,0 +1,64 @@ +-- 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.1.3/test/parser_log/sample_21.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_21.lua new file mode 100644 index 0000000..b2bac4b --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_21.lua @@ -0,0 +1,77 @@ +-- 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.1.3/test/parser_log/sample_22.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_22.lua new file mode 100644 index 0000000..6885f01 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_22.lua @@ -0,0 +1,43 @@ +-- 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.1.3/test/parser_log/sample_23.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_23.lua new file mode 100644 index 0000000..eb658ed --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_23.lua @@ -0,0 +1,70 @@ +-- 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.1.3/test/parser_log/sample_24.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_24.lua new file mode 100644 index 0000000..6403234 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_24.lua @@ -0,0 +1,84 @@ +-- 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.1.3/test/parser_log/sample_25.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_25.lua new file mode 100644 index 0000000..594e267 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_25.lua @@ -0,0 +1,159 @@ +-- 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.1.3/test/parser_log/sample_26.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_26.lua new file mode 100644 index 0000000..bfa3920 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_26.lua @@ -0,0 +1,53 @@ +-- 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.1.3/test/parser_log/sample_27.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_27.lua new file mode 100644 index 0000000..77db3ef --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_27.lua @@ -0,0 +1,48 @@ +-- 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) + 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): '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.1.3/test/parser_log/sample_28.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_28.lua new file mode 100644 index 0000000..e4c9e21 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_28.lua @@ -0,0 +1,79 @@ +-- 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.1.3/test/parser_log/sample_29.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_29.lua new file mode 100644 index 0000000..b278ba2 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_29.lua @@ -0,0 +1,94 @@ +-- 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.1.3/test/parser_log/sample_30.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_30.lua new file mode 100644 index 0000000..3807d14 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_30.lua @@ -0,0 +1,119 @@ +-- 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=true) + str_checkname: 'i' + for_stat: numerical loop + new_localvar: '(for index)' + new_localvar: '(for limit)' + new_localvar: '(for step)' + new_localvar: 'i' + 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=false) + 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=true) + str_checkname: 'i' + for_stat: numerical loop + new_localvar: '(for index)' + new_localvar: '(for limit)' + new_localvar: '(for step)' + new_localvar: 'i' + 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=false) + 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.1.3/test/parser_log/sample_31.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_31.lua new file mode 100644 index 0000000..0d0a602 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/parser_log/sample_31.lua @@ -0,0 +1,127 @@ +-- 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=true) + str_checkname: 'foo' + for_stat: list-based loop + forlist: begin + new_localvar: '(for generator)' + new_localvar: '(for state)' + new_localvar: '(for control)' + 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=false) + 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=true) + str_checkname: 'foo' + for_stat: list-based loop + forlist: begin + new_localvar: '(for generator)' + new_localvar: '(for state)' + new_localvar: '(for control)' + 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=false) + 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.1.3/test/test_llex_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua new file mode 100644 index 0000000..e9ad45f --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua @@ -0,0 +1,566 @@ +--[[-------------------------------------------------------------------- + + test_llex_mk2.lua + Test for llex_mk2.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. + +----------------------------------------------------------------------]] + +------------------------------------------------------------------------ +-- if BRIEF is not set to false, auto-test will silently succeed +------------------------------------------------------------------------ +BRIEF = true -- if set to true, messages are less verbose + +package.path = "../?.lua;"..package.path +local llex = require "llex_mk2" + +------------------------------------------------------------------------ +-- simple manual tests +------------------------------------------------------------------------ + +--[[ +local function dump(z) + llex.init(z) + while true do + local token, seminfo = llex.llex() + if token == "" then + seminfo = " "..seminfo + elseif token == "" then + seminfo = " "..seminfo + elseif token == "" then + seminfo = " '"..seminfo.."'" + else + seminfo = "" + end + io.stdout:write(token..seminfo.."\n") + if token == "" then break end + end +end + +dump("local c = luaZ:zgetc(z)") +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 1", + "--[[bovine]]", + PASS, "1 ", + }, + ------------------------------------------------------------- + { "basic block comment 2", + "--[=[bovine]=]", + PASS, "1 ", + }, + ------------------------------------------------------------- + { "basic block comment 3", + "--[====[-[[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]", + FAIL, ":1: unfinished long comment", + }, + ------------------------------------------------------------- + { "unterminated block comment 4", + "--[[bovine\nmoo moo\nwoof", + FAIL, ":3: unfinished long comment", + }, + ------------------------------------------------------------- + { "basic long string 1", + "\n[[bovine]]\n", + PASS, "2 = bovine\n3 ", + }, + ------------------------------------------------------------- + { "basic long string 2", + "\n[=[bovine]=]\n", + PASS, "2 = bovine\n3 ", + }, + ------------------------------------------------------------- + { "first newline consumed in long string", + "[[\nmoo]]", + PASS, "2 = moo\n2 ", + }, + ------------------------------------------------------------- + { "multiline long string 1", + "[[moo\nmoo moo\n]]", + PASS, "3 = moo\nmoo moo\n\n3 ", + }, + ------------------------------------------------------------- + { "multiline long string 2", + "[===[moo\n[=[moo moo]=]\n]===]", + PASS, "3 = moo\n[=[moo 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 2", + "[==[bovine]==", + FAIL, ":1: unfinished long string", + }, + ------------------------------------------------------------- + { "complex long string 1", + "[=[moo[[moo]]moo]=]", + PASS, "moo[[moo]]moo", + }, + ------------------------------------------------------------- + { "complex long string 2", + "[=[moo[[moo[[[[]]]]moo]]moo]=]", + PASS, "moo[[moo[[[[]]]]moo]]moo", + }, + ------------------------------------------------------------- + { "complex long string 3", + "[=[[[[[]]]][[[[]]]]]=]", + PASS, "[[[[]]]][[[[]]]]", + }, + ------------------------------------------------------------- + -- NOTE: this native lexer does not support compatible long + -- strings (LUA_COMPAT_LSTR) + ------------------------------------------------------------- + --{ "deprecated long string 1", + -- "[[moo[[moo]]moo]]", + -- FAIL, ":1: nesting of [[...]] is deprecated near '['", + --}, + --------------------------------------------------------------- + --{ "deprecated long string 2", + -- "[[[[ \n", + -- FAIL, ":1: nesting of [[...]] is deprecated near '['", + --}, + --------------------------------------------------------------- + --{ "deprecated long string 3", + -- "[[moo[[moo[[[[]]]]moo]]moo]]", + -- FAIL, ":1: nesting of [[...]] is deprecated near '['", + --}, + --------------------------------------------------------------- + --{ "deprecated long string 4", + -- "[[[[[[]]]][[[[]]]]]]", + -- FAIL, ":1: nesting of [[...]] is deprecated near '['", + --}, + ------------------------------------------------------------- + { "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 ", + }, + ------------------------------------------------------------- + -- NOTE: in Lua 5.1.x, shbang handling is no longer performed + -- in the lexer; it is now done in lauxlib.c (luaL_loadfile) + -- so the following cannot be performed by the lexer... + ------------------------------------------------------------- + --{ "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", + PASS, "1 = 12345.6789\n", + }, + ------------------------------------------------------------- + { "malformed number with decimal points", + "1.1.", + FAIL, ":1: malformed number", + }, + ------------------------------------------------------------- + { "double decimal points", + ".1.1", + FAIL, ":1: malformed number", + }, + ------------------------------------------------------------- + { "double dots within numbers", + "1..1", + FAIL, ":1: malformed number", + }, + ------------------------------------------------------------- + { "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", + }, + ------------------------------------------------------------- + { "hexadecimal numbers", + "0x00FF 0X1234 0xDEADBEEF", + PASS, "1 = 255\n1 = 4660\n1 = 3735928559\n", + }, + ------------------------------------------------------------- + { "invalid hexadecimal numbers 1", + "0xFOO", + FAIL, ":1: malformed number", + }, + ------------------------------------------------------------- + { "invalid hexadecimal numbers 2", + "0.BAR", + FAIL, ":1: malformed number", + }, + ------------------------------------------------------------- + { "invalid hexadecimal numbers 3", + "0BAZ", + FAIL, ":1: malformed number", + }, + ------------------------------------------------------------- + { "single character symbols 1", + "= > < ~ #", + PASS, "1 CHAR = '='\n1 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 ", + }, + ------------------------------------------------------------- + -- NOTE: in Lua 5.1.x, this test is no longer performed + ------------------------------------------------------------- + --{ "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 + llex.init(chunk, "=test") + -- lexer test loop + repeat + -- protected call + local status, token, seminfo = pcall(llex.llex) + output = output..llex.ln.." " + if status then + -- successful call + if #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.1.3/test/test_lparser_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua new file mode 100644 index 0000000..11f2827 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua @@ -0,0 +1,329 @@ +--[[-------------------------------------------------------------------- + + test_lparser_mk2.lua + Test for lparser_mk2.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 +------------------------------------------------------------------------ + +package.path = "../?.lua;"..package.path +local llex = require "llex_mk2" +local lparser = require "lparser_mk2" + +------------------------------------------------------------------------ +-- dump contents of log table +------------------------------------------------------------------------ + +local function dump_log(fs) + local log = fs.log + for i = 1, #log do + print(log[i]) + end +end + +------------------------------------------------------------------------ +-- try 1 +------------------------------------------------------------------------ + +--[=[ +llex.init("local a = 1", "=string") +lparser.init(llex) +-- nothing is returned, so hope there is an error if problem occurs +local fs = lparser.parser() +dump_log(fs) +--]=] + +------------------------------------------------------------------------ +-- try 2 +------------------------------------------------------------------------ + +-- a slightly larger sample +--[=[ +llex.init([[ +local a = 47 +local b = "hello, world!" +print(a, b) +]], "@sample.lua") +lparser.init(llex) +-- nothing is returned, so hope there is an error if problem occurs +local fs = lparser.parser() +dump_log(fs) +--]=] + +------------------------------------------------------------------------ +-- automatic dumper of output log data +------------------------------------------------------------------------ + +local test_case = { +-- 1 attempts to exercise most parts, extent of coverage not known +[[ +]], +-- 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 +foo = function(...) local bar = ... return end +]], +-- 17 +[[ +foo = {} +foo = { 1,2,3; "foo"; } +foo = { bar=77, baz=88, } +foo = { ["bar"]=77, ["baz"]=88, } +]], +-- 18 simple tests for variable management follows +[[ + print(a) +]], +-- 19 +[[ + local a + print(a) +]], +-- 20 +[[ + do + local a + print(a) + end + print(a) +]], +-- 21 +[[ + local a,b,c + do + local b + print(b) + end + print(b) +]], +-- 22 +[[ + local function foo() end + bar = foo +]], +-- 23 +[[ + do + local function foo() end + bar = foo + end + baz = foo +]], +-- 24 +[[ + local foo + local function bar() + baz = nil + foo = bar() + end + foo = bar +]], +-- 25 +[[ + 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 +]], +-- 26 +[[ + function foo:bar() + print(self) + end +]], +-- 27 +[[ + function foo(...) + print(arg) + end +]], +-- 28 +[[ + local c,d + function foo(a,b,c) + print(a,c,d,e) + end +]], +-- 29 +[[ + function foo(a,b) + local bar = function(c,d) + print(a,b,c,d) + end + end +]], +-- 30 +[[ + for i = 1,10 do + print(i) + end + for i = 1,10,-2 do + print(i) + end +]], +-- 31 +[[ + 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, #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 + llex.init(src, "=string") + lparser.init(llex) + local fs = lparser.parser() + -- grab logged messages and write + local log = fs.log + local indent = 0 + for i = 1, #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.1.3/test/test_lparser_mk2_2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua new file mode 100644 index 0000000..c135a8c --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2_2.lua @@ -0,0 +1,159 @@ +--[[-------------------------------------------------------------------- + + test_lparser_mk2_2.lua + Test for lparser_mk2.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.1.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.1.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 +------------------------------------------------------------------------ + +package.path = "../?.lua;"..package.path +local llex = require "llex_mk2" +local lparser = require "lparser_mk2" + +------------------------------------------------------------------------ +-- load test cases +------------------------------------------------------------------------ + +dofile("../../test_lua/test_parser-5.1.lua") + +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 + llex.init(test_case, "=test_sample") + lparser.init(llex) + + local status, func = pcall(lparser.parser) + -- 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 -- cgit v1.1