/// <summary> /// Gets a VariableAST /// </summary> /// <returns>VariableAST</returns> private AST Variable() { VariableAST ast = new VariableAST(this.currentToken); this.ConsumeToken(TokenType.IDTOKEN); return(ast); }
public ForAST(Token token, StatementListAST ast, VariableAST variable, AST expression1, AST expression2) : base(token) { this.children = ast; this.variable = variable; this.expression1 = expression1; this.expression2 = expression2; }
/// <summary> /// Gets a ReadAST /// </summary> /// <returns>ReadAST</returns> private AST Read() { Token token = this.currentToken; this.ConsumeToken(TokenType.READ); VariableAST variable = this.Variable() as VariableAST; return(new ReadAST(token, variable)); }
/// <summary> /// Gets an assignment AST /// </summary> /// <returns>AssignmentAST</returns> private AST Assignment() { VariableAST left = this.Variable() as VariableAST; Token token = this.currentToken; this.ConsumeToken(token.type); AST right = this.Expression(); AssignAST ast = new AssignAST(left, this.currentToken, right); return(ast); }
/// <summary> /// Gets a VariableDeclarationAST /// </summary> /// <returns>VariableDeclarationAST</returns> private AST VariableDeclaration() { this.ConsumeToken(TokenType.VAR); VariableAST variable = new VariableAST(this.currentToken); this.ConsumeToken(TokenType.IDTOKEN); this.ConsumeToken(TokenType.TWODOT); TypeAST type = (TypeAST)this.TypeSpec(); if (this.currentToken.type == TokenType.SEMICOLON) { return(new VariableDeclarationAST(variable, type, this.currentToken)); } else { this.ConsumeToken(TokenType.ASSIGN); return(new VariableDeclarationAST(variable, type, this.currentToken, this.Expression())); } }
/// <summary> /// Gets a ForAST /// </summary> /// <returns>ForAST</returns> private AST For() { Token token = this.currentToken; this.ConsumeToken(TokenType.FOR); VariableAST variable = this.Variable() as VariableAST; this.ConsumeToken(TokenType.IN); AST expressionAST = this.Expression(); this.ConsumeToken(TokenType.TWO_CONCECUTIVE_DOTS); AST expressionAST2 = this.Expression(); this.ConsumeToken(TokenType.DO); StatementListAST ast = new StatementListAST(); this.StatementList().ForEach(x => ast.children.Add(x)); this.ConsumeToken(TokenType.END); this.ConsumeToken(TokenType.FOR); return(new ForAST(token, ast, variable, expressionAST, expressionAST2)); }
public AssignAST(VariableAST left, Token operation, AST right) : base(operation) { this.left = left; this.right = right; }
/// <summary> /// Traverses variable AST /// </summary> /// <param name="ast">VariableAST</param> /// <returns>Symbol value</returns> private object VisitVariableAST(VariableAST ast) { string variableName = (string)ast.value; return(this.symbolTable.LookupSymbol(variableName).value); }
public ReadAST(Token token, VariableAST variable) : base(token) { this.variable = variable; }
public VariableDeclarationAST(VariableAST varNode, TypeAST typeNode, Token token, AST assignValue = null) : base(token) { this.assignedValue = assignValue; this.varNode = varNode; this.typeNode = typeNode; }