public void Visit(Dot t, IEnvironment env, object value) { string member = t.Name; if (value is ClassInfo) { if (member == "new") { ClassInfo ci = value as ClassInfo; NestedEnv e = new NestedEnv(ci.Environment); RavObject ro = new RavObject(e); e.PutNew("this", ro); InitObject(ci, e); result = ro; return; } } else if (value is RavObject) { try { result = (value as RavObject).Read(member); return; } catch (RavObject.AccessException) { } } result = new ErrorValue("bad member access in Dot: " + member, t); }
public override Value GetValue(Value baseValue, NestedEnv env) { Value[] args = new Value[ChildrenCount]; for (int i = 0; i < ChildrenCount; i++) { args[i] = this[i].GetValue(null, env); } return(baseValue.Invoke(args)); }
public virtual Value GetValue(Value baseValue, NestedEnv env) { Value result = NilValue.Nil; foreach (IASTNode node in Children) { result = node.GetValue(null, env); } return(result); }
public override Value SetValue(Value baseValue, NestedEnv env, Value value) { Value bv = null; for (int i = 0; i < ChildrenCount - 1; i++) { bv = this[i].GetValue(bv, env); } return(this[ChildrenCount - 1].SetValue(bv, env, value)); }
public override Value GetValue(Value baseValue, NestedEnv env) { Value result = NilValue.Nil; while (Cond.GetValue(null, env).AsBool()) { result = Body.GetValue(null, env); } return(result); }
public override Value GetValue(Value baseValue, NestedEnv env) { Value bv = null; for (int i = 0; i < ChildrenCount; i++) { bv = this[i].GetValue(bv, env); } return(bv); }
public override Value GetValue(Value baseValue, NestedEnv env) { IASTNode psn = Params; string[] ps = new string[psn.ChildrenCount]; for (int i = 0; i < ps.Length; i++) { ps[i] = psn[i].Token.Literal; } return(new FuncValue(env, ps, Body)); }
public override Value GetValue(Value baseVaue, NestedEnv env) { Value left = this[0].GetValue(null, env); for (int i = 1; i < ChildrenCount; i += 2) { Value right = this[i + 1].GetValue(null, env); left = left.ComputeWith(this[i].Token.Literal, right); } return(left); }
public override Value GetValue(Value baseValue, NestedEnv env) { Value prev = Body.GetValue(baseValue, env); double act = prev.AsNumber(); switch (Optr.Token.Literal) { case "++": act = prev.AsNumber() + 1; break; case "--": act = prev.AsNumber() - 1; break; } Body.SetValue(baseValue, env, new NumberValue(act)); return(prev); }
public static NestedEnv CreateBuindinEnv() { NestedEnv env = new NestedEnv(); env.SetToSelf("print", FuncPrint, true); env.SetToSelf("println", FuncPrintln, true); env.SetToSelf("typeof", FuncTypeof, true); env.SetToSelf("info", FuncInfo, true); env.SetToSelf("prinfo", FuncPrinfo, true); env.SetToSelf("true", BoolValue.True, true); env.SetToSelf("false", BoolValue.False, true); env.SetToSelf("nil", NilValue.Nil, true); return(env); }
public override Value GetValue(Value baseVaue, NestedEnv env) { Value bodyValue = Body.GetValue(null, env); switch (Prefix) { case "+": return(new NumberValue(bodyValue.AsNumber())); case "-": return(new NumberValue(-bodyValue.AsNumber())); case "!": return(new BoolValue(!bodyValue.AsBool())); default: return(NilValue.Nil); } }
public override Value GetValue(Value baseVaue, NestedEnv env) { string str = NameStr; switch (str) { case "nil": return(NilValue.Nil); case "true": return(BoolValue.True); case "false": return(BoolValue.False); default: return(env[NameStr]); } }
public static void TestParser() { string s = "(996 + 1.2 - 6 * (prev - 1) / prev - 3 * 5 * 13.6 / ext / k)"; StringReader reader = new StringReader(s); TokenStream ts = new TokenStream(reader); ts.AddTokenizers( new IdTokenizer(), new DecimalTokenizer(), new DigitTokenizer(), new StringTokenizer(), new NameTokenizer() ); Parser parser = CreateProgramParser(); NestedEnv env = Buildin.CreateBuindinEnv(); List <IASTNode> res = new List <IASTNode>(); Console.Write(">>> "); while ((s = Console.ReadLine()) != ".exit") { ts.Reset(new StringReader(s)); if (!parser.Parse(ts, res) || res.Count == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Parse failed"); Console.ResetColor(); } else { IASTNode node = res[0].Reduce(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Parse succeeded"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(node.ToString()); Console.ResetColor(); string result = node.GetValue(null, env).ToString(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("==> " + result); Console.ResetColor(); //PrintAST(node); } res.Clear(); Console.Write(">>> "); } }
public override Value GetValue(Value baseValue, NestedEnv env) { Value result = Cond().GetValue(null, env); if (result.AsBool()) { return(TruePart().GetValue(null, env)); } else if (ChildrenCount > 2) { return(this[2].GetValue(null, env)); } else { return(NilValue.Nil); } }
public override Value GetValue(Value baseValue, NestedEnv env) { return(baseValue[Key.GetValue(null, env)]); }
public override Value SetValue(Value baseValue, NestedEnv env, Value value) { baseValue[Key.GetValue(null, env)] = value; return(value); }
public override Value SetValue(Value baseValue, NestedEnv env, Value value) { baseValue[Key.Token.Value] = value; return(value); }
public override Value GetValue(Value baseValue, NestedEnv env) { return(Content.GetValue(null, env)); }
public override Value SetValue(Value baseVaue, NestedEnv env, Value value) { return(env[NameStr] = value); }
public override Value GetValue(Value baseValue, NestedEnv env) { return(baseValue[Key.Token.Value]); }
public virtual Value SetValue(Value baseValue, NestedEnv env, Value value) { return(NilValue.Nil); }
public override Value GetValue(Value baseVaue, NestedEnv env) { return(new StringValue(Token.Literal)); }
public override Value GetValue(Value baseValue, NestedEnv env) { return(Left.SetValue(baseValue, env, Right.GetValue(null, env))); }
public override Value GetValue(Value baseVaue, NestedEnv env) { return Token.Value; }
public virtual Value SetValue(Value baseVaue, NestedEnv env, Value value) => NilValue.Nil;
public virtual Value GetValue(Value baseVaue, NestedEnv env) => Token.Value;
public override Value SetValue(Value baseVaue, NestedEnv env, Value value) { return NilValue.Nil; }