示例#1
0
文件: Sta.cs 项目: pBactusp/Shpoon
        public static StatementNode Parse(TokenString tStr, ref int index)
        {
            switch (tStr[index].Type)
            {
            case TokenType.cBraceOpen:
                return(CompoundStaNode.Parse(tStr, ref index));

            case TokenType.ifStatement:
                return(ConditionalStaNode.Parse(tStr, ref index));

            case TokenType.doStatement:
                return(DoLoopStaNode.Parse(tStr, ref index));

            case TokenType.whileStatement:
                return(WhileLoopStaNode.Parse(tStr, ref index));

            case TokenType.forStatement:
                return(ForLoopStaNode.Parse(tStr, ref index));

            case TokenType.returnStatement:
                return(ReturnStaNode.Parse(tStr, ref index));

            case TokenType.lineEnd:
                return(NopStaNode.Parse(tStr, ref index));

            default:
                return(ExpressionStaNode.Parse(tStr, ref index));
            }
        }
示例#2
0
        public static WhileLoopStaNode Parse(TokenString tStr, ref int index)
        {
            int startIndex = index;

            if (!tStr.Match(index, TokenType.whileStatement, TokenType.rBraceOpen))
            {
                index = startIndex;
                return(null);
            }

            index++;
            ExpressionNode   condition = Exp.Parse(tStr.GetRangeInBrackets(ref index));
            StatementNode    body      = Sta.Parse(tStr, ref index);
            WhileLoopStaNode node      = new WhileLoopStaNode(condition, body);

            return(node);
        }