Beispiel #1
0
 public object Visit(WhileActionNode n, object o)
 {
     Append($"{AddIndent()}while (");
     n.Expression.Accept(this, null);
     AppendLine(")");
     AppendLine($"{AddIndent()}{{");
     IncreaseIndent();
     n.Actions.Accept(this, null);
     DecreaseIndent();
     AppendLine($"{AddIndent()}}}");
     return(null);
 }
Beispiel #2
0
        private ActionNode IterationStatement()
        {
            ActionNode         itsAST;
            SourceCodePosition itsPos = _currentToken.SourcePosition;

            if (_currentToken.Type == Token.TokenType.While)
            {
                Accept(Token.TokenType.While);
                Accept(Token.TokenType.LeftParen);
                ExpressionNode itsExpr = Expression();
                Accept(Token.TokenType.RightParen);
                Accept(Token.TokenType.LeftBrace);
                ActionSequenceNode itsActions = ActionStatements();
                Accept(Token.TokenType.RightBrace);
                itsAST = new WhileActionNode(itsExpr, itsActions, itsPos);
            }
            else
            {
                Accept(Token.TokenType.Foreach);
                Accept(Token.TokenType.LeftParen);
                VarDeclaringNode itsDecl;
                Accept(Token.TokenType.Var);
                TypeNode       itsType = Type();
                IdentifierNode itsName = new IdentifierNode(_currentToken, itsType);
                Accept(Token.TokenType.Identifier);
                itsDecl = new VarDeclaringNode(itsName, itsType, itsPos);
                Accept(Token.TokenType.In);
                ExpressionNode itsExpr = Expression();
                Accept(Token.TokenType.RightParen);
                Accept(Token.TokenType.LeftBrace);
                ActionSequenceNode itsActions = ActionStatements();
                Accept(Token.TokenType.RightBrace);
                itsAST = new ForeachActionNode(itsDecl, itsName, itsExpr, itsActions, itsPos);
            }
            return(itsAST);
        }
Beispiel #3
0
 public object Visit(WhileActionNode n, object o)
 {
     return(null);
 }