コード例 #1
0
ファイル: SyntaxTree.cs プロジェクト: treert/SimpleScript
 public BinaryExpression(ExpSyntaxTree left_, Token op_, ExpSyntaxTree right_)
 {
     left  = left_;
     op    = op_;
     right = right_;
     _line = op_.m_line;
 }
コード例 #2
0
ファイル: Parser.cs プロジェクト: treert/SimpleScript
        TableAccess ParseTableAccessor(ExpSyntaxTree table)
        {
            NextToken();// skip '[' or '.'

            var index_access = new TableAccess(_current.m_line);

            index_access.table = table;
            if (_current.m_type == (int)'[')
            {
                index_access.index = ParseExp();
                if (NextToken().m_type != (int)']')
                {
                    throw NewParserException("expect ']'", _current);
                }
            }
            else
            {
                if (!NextToken().IsLiteralString())
                {
                    throw NewParserException("expect <id> after '.'", _current);
                }
                index_access.index = new Terminator(_current.ConvertToStringToken());
            }
            return(index_access);
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: treert/SimpleScript
        FuncCall ParseFunctionCall(ExpSyntaxTree caller)
        {
            Debug.Assert(LookAhead().Match('('));// 基本的函数调用只支持语法 f(arg,...),后面可以安排写语法糖什么的。
            var func_call = new FuncCall(LookAhead().m_line);

            func_call.caller = caller;
            func_call.args   = ParseArgs();
            return(func_call);
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: treert/SimpleScript
 ExpSyntaxTree ParseTailExp(ExpSyntaxTree exp)
 {
     // table index or func call
     for (; ;)
     {
         if (LookAhead().Match('[') || LookAhead().Match('.'))
         {
             exp = ParseTableAccessor(exp);
         }
         else if (LookAhead().Match('('))
         {
             exp = ParseFunctionCall(exp);
         }
         else
         {
             break;
         }
     }
     return(exp);
 }
コード例 #5
0
ファイル: Parser.cs プロジェクト: treert/SimpleScript
        SyntaxTree ParseOtherStatement()
        {
            // 没什么限制,基本可以随意写些MainExp
            // 重点处理的是一些赋值类语句,赋值类语句的左值必须是var类型的
            // SS还增加几个语法支持,+=,-=,++,--
            if (IsMainExpNext() == false)
            {
                return(null);
            }

            ExpSyntaxTree exp = ParseMainExp();

            if (LookAhead().Match('=') || LookAhead().Match(','))
            {
                // assign statement
                if (!IsVar(exp))
                {
                    throw NewParserException("expect var for assign statement", _current);
                }
                var assign_statement = new AssignStatement(LookAhead().m_line);
                assign_statement.var_list.Add(exp);
                while (LookAhead().m_type != (int)'=')
                {
                    if (NextToken().m_type != (int)',')
                    {
                        throw NewParserException("expect ',' to split var-list", _current);
                    }
                    if (LookAhead().m_type != (int)TokenType.NAME)
                    {
                        throw NewParserException("expect 'id' to start var", _look_ahead);
                    }
                    exp = ParseMainExp();
                    if (!IsVar(exp))
                    {
                        throw NewParserException("expect var for assign statement", _current);
                    }
                    assign_statement.var_list.Add(exp);
                }
                NextToken();// skip '='
                assign_statement.exp_list = ParseExpList();

                return(assign_statement);
            }
            var type = (TokenType)LookAhead().m_type;

            if (SpecialAssginStatement.NeedWork(type))
            {
                if (!IsVar(exp))
                {
                    throw NewParserException("expect var here", _current);
                }
                var special_statement = new SpecialAssginStatement(_current.m_line);
                special_statement.var = exp;
                special_statement.op  = type;
                if (SpecialAssginStatement.IsSelfMode(type))
                {
                    special_statement.exp = ParseExp();
                }
                return(special_statement);
            }

            return(exp);// 不限制了
        }