示例#1
0
            private Statement stmt()
            {
                Statement  retVal;
                Statement  do_if_true;
                Statement  do_if_false;
                Expression cmp;
                int        local;
                Token      id;
                int        line = l.currentLine;

                switch (lookAhead.TokenType)
                {
                case '{':
                    match('{');
                    retVal = stmts();
                    match('}');
                    break;

                case TokenType.TOKEN_IF:
                    accept(); match('(');
                    cmp = expr();
                    match(')');
                    do_if_true = stmt();
                    if (lookAhead.TokenType == TokenType.TOKEN_ELSE)
                    {
                        accept();
                        do_if_false = stmt();
                    }
                    else
                    {
                        do_if_false = new stat_nop();
                    }
                    retVal = new stat_if(m, line, cmp, do_if_true, do_if_false);
                    break;

                case TokenType.TOKEN_WHILE:
                    accept(); match('(');
                    cmp = expr();
                    match(')');
                    retVal = new stat_while(m, line, cmp, stmt());
                    break;

                case TokenType.TOKEN_ID:
                    id    = match(TokenType.TOKEN_ID);
                    local = m.GetLocalIDByName(id.strToken);
                    if (lookAhead.TokenType == '(')     // function call
                    {
                        accept(); List <Expression> argss = args(); match(')');
                        if (local != -1)
                        {
                            retVal = new stat_exp(m, line, new exp_functioncall(m, line, argss, local, true));
                        }
                        else
                        {
                            retVal = new stat_exp(m, line, new exp_functioncall(m, line, argss, m.parser_checkStringMap(id.strToken, true), false));
                        }
                    }
                    else
                    {
                        match('=');
                        if (local != -1)
                        {
                            retVal = new stat_assignment_local(m, line, local, expr());
                        }
                        else
                        {
                            retVal = new stat_assignment(m, line, m.parser_checkStringMap(id.strToken, true), expr());
                        }
                    }
                    match(';');
                    break;

                case TokenType.TOKEN_RETURN:
                    accept();
                    retVal = new stat_return(m, line, expr());
                    match(';');
                    break;

                case TokenType.TOKEN_OUT:
                    accept();
                    match('(');
                    retVal = new stat_out(m, line, expr(), match(',').TokenType != 0?expr():null);
                    match(')');
                    match(';');
                    break;

                case TokenType.TOKEN_LOCAL:
                    accept();
                    paramList(true);
                    match(';');
                    retVal = new stat_nop();
                    break;

                case TokenType.TOKEN_BREAK:
                    accept();
                    retVal = new stat_break(m, line);
                    match(';');
                    break;

                case TokenType.TOKEN_CONTINUE:
                    accept();
                    retVal = new stat_continue(m, line);
                    match(';');
                    break;

                default:
                    retVal = new stat_exp(m, line, expr());
                    match(';');
                    break;
                }
                return(retVal);
            }
示例#2
0
            private Statement stmt()
            {
                Statement  retVal;
                Statement  do_if_true;
                Statement  do_if_false;
                Expression cmp;
                Statement  forExpr1; Expression forExpr2; Statement forExpr3;
                int        line = l.currentLine;

                switch (lookAhead.TokenType)
                {
                case '{':
                    match('{');
                    retVal = stmts();
                    match('}');
                    break;

                case TokenType.TOKEN_IF:
                    accept(); match('(');
                    cmp = expr();
                    match(')');
                    do_if_true = stmt();
                    if (lookAhead.TokenType == TokenType.TOKEN_ELSE)
                    {
                        accept();
                        do_if_false = stmt();
                    }
                    else
                    {
                        do_if_false = new stat_nop(m, line);
                    }
                    retVal = new stat_if(m, line, cmp, do_if_true, do_if_false);
                    break;

                case TokenType.TOKEN_WHILE:
                    accept(); match('(');
                    cmp = expr();
                    match(')');
                    retVal = new stat_while(m, line, cmp, stmt());
                    break;

                case TokenType.TOKEN_RETURN:
                    accept();
                    retVal = new stat_return(m, line, expr());
                    match(';');
                    break;

                case TokenType.TOKEN_LOCAL:
                    accept();
                    retVal = localList();
                    match(';');
                    break;

                case TokenType.TOKEN_BREAK:
                    accept();
                    retVal = new stat_break(m, line);
                    match(';');
                    break;

                case TokenType.TOKEN_CONTINUE:
                    accept();
                    retVal = new stat_continue(m, line);
                    match(';');
                    break;

                case TokenType.TOKEN_FOR:
                    accept(); match('(');
                    if (lookAhead.TokenType == ';')
                    {
                        forExpr1 = new stat_nop(m, l.currentLine);
                    }
                    else
                    {
                        forExpr1 = new stat_exp(m, l.currentLine, expr());
                    }
                    match(';');

                    if (lookAhead.TokenType == ';')
                    {
                        forExpr2 = new exp_number(m, l.currentLine, 1.0);
                    }
                    else
                    {
                        forExpr2 = expr();
                    }
                    match(';');

                    if (lookAhead.TokenType == ')')
                    {
                        forExpr3 = new stat_nop(m, l.currentLine);
                    }
                    else
                    {
                        forExpr3 = new stat_exp(m, l.currentLine, expr());
                    }
                    match(')');

                    retVal = new stat_for(m, line, forExpr1, forExpr2, forExpr3, stmt());
                    break;

                default:
                    retVal = new stat_exp(m, line, expr());
                    match(';');
                    break;
                }
                return(retVal);
            }