示例#1
0
        ExpressionList ParseArgs()
        {
            ExpressionList exp_list = null;

            if (LookAhead().m_type == (int)'(')
            {
                NextToken();
                if (LookAhead().m_type != (int)')')
                {
                    exp_list = ParseExpList(true);
                }

                if (NextToken().m_type != (int)')')
                {
                    throw NewParserException("expect ')' to end function-args", _current);
                }
            }
            else if (LookAhead().m_type == (int)'{')
            {
                exp_list = new ExpressionList(LookAhead().m_line);
                exp_list.exp_list.Add(ParseTableConstructor());
            }
            else
            {
                throw NewParserException("expect '(' or '{' to start function-args", _look_ahead);
            }
            return(exp_list);
        }
示例#2
0
        void HandleExpList(ExpressionList tree, int expect_value_count)
        {
            int start_register = GetNextRegisterId();

            for (int i = 0; i < tree.exp_list.Count; ++i)
            {
                HandleExpRead(tree.exp_list[i]);
                GenerateRegisterId();
            }
            // ajust value count
            if (expect_value_count != -1)
            {
                int fix_value_count = tree.exp_list.Count;
                if (fix_value_count < expect_value_count)
                {
                    // need fill nil when need
                    if (tree.return_any_value)
                    {
                        var f    = GetCurrentFunction();
                        var code = Instruction.A(OpType.OpType_FillNilFromTopToA, start_register + expect_value_count);
                        f.AddInstruction(code, tree.line);
                    }
                    else
                    {
                        FillNil(start_register + fix_value_count, start_register + expect_value_count, tree.line);
                    }
                }
            }
            ResetRegisterId(start_register);
        }
示例#3
0
        ExpressionList ParseExpList(bool is_args = false)
        {
            var exp = new ExpressionList(LookAhead().m_line);

            exp.exp_list.Add(ParseExp());
            while (LookAhead().m_type == (int)',')
            {
                NextToken();
                if (is_args && LookAhead().m_type == (int)')')
                {
                    break;// func call args can have a extra ","
                }
                exp.exp_list.Add(ParseExp());
            }
            exp.return_any_value = IsExpReturnAnyCountValue(exp.exp_list[exp.exp_list.Count - 1]);
            return(exp);
        }