Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        public static DoLoopStaNode Parse(TokenString tStr, ref int index)
        {
            int startIndex = index;

            if (!tStr.Match(index, TokenType.doStatement, TokenType.cBraceOpen))
            {
                return(null);
            }

            index++;


            StatementNode body = Sta.Parse(tStr, ref index);

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

            index++;
            ExpressionNode condition = Exp.Parse(tStr.GetRangeInBrackets(ref index));

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

            index++;
            DoLoopStaNode node = new DoLoopStaNode(condition, body);

            return(node);
        }