Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local raw_tokens = dofile("Tokens.lua") -- output from your tokenizer
- --functions for env
- function table.find(tbl, val)
- for i, v in ipairs(tbl) do
- if v == val then return i end
- end
- return nil
- end
- --vars
- local BlockFollowKeyword = {'else', 'elseif', 'until', 'end'}
- local UnopSet = {'-', 'not', '#'}
- local BinopSet = {'+', '-', '*', '/', '%', '^', '#', '..', '.', ':', '>', '<', '<=', '>=', '~=', '==','+=', '-=', '*=', '/=', '%=', '^=', '..=','and', 'or'}
- local Compounds = {'+=', '-=', '*=', '/=', '^=', '..=', '%='}
- local UnaryPriority = 8
- -- Filter out newline tokens
- local tokens = {}
- for _, token in ipairs(raw_tokens) do
- if token.kind ~= "newline" then
- table.insert(tokens, token)
- end
- end
- function ParseTokens(text)
- local p = 1
- local length = #tokens
- function get()
- local tok = tokens[p]
- if p < #tokens then
- p = p + 1
- end
- return tok
- end
- function peek(n)
- local index = p + (n or 0)
- return tokens[index] or tokens[#tokens]
- end
- function look(n)
- n = n or 0
- if p <= length then
- return string.sub(text, p + n, p + n)
- else
- return ""
- end
- end
- function isBlockFollow()
- local token = peek()
- return token and token.kind == "keyword" and table.find(BlockFollowKeyword, token.value)
- end
- function isUnop()
- local token = peek()
- return token and table.find(UnopSet, token.value) or false
- end
- function isBinop()
- local token = peek()
- return token and table.find(BinopSet, token.value) or false
- end
- function expect(expected_type, expected_source)
- local tk = peek()
- if tk and tk.Type == expected_type and (expected_source == nil or tk.Source == expected_source) then
- return get()
- else
- for i = -3, 3 do
- local lookahead = peek(i)
- print(string.format("Tokens[%d] = `%s`", i, lookahead and lookahead.Source or "nil"))
- end
- end
- end
- function MkNode(node)
- local getf = node.GetFirstToken
- local getl = node.GetLastToken
- local self = node
- node.GetFirstToken = function ()
- local t = getf(self)
- assert(t, "Node has no first token")
- return t
- end
- node.GetLastToken = function ()
- local t = getl(self)
- assert(t, "Node has no last token")
- return t
- end
- return node
- end
- local block;
- local expr;
- function varlist(acceptVarg)
- local varList = {}
- local commaList = {}
- if peek().kind == "identifier" then
- table.insert(varList, get())
- elseif peek().val == "..." and acceptVarg then
- return {varList, commaList, get()}
- end
- while peek().val == "," do
- table.insert(commaList, get())
- if peek().val == "..." and acceptVarg then
- return {varList, commaList, get()}
- else
- local id = expect("identifier")
- table.insert(varList, id)
- end
- end
- return {varList, commaList}
- end
- function funcdecl(isAnonymous, locals, upvals, loc)
- local functionKw = get()
- local nameChain
- local nameChainSeperator
- if not isAnonymous then
- nameChain = {}
- nameChainSeperator = {}
- local token = peek()
- table.insert(nameChain, token)
- while peek().val == "."do
- table.insert(nameChainSeperator, get())
- table.insert(nameChain, expect("Ident"))
- end
- if peek().val == ":" then
- table.insert(nameChainSeperator, get())
- table.insert(nameChain, expect("Ident"))
- end
- end
- local oparenTk = expect("Symbol", "(")
- local argList, argCommaList, vargToken = varlist(true)
- local cparenTk = expect("Symbol", ")")
- local fbody, enTk = blockbody("end", locals, upvals)
- node = MkNode({
- Type = (isAnonymous == true and "FunctionLiteral" or "FunctionStat"),
- NameChain = nameChain,
- ArgList = argList,
- Body = fbody,
- Token_Function = functionKw,
- Token_NameChainSeperator = nameChainSeperator,
- Token_OpenParen = oparenTk,
- Token_Varg = vargToken,
- Token_CloseParen = cparenTk,
- Token_End = enTk,
- GetFirstToken = function() return node.Token_Function end,
- GetLastToken = function() return node.Token_End end,
- })
- return node
- end
- function tableexpr(locals, upvals)
- local obrace = expect("Symbol", "{")
- local entries = {}
- local seperators = {}
- local length = 0
- local lastIndex
- local valLen = 0
- while peek().val ~= "}" do
- local index
- local val
- if peek().val == "{" then
- local obrac = get()
- local index = expr(locals, upvals)
- local cbrac = expect("Symbol", "]")
- local eq = expect("Symbol", "=")
- local value = expr(locals, upvals)
- local indx = index.Token and index.Token.val or false
- val = value
- table.insert(entries, {
- EntryType = "Index",
- Index = index,
- Value = value,
- Token_OpenBracket = obrac,
- Token_CloseBracket = cbrac,
- Token_Equals = eq,
- })
- elseif peek().kind == "identifier" then
- local field = get()
- local eq = get()
- local value = expr(locals, upvals)
- inds = field
- val = value
- table.insert(entries, {
- EntryType = "Field",
- Field = field,
- Value = value,
- Token_Equals = eq,
- })
- else
- local value = expr(locals, upvals)
- table.insert(entries, {
- EntryType = "Value",
- Value = value,
- })
- end
- if peek().val == "," or peek().val == ";" then
- table.insert(seperators, get())
- else
- break
- end
- end
- local cbrace = expect("Symbol", "}")
- node = MkNode({
- Type = "TableLiteral",
- EntryList = entries,
- Token_SeperatorList = seperators,
- Token_OpenBrace = obrace,
- Token_CloseBrace = cbrace,
- GetFirstToken = function(self)
- return self.Token_OpenBrace
- end,
- GetLastToken = function(self)
- return self.Token_CloseBrace
- end
- })
- return node
- end
- function prefixexpr(locals, upvals)
- local tk = get()
- --print(tk)
- if tk.val == "(" then
- local oparenTk = get()
- local inner = expr(locals, upvals)
- local cparenTk = expect('Symbol', ')')
- node = MkNode({
- Type = "ParenExpr",
- Expression = inner,
- Token_OpenParen = oparenTk,
- Token_CloseParen = cparenTk,
- GetFirstToken = function(self)
- return self.Token_OpenParen
- end,
- GetLastToken = function(self)
- return self.Token_CloseParen
- end
- })
- return node
- elseif tk.kind == "identifier" then
- node = MkNode({
- Type = "VariableExpr",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- if locals[node.Token.Source] ~= nil then
- table.insert(locals[node.Token.Source].Tokens, node.Token)
- locals[node.Token.Source]:UseCountIncrease()
- elseif upvals[node.Token.Source] ~= nil then
- table.insert(upvals[node.Token.Source].Tokens, node.Token)
- upvals[node.Token.Source]:UseCountIncrease()
- end
- return node
- end
- end
- function functionargs(locals, upvals)
- local tk = peek()
- if tk.val == "(" then
- local oparenTk = get()
- local argList = {}
- local argCommaList = {}
- while peek().val ~= ")" do
- table.insert(argList, expr(locals, upvals))
- if peek().val == "," then
- table.insert(argCommaList, get())
- else
- break
- end
- end
- local cparenTk = expect("Symbol", ")")
- local node = MkNode({
- CallType = "ArgCall",
- ArgList = argList,
- Token_OpenParen = oparenTk,
- Token_CloseParen = cparenTk,
- GetFirstToken = function(self)
- return self.Token_OpenParen
- end,
- GetLastToken = function(self)
- return self.Token_CloseParen
- end
- })
- return node
- elseif tk.val == "{" then
- node = MkNode({
- CallType = "TableCall",
- TableExpr = expr(locals, upvals),
- GetFirstToken = function(self)
- return self.TableExpr:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.TableExpr:GetLastToken()
- end
- })
- return node
- elseif tk.kind == "string" then
- node = MkNode({
- CallType = "String",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- else
- error("Function arguments expected.")
- end
- end
- function primaryexpr(locals, upvals)
- local base = prefixexpr(locals, upvals)
- assert(base, "Expected a primary expression")
- while true do
- local tk = peek()
- if tk.val == "." then
- local dotTk = get()
- local fieldName = expect("name")
- local node = MkNode{
- Type = "FieldExpr",
- Base = base,
- Field = fieldName,
- Token_Dot = dotTk,
- GetFirstToken = function(self)
- return self.Base:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.Field
- end
- }
- elseif tk.val == ":" then
- local colonTk = get()
- local methodName = expect("Ident")
- local fargs = functionargs(locals, upvals)
- local node = MkNode{
- Type = "MethodExpr",
- Base = base,
- Method = methodName,
- FunctionArguments = fargs,
- Token_Colon = colonTk,
- GetFirstToken = function(self)
- return self.Base:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.FunctionArguments:GetLastToken()
- end
- }
- base = node
- elseif tk.val == "[" then
- local colonTk = get()
- local methodName = expect("Ident")
- local node = MkNode{
- Type = "MethodExpr",
- Base = base,
- Method = methodName,
- FunctionArguments = functionargs(locals, upvals),
- Token_Colon = colonTk,
- GetFirstToken = function(self)
- return self.Base:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.FunctionArguments:GetLastToken()
- end
- }
- base = node
- elseif tk.val == "{" then
- node = MkNode({
- Type = "CallExpr",
- Base = base,
- FunctionArguments = functionargs(locals, upvals),
- GetFirstToken = function(self)
- return self.Base:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.FunctionArguments:GetLastToken()
- end
- })
- base = node
- elseif table.find(Compounds, tk.val) then
- local compoundTk = get()
- local rhs = expr(locals, upvals)
- local node = MkNode({
- Type = "CompoundStat",
- Base = base,
- Token_Compound = compoundTk,
- Rhs = rhs,
- Lhs = base,
- GetFirstToken = function(self)
- return self.Base:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.Rhs:GetLastToken()
- end
- })
- base = node
- else
- return base
- end
- end
- end
- function simpleexpr(locals, upvals)
- local tk = peek()
- if tk.kind == "number" then
- local node = MkNode({
- Type = "NumberExpr",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- elseif tk.kind == "string" then
- node = MkNode({
- Type = "StringLiteral",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- elseif tk.kind == "hash" then
- local node = MkNode({
- Type = "HashLiteral",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- elseif tk.val == "nil" then
- local node = MkNode({
- Type = "NilLiteral",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- elseif tk.val == "true" or tk.val == "false" then
- node = MkNode({
- Type = "BooleanLiteral",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- elseif tk.val == "..." then
- local node = MkNode({
- Type = "VargLiteral",
- Token = get(),
- GetFirstToken = function(self) return self.Token end,
- GetLastToken = function(self) return self.Token end
- })
- return node
- elseif tk.val == "{" then
- return tableexpr(locals, upvals)
- elseif tk.val == "function" then
- return funcdecl(true, locals, upvals)
- else
- return primaryexpr(locals, upvals)
- end
- end
- function subexpr(limit, locals, upvals)
- local curNode;
- if isUnop() then
- local opTk = get()
- local ex = subexpr(UnaryPriority, locals, upvals)
- local node = MkNode{
- Type = "UnopExpr",
- Token_Op = opTk,
- Rhs = ex,
- GetFirstToken = function(self)
- return self.Token_Op
- end,
- GetLastToken = function(self)
- return self.Rhs:GetLastToken()
- end
- }
- curNode = node
- else
- curNode = simpleexpr(locals, upvals)
- assert(curNode, "Expected a simple expression")
- end
- end
- function expr(locals, upvals)
- return subexpr(0, locals, upvals)
- end
- function exprlist(locals, upvals)
- local exprList = { expr(locals, upvals) }
- local commaList = {}
- while peek().Source == "," do
- table.insert(commaList, get())
- table.insert(exprList, expr(locals, upvals))
- end
- return {exprList, commaList}
- end
- function blockbody(terminator, locals, upvals)
- local body = block(locals, upvals)
- local after = peek()
- if after.kind == "keyword" and after.value == terminator then
- return body, get()
- end
- end
- function subexpr(limit, locals, upvals)
- local curNode
- if isUnop() then
- local opTK = get()
- local ex = subexpr(UnaryPriority, locals, upvals)
- node = MkNode({
- Type = "UnopExpr",
- Token_Op = opTk,
- Rhs = ex,
- GetFirstToken = function() return node.Token_Op end,
- GetLastToken = function() return node.Rhs:GetLastToken() end,
- })
- curNode = node
- else
- curNode = simpleexpr(locals, upvals)
- assert(curNode, "nil simpleexpr")
- end
- end
- expr = function(locals, upvals)
- return subexpr(0, locals, upvals)
- end
- function exprstat(locals, upvals)
- local ex = primaryexpr(locals, upvals)
- if ex.kind == "MethodExpr" or ex.Type == "CallExpr" then
- node = MkNode({
- Type = "CallExprStat",
- Expression = ex,
- GetFirstToken = function(self)
- return self.Expression:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.Expression:GetLastToken()
- end
- })
- return node
- elseif ex.kind == "CompoundStat" then
- return ex
- else
- local lhs = {ex}
- local lhsSeperator = {}
- while peek().val == "," do
- table.insert(lhsSeperator, get())
- local lhsPart = primaryexpr(locals, upvals)
- if lhsPart.Type == "MethodExpr" or lhsPart.Type == "CallExpr" then
- error("Bad left hand side of assignment")
- end
- table.insert(lhs, lhsPart)
- end
- local eq = expect("Symbol", "=")
- local rhs = { expr(locals, upvals) }
- local rhsSeperator = {}
- while peek().val == "," do
- table.insert(rhsSeperator, get())
- table.insert(rhs, expr(locals, upvals))
- end
- node = MkNode({
- Type = "AssignmentStat",
- Rhs = rhs,
- Lhs = lhs,
- Token_Equals = eq,
- Token_LhsSeperatorList = lhsSeperator,
- Token_RhsSeperatorList = rhsSeperator,
- GetFirstToken = function(self)
- return self.Lhs[1]:GetFirstToken()
- end,
- GetLastToken = function(self)
- return self.Rhs[#self.Rhs]:GetLastToken()
- end
- })
- return node
- end
- end
- function ifstat(locals, upvals)
- local ifKw = get()
- local condition = expr(locals, upvals)
- local thenKw = expect("Keyword", "then")
- local ifBody = block(locals, upvals)
- local elseClauses = {}
- while peek().val == "elseif" or peek().val == "else" do
- local elseifKw = get()
- local elseifCondition
- local elseifThenKw
- if elseifKw.val == "elseif" then
- elseifCondition = expr(locals, upvals)
- elseifThenKw = expect("Keyword", "then")
- end
- local elseifBody = block(locals, upvals)
- table.insert(elseClauses, {
- Condition = elseifCondition,
- Body = elseifBody,
- ClauseType = elseifKw.val,
- Token = elseifKw,
- Token_Then = elseifThenKw
- })
- if elseifKw.val == "else" then
- break
- end
- end
- local enKw = expect("Keyword", "end")
- node = MkNode({
- Type = "IfStat",
- Condition = condition,
- Body = ifBody,
- ElseClauseList = elseClauses,
- Token_If = ifKw,
- Token_Then = thenKw,
- Token_End = enKw,
- GetFirstToken = function(self)
- return self.Token_If
- end,
- GetLastToken = function(self)
- return self.Token_End
- end
- })
- return node
- end
- function dostat(locals, upvals)
- local doKw = get()
- local body, enKw = blockbody("end", locals, upvals)
- node = MkNode({
- Type = "DoStat",
- Body = body,
- Token_Do = doKw,
- Token_End = enKw,
- GetFirstToken = function(self)
- return self.Token_Do
- end,
- GetLastToken = function(self)
- return self.Token_End
- end
- })
- return node
- end
- function whilestat(locals, upvals)
- local whileKw = get()
- local condition = expr(locals, upvals)
- local thenKw = expect("Keyword", "do")
- local body, enKw = blockbody("end", locals, upvals)
- node = MkNode({
- Type = "WhileStat",
- Condition = condition,
- Body = body,
- Token_While = whileKw,
- Token_Do = thenKw,
- Token_End = enKw,
- GetFirstToken = function(self)
- return self.Token_While
- end,
- GetLastToken = function(self)
- return self.Token_End
- end
- })
- return node
- end
- function forstat(locals, upvals)
- local forkw = get()
- local loopVars, loopVarCommas = varlist()
- local node = {}
- if peek().val == "=" then
- local eqTk = get()
- local exprList = exprlist(locals, upvals)
- if #exprList < 2 or #exprList > 3 then
- error("Expected 2 or 3 expressions for numeric for loop")
- end
- local doTk = expect("Keyword", "do")
- local body, enTk = blockbody("end", locals, upvals)
- node = MkNode({
- Type = "NumericForStat",
- VarList = loopVars,
- RangeList = exprList,
- Body = body,
- Token_For = forkw,
- Token_Equals = eqTk,
- Token_Do = doTk,
- Token_End = enTk,
- GetFirstToken = function(self)
- return self.Token_For
- end,
- GetLastToken = function(self)
- return self.Token_End
- end
- })
- return node
- elseif peek().val == "in" then
- local inTk = get()
- local exprList = exprlist(locals, upvals)
- local doTk = expect("Keyword", "do")
- local body, enTk = blockbody("end", locals, upvals)
- node = MkNode({
- Type = "GenericForStat",
- VarList = loopVars,
- GeneratorList = exprList,
- Body = body,
- Token_For = forkw,
- Token_In = inTk,
- Token_Do = doTk,
- Token_End = enTk,
- GetFirstToken = function(self)
- return self.Token_For
- end,
- GetLastToken = function(self)
- return self.Token_End
- end
- })
- return node
- end
- end
- function repeatstat(locals, upvals)
- local repeatKw = get()
- local body, untilTk = blockbody("until", locals, upvals)
- local condition = expr(locals, upvals)
- node = MkNode({
- Type = "RepeatStat",
- Body = body,
- Condition = condition,
- Token_Repeat = repeatKw,
- Token_Until = untilTk,
- GetFirstToken = function(self)
- return self.Token_Repeat
- end,
- GetLastToken = function(self)
- return self.Condition:GetLastToken()
- end
- })
- return node
- end
- function localdecl(locals, upvals)
- local localKw = get()
- if peek().val == "function" then
- local funcStat = funcdecl(false, locals, upvals, true)
- node = MkNode({
- Type = "LocalFunctionStat",
- FunctionStat = funcStat,
- Token_Local = localKw,
- GetFirstToken = function(self)
- return self.Token_Local
- end,
- GetLastToken = function(self)
- return self.FunctionStat:GetLastToken()
- end
- })
- return node
- elseif peek().kind == "identifier" then
- local varList, varCommaList = varlist(false)
- local exprList = {}
- local eqToken
- if peek().val == "=" then
- eqToken = get()
- local exprList1 = exprlist(locals, upvals)
- exprList = exprlist(locals, upvals)
- node = MkNode({
- Type = "LocalVarStat",
- VarList = varList,
- ExprList = exprList,
- Token_Local = localKw,
- Token_Equals = eqToken,
- GetFirstToken = function(self)
- return self.Token_Local
- end,
- GetLastToken = function()
- if #node.ExprList > 0 then
- return node.ExprList[#node.ExprList]:GetLastToken()
- else
- return node.VarList[#node.VarList]
- end
- end
- })
- return node
- else
- error("`function` or ident expected")
- end
- end
- end
- function retstat(locals, upvals)
- local returnKw = get()
- local exprList
- local commaList
- if isBlockFollow() then
- exprList = {}
- commaList = {}
- else
- exprList, commaList = exprlist(locals, upvals)
- end
- local self
- self = {
- Type = "ReturnStat",
- ExprList = exprList,
- Token_Return = returnKw,
- Token_CommaList = commaList,
- GetFirstToken = function(self)
- return self.Token_Return
- end,
- GetLastToken = function(self)
- if #self.ExprList > 0 then
- return self.ExprList[#self.ExprList]:GetLastToken()
- else
- return self.Token_Return
- end
- end
- }
- return self
- end
- function breakstat(locals, upvals)
- local breakKw = get()
- local self = {
- Type = "BreakStat",
- Token_Break = breakKw,
- GetFirstToken = function(self)
- return self.Token_Break
- end,
- GetLastToken = function(self)
- return self.Token_Break
- end
- }
- return self
- end
- function continuestat(locals, upvals)
- local continueKw = get()
- local self = {
- Type = "ContinueStat",
- Token_Continue = continueKw,
- GetFirstToken = function(self)
- return self.Token_Continue
- end,
- GetLastToken = function(self)
- return self.Token_Continue
- end
- }
- return self
- end
- function statement(locals, upvals)
- local tok = peek()
- if tok.val == "if" then
- return { false, ifstat(locals, upvals) }
- elseif tok.val == "while" then
- return { false, whilestat(locals, upvals) }
- elseif tok.val == "do" then
- return { false, dostat(locals, upvals) }
- elseif tok.val == "for" then
- return { false, forstat(locals, upvals) }
- elseif tok.val == "repeat" then
- return { false, repeatstat(locals, upvals) }
- elseif tok.val == "function" then
- return { false, funcdecl(false, locals, upvals) }
- elseif tok.val == "local" then
- return { false, localdecl(locals, upvals) }
- elseif tok.val == "return" then
- return { true, retstat(locals, upvals) }
- elseif tok.val == "break" then
- return { true, breakstat(locals, upvals) }
- elseif tok.val == "continue" then
- return { true, continuestat(locals, upvals) }
- else
- return { false, exprstat(locals, upvals) }
- end
- end
- local blocks = 1
- block = function(a,b)
- local myblocknum = blocks + 1
- local statements = {}
- local semicolons = {}
- local isLast = false
- local locals = {}
- local upvals = {}
- if b ~= nil then
- for i,v in pairs(b) do
- upvals[i] = v
- end
- end
- if a ~= nil then
- for i,v in pairs(a) do
- upvals[i] = v
- end
- end
- local thing
- local i = 0
- while not isLast and not isBlockFollow() do
- if thing and thing == peek() then
- print("INFINITE LOOP POSSIBLE ON STATEMENT " .. thing.val .. " :", thing)
- end
- thing = peek()
- isLast, stat = statement(locals, upvals)
- if stat then
- table.insert(statements, statement)
- if stat.Type == "LocalVarStat" then
- for _, token in ipairs(stat.VarList) do
- token.UseCount = 0
- token.Number = 1
- i = i + 1
- locals[token.val] = token
- local tokens = {}
- function lol()
- token.UseCount = token.UseCount + 1
- for _, t in ipairs(tokens) do
- t.UseCount = token.UseCount
- end
- end
- token.Tokens = {}
- function token.Tokens.push(t)
- t.UseCountIncrease = lol
- t.UseCount = token.UseCount
- t.Tokens = token.Tokens
- table.insert(tokens, t)
- end
- function token.Tokens.get()
- return tokens
- end
- token.UseCountIncrease = lol
- end
- break
- elseif stat.Type == "LocalFunctionStat" then
- local nameChain = stat.FunctionStat.NameChain
- if #nameChain == 1 then
- local token = nameChain[1]
- token.UseCount = 0
- token.Number = 1
- i = i + 1
- locals[token.val] = token
- local tokens = {}
- function lol()
- token.UseCount = token.UseCount + 1
- for _, t in ipairs(tokens) do
- t.UseCount = token.UseCount
- end
- end
- token.Tokens = {}
- function token.Tokens.push(t)
- t.UseCountIncrease = lol
- t.UseCount = token.UseCount
- t.Tokens = token.Tokens
- table.insert(tokens, t)
- end
- function token.Tokens.get()
- return tokens
- end
- token.UseCountIncrease = lol
- end
- break
- else
- break
- end
- end
- local next = peek()
- if next.kind == "symbol" and next.val == ";" then
- table.insert(semicolons, get())
- end
- end
- node = {
- Type = "StatList",
- StatementList = statements,
- GetFirstToken = function(self)
- if #node.StatementList == 0 then
- return
- else
- return node.StatementList[1]:GetFirstToken()
- end
- end,
- GetLastToken = function(self)
- if #node.StatementList == 0 then
- return
- else
- return node.StatementList[#node.StatementList]:GetLastToken()
- end
- end
- }
- return node
- end
- return block({}, {})
- end
- ParseTokens(tokens)
Advertisement
Add Comment
Please, Sign In to add comment