public void VisitVariable(IndentWriter context, AstStatement.VariableStmt variableStmt) { context.WriteLine($"[{variableStmt.Variable.Type.Name}] {variableStmt.Variable.Name} = {{"); context.Indent(); this.PrintExpression(context, variableStmt.Expression, variableStmt.Scope); context.Unindent(); context.WriteLine("}"); }
public AstStatement VisitVariable(Scope context, AstStatement.VariableStmt variableStmt) { var expr = variableStmt.Expression.Accept(context, this); variableStmt.Expression = expr; variableStmt.Variable = new Variable() { NameToken = variableStmt.VariableName, Type = expr.Type, }; variableStmt.Scope.DeclareVariable(variableStmt.Variable); return(variableStmt); }
public List <Instruction> VisitVariable(object context, AstStatement.VariableStmt variableStmt) { var scope = variableStmt.Scope; var list = variableStmt.Expression.Accept(scope, this); if (variableStmt.Variable.Type != DataTypes.Int) { throw new InvalidOperationException("only integer type expected as variable for now"); } var id = scope.GetHeapLayoutUntil(variableStmt.Variable); list.Add(WriteLocal, id); return(list); }
public Tree VisitVariable(object c, AstStatement.VariableStmt variableStmt) => new Tree("var", Expr(variableStmt.Expression));