ScriptTable ParseTable(CodeTable table) { ScriptTable ret = m_script.CreateTable(); foreach (CodeTable.TableVariable variable in table.Variables) { ret.SetValue(variable.key, ResolveOperand(variable.value)); } foreach (ScriptScriptFunction func in table.Functions) { func.SetTable(ret); ret.SetValue(func.Name, func); } return ret; }
//返回Table数据 private CodeTable GetTable() { CodeTable ret = new CodeTable(); ReadLeftBrace(); while (PeekToken().Type != TokenType.RightBrace) { Token token = ReadToken(); if (token.Type == TokenType.Identifier || token.Type == TokenType.String || token.Type == TokenType.SimpleString || token.Type == TokenType.Number || token.Type == TokenType.Boolean || token.Type == TokenType.Null) { Token next = ReadToken(); if (next.Type == TokenType.Assign || next.Type == TokenType.Colon) { if (token.Type == TokenType.Null) { ret._Variables.Add(new CodeTable.TableVariable(m_script.Null.KeyValue, GetObject())); } else { ret._Variables.Add(new CodeTable.TableVariable(token.Lexeme, GetObject())); } Token peek = PeekToken(); if (peek.Type == TokenType.Comma || peek.Type == TokenType.SemiColon) { ReadToken(); } } else { throw new ParserException("Table变量赋值符号为[=]或者[:]", token); } } else if (token.Type == TokenType.Function) { UndoToken(); ret._Functions.Add(ParseFunctionDeclaration(true)); } else { throw new ParserException("Table开始关键字必须为[变量名称]或者[function]关键字", token); } } ReadRightBrace(); ret.Init(); return ret; }