public object Visit(ForeachActionNode n, object o) { Append($"{AddIndent()}foreach (var {n.Identifier.Value} in "); // use C# var keyword to account for any Deslang type n.Expression.Accept(this, null); AppendLine(")"); AppendLine($"{AddIndent()}{{"); IncreaseIndent(); n.Actions.Accept(this, null); DecreaseIndent(); AppendLine($"{AddIndent()}}}"); return(null); }
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); }
public object Visit(ForeachActionNode n, object o) { n.itsDeclaring.Accept(this, null); // visit the declaration associated with the foreach loop return(null); }