public override LData VisitForNode(ForNode n) { LData list = Visit(n.inList); var val = list.GetValue(); LData it = LDataMaker.GetDataFor(n.inList.Type.ArrayType); Vars = Vars.GoDown(); Vars.PutInScope(n.var, it); for (int i = 0; i < val.length; i++) { it.SetValue(val._arr[i].GetValue()); Visit(n.body); } Vars = Vars.GoUp(); return(null); }
public override LData VisitVarListExprNode(VarListExprNode n) { LData upper = Visit(n.upper); LData lower = Visit(n.lower); LData stepsize = Visit(n.stepsize); LData current = LDataMaker.GetDataFor(n.Type.ArrayType); current.SetValue(lower.GetValue()); List <LData> arr = new List <LData>(); while (current.GetValue() < upper.GetValue()) { arr.Add(current); LData prev = current; current = LDataMaker.GetDataFor(n.Type.ArrayType); current.SetValue(prev.GetValue() + stepsize.GetValue()); } return(new LArray(arr)); }
public override LData VisitBinaryExprNode(BinaryExprNode n) { LData lhs = Visit(n.lhs); LData rhs = Visit(n.rhs); LData newdat = LDataMaker.GetDataFor(n.Type); switch (n.op) { case "*": { newdat.SetValue(lhs.GetValue() * rhs.GetValue()); } break; case "/": { newdat.SetValue(lhs.GetValue() / rhs.GetValue()); } break; case "+": { newdat.SetValue(lhs.GetValue() + rhs.GetValue()); } break; case "-": { newdat.SetValue(lhs.GetValue() - rhs.GetValue()); } break; case ">>": { newdat.SetValue(lhs.GetValue() >> rhs.GetValue()); } break; case "<<": { newdat.SetValue(lhs.GetValue() << rhs.GetValue()); } break; case "&": { newdat.SetValue(lhs.GetValue() & rhs.GetValue()); } break; case "|": { newdat.SetValue(lhs.GetValue() | rhs.GetValue()); } break; case "^": { newdat.SetValue(lhs.GetValue() ^ rhs.GetValue()); } break; case "%": { newdat.SetValue(lhs.GetValue() % rhs.GetValue()); } break; case "<": { newdat.SetValue(lhs.GetValue() < rhs.GetValue()); } break; case ">": { newdat.SetValue(lhs.GetValue() > rhs.GetValue()); } break; case "<=": { newdat.SetValue(lhs.GetValue() <= rhs.GetValue()); } break; case ">=": { newdat.SetValue(lhs.GetValue() >= rhs.GetValue()); } break; case "==": { newdat.SetValue(lhs.GetValue() == rhs.GetValue()); } break; case "!=": { newdat.SetValue(lhs.GetValue() != rhs.GetValue()); } break; case "&&": { newdat.SetValue(lhs.GetValue() && rhs.GetValue()); } break; case "||": { newdat.SetValue(lhs.GetValue() || rhs.GetValue()); } break; default: throw new Exception($"Did not match the binop: {n.op} at {n.sourceLoc}"); } return(newdat); }