Exemplo n.º 1
0
        void HandleAssignStatement(AssignStatement tree)
        {
            HandleExpList(tree.exp_list, tree.var_list.Count);
            // var list
            int register = GetNextRegisterId();

            ResetRegisterId(register + tree.var_list.Count);
            for (int i = 0; i < tree.var_list.Count; ++i)
            {
                HandleVarWrite(tree.var_list[i], register + i);
            }
            ResetRegisterId(register);
        }
Exemplo n.º 2
0
        SyntaxTree ParseOtherStatement()
        {
            // lua做了限制,其他语句只有两种,assign statement and func call
            // SS还增加几个语法支持,+=,-=,++,--
            SyntaxTree exp;

            if (LookAhead().m_type == (int)TokenType.NAME)
            {
                exp = ParsePrefixExp();
                if (IsVar(exp))
                {
                    if (LookAhead().m_type == (int)TokenType.ADD_ONE)
                    {
                        // ++
                        NextToken();
                        var special_statement = new SpecialAssginStatement(_current.m_line);
                        special_statement.var       = exp;
                        special_statement.is_add_op = true;
                        return(special_statement);
                    }
                    else if (LookAhead().m_type == (int)TokenType.ADD_SELF)
                    {
                        // +=
                        NextToken();
                        var special_statement = new SpecialAssginStatement(_current.m_line);
                        special_statement.var       = exp;
                        special_statement.exp       = ParseExp();
                        special_statement.is_add_op = true;
                        return(special_statement);
                    }
                    else if (LookAhead().m_type == (int)TokenType.DEC_ONE)
                    {
                        // --
                        NextToken();
                        var special_statement = new SpecialAssginStatement(_current.m_line);
                        special_statement.var       = exp;
                        special_statement.is_add_op = false;
                        return(special_statement);
                    }
                    else if (LookAhead().m_type == (int)TokenType.DEC_SELF)
                    {
                        // -=
                        NextToken();
                        var special_statement = new SpecialAssginStatement(_current.m_line);
                        special_statement.var       = exp;
                        special_statement.exp       = ParseExp();
                        special_statement.is_add_op = false;
                        return(special_statement);
                    }

                    // assign statement
                    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 = ParsePrefixExp();
                        if (!IsVar(exp))
                        {
                            throw NewParserException("expect var here", _current);
                        }
                        assign_statement.var_list.Add(exp);
                    }
                    NextToken();// skip '='
                    assign_statement.exp_list = ParseExpList();

                    return(assign_statement);
                }
                else
                {
                    Debug.Assert(exp is FuncCall);
                    return(exp);
                }
            }
            else
            {
                if (IsMainExp())
                {
                    throw NewParserException("unsupport statement", _look_ahead);
                }
                return(null);
            }
        }