public ForeachActionNode(VarDeclaringNode decl, IdentifierNode ident, ExpressionNode expr, ActionSequenceNode actions, SourceCodePosition pos) : base(pos) { itsDeclaring = decl; Identifier = ident; Expression = expr; Actions = actions; }
// uses the current scope level to determine whether the variable should be added to the current class ST or the current method ST public object Visit(VarDeclaringNode n, object o) { if (_currentScopeLevel == 1) { _currentClassST.EnterSymbol(n.Identifier.Value, n); } else if (_currentScopeLevel == 2) { _currentMethodST.EnterSymbol(n.Identifier.Value, n); } return(null); }
// we create variable declarings as public fields with generic getters and setters to adhere to the semantics of Deslang public object Visit(VarDeclaringNode n, object o) { if (_currentScopeLevel == 1) { Append($"{AddIndent()}public "); n.Type.Accept(this, null); Append($" {n.Identifier.Value} {{ get; set; }}"); AppendLine(); } else { Append($"{AddIndent()}"); n.Type.Accept(this, null); Append($" {n.Identifier.Value};"); AppendLine(); } return(null); }
private VarDeclaringNode ParseVariableDeclaring() { VarDeclaringNode itsAST; SourceCodePosition itsPos = _currentToken.SourcePosition; Accept(Token.TokenType.Var); TypeNode itsType = Type(); IdentifierNode itsName = new IdentifierNode(_currentToken, itsType); Accept(Token.TokenType.Identifier); itsAST = new VarDeclaringNode(itsName, itsType, itsPos); if (_currentToken.Type == Token.TokenType.AssignmentOperator) { itsAST = new AssignedVarDeclaringNode(itsName, itsType, Assigning(), itsPos); } Accept(Token.TokenType.Semicolon); return(itsAST); }
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); }