Ejemplo n.º 1
0
        //返回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 if (next.Type == TokenType.Comma || next.Type == TokenType.SemiColon)
                    {
                        if (token.Type == TokenType.Null)
                        {
                            ret._Variables.Add(new CodeTable.TableVariable(m_script.Null.KeyValue, new CodeScriptObject(m_script, null)));
                        }
                        else
                        {
                            ret._Variables.Add(new CodeTable.TableVariable(token.Lexeme, new CodeScriptObject(m_script, null)));
                        }
                    }
                    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);
        }
Ejemplo n.º 2
0
        private CodeTable GetTable()
        {
            CodeTable table = new CodeTable();

            this.ReadLeftBrace();
            while (this.PeekToken().Type != Scorpio.Compiler.TokenType.RightBrace)
            {
                Token token = this.ReadToken();
                if ((token.Type != Scorpio.Compiler.TokenType.Comma) && (token.Type != Scorpio.Compiler.TokenType.SemiColon))
                {
                    if ((((token.Type == Scorpio.Compiler.TokenType.Identifier) || (token.Type == Scorpio.Compiler.TokenType.String)) || ((token.Type == Scorpio.Compiler.TokenType.SimpleString) || (token.Type == Scorpio.Compiler.TokenType.Number))) || ((token.Type == Scorpio.Compiler.TokenType.Boolean) || (token.Type == Scorpio.Compiler.TokenType.Null)))
                    {
                        Token token2 = this.ReadToken();
                        if ((token2.Type == Scorpio.Compiler.TokenType.Assign) || (token2.Type == Scorpio.Compiler.TokenType.Colon))
                        {
                            if (token.Type == Scorpio.Compiler.TokenType.Null)
                            {
                                table._Variables.Add(new CodeTable.TableVariable(this.m_script.Null.KeyValue, this.GetObject()));
                            }
                            else
                            {
                                table._Variables.Add(new CodeTable.TableVariable(token.Lexeme, this.GetObject()));
                            }
                        }
                        else
                        {
                            if ((token2.Type != Scorpio.Compiler.TokenType.Comma) && (token2.Type != Scorpio.Compiler.TokenType.SemiColon))
                            {
                                throw new ParserException("Table变量赋值符号为[=]或者[:]", token);
                            }
                            if (token.Type == Scorpio.Compiler.TokenType.Null)
                            {
                                table._Variables.Add(new CodeTable.TableVariable(this.m_script.Null.KeyValue, new CodeScriptObject(this.m_script, null)));
                            }
                            else
                            {
                                table._Variables.Add(new CodeTable.TableVariable(token.Lexeme, new CodeScriptObject(this.m_script, null)));
                            }
                        }
                    }
                    else
                    {
                        if (token.Type != Scorpio.Compiler.TokenType.Function)
                        {
                            throw new ParserException("Table开始关键字必须为[变量名称]或者[function]关键字", token);
                        }
                        this.UndoToken();
                        table._Functions.Add(this.ParseFunctionDeclaration(true));
                    }
                }
            }
            this.ReadRightBrace();
            table.Init();
            return(table);
        }