public SESet(SExprAtomic ha, SExprComp c, bool imm) : base(ha, c) { if (c.Atomics.Count < 1) { throw new VMException("it takes at least 1 argument", ha); } var n = c.Atomics.Pop(); if (n is SExprAtomic && (n as SExprAtomic).Token.TType == SToken.TokenType.ATOMIC) { varName = (string)(n as SExprAtomic).Token.TValue; } else { nameExpr = SExpression.Cast(n); } if (c.Atomics.Count > 0) { varValue = SExpression.Cast(c.Atomics.Pop()); } else { varValue = new SNull(); } makeImmutable = imm; }
public SECond(SExprAtomic ha, SExprComp c) { if (c.Atomics.Count < 2) { throw new VMException("at least 1 branch must be defined", ha); } condition = SExpression.Cast(c.Atomics.Pop()); branches = new List <Tuple <SExpression, SExpression> >(); foreach (var a in c.Atomics) { var b = a as SExprComp; if (b == null || b.Atomics.Count < 2) { throw new VMException("each branch must be a compound", ha); } var cond = b.Atomics.Pop(); if (cond is SExprAtomic && ((SExprAtomic)cond).Token.TType == SToken.TokenType.ATOMIC && (string)((SExprAtomic)cond).Token.TValue == "_") { defaultBranch = SExpression.Cast(b.Atomics.Pop()); } else { branches.Add(new Tuple <SExpression, SExpression>( SExpression.Cast(cond), SExpression.Cast(b.Atomics.Pop()) )); } } }
public override SExpr Clone() { SExprComp ret = new SExprComp(); ret.Atomics = Atomics.Select(a => a.Clone()).ToList(); return(ret); }
public SERegexMatch(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count > 1) { regex = SExpression.Cast(c.Atomics.Pop()); text = SExpression.Cast(c.Atomics.Pop()); if (c.Atomics.Count > 0) { start = SExpression.Cast(c.Atomics.Pop()); } else { start = new SNumber(0); } if (c.Atomics.Count > 0) { length = SExpression.Cast(c.Atomics.Pop()); } else { length = new SNumber(-1); } } else { throw new VMException("it takes at least 2 arguments", ha); } }
public static SExpression Cast(SExprComp c) { if (c.Atomics.Count == 0) { return(new SEList(c)); } var _head = c.Atomics.Pop(); if (_head is SExprComp) { if (c.Atomics.Count == 0) { return(SExpression.Cast(_head)); } else { var first = _head; while (first is SExprComp) { first = (first as SExprComp).Atomics[0]; } return(new SECall(SExpression.Cast(_head), (from a in c.Atomics select SExpression.Cast(a)).ToList(), first as SExprAtomic, c)); } } var head = _head as SExprAtomic; if (head.Token.TType == SToken.TokenType.ATOMIC) { string tvalue = (string)head.Token.TValue; if (SExpression.KeywordsLookup.ContainsKey(tvalue)) { return(SExpression.KeywordsLookup[tvalue](head, c)); } else { if (c.Atomics.Count == 0) { return(new SEVariable(tvalue, head, c)); } else { return(new SECall(tvalue, (from a in c.Atomics select SExpression.Cast(a)).ToList(), head, c)); } } } else if (head.Token.TType == SToken.TokenType.STRING || head.Token.TType == SToken.TokenType.NUMBER) { c.Atomics.Insert(0, head); return(new SEList(c)); } else { throw new VMException("invalid cast", head); } }
public SEInteropGetType(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 1) { throw new VMException("it takes 1 argument", ha); } typeName = SExpression.Cast(c.Atomics.Pop()); }
public SESub(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 2 && c.Atomics.Count != 3) { throw new VMException("it takes 2 or 3 arguments", ha); } arguments = (from a in c.Atomics select SExpression.Cast(a)).ToList(); }
public SEKeys(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 1) { throw new VMException("it takes 1 argument"); } dict = SExpression.Cast(c.Atomics.Pop()); }
public SEUnsafe(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 1) { throw new VMException("it takes 1 argument", ha); } obj = SExpression.Cast(c.Atomics.Pop()); }
public SEGet(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count < 2) { throw new VMException("it takes at least 2 arguments", ha); } dict = SExpression.Cast(c.Atomics.Pop()); keys = c.Atomics.Select(a => SExpression.Cast(a)).ToList(); }
public SEInteropNew(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count < 1) { throw new VMException("it takes at least 1 argument", ha); } type = SExpression.Cast(c.Atomics.Pop()); arguments = c.Atomics.Select(a => SExpression.Cast(a)).ToList(); }
public SEMultiCore(SExprAtomic ha, SExprComp c, string f) : base(ha, c) { argumentExprs = (from a in c.Atomics select SExpression.Cast(a)).ToList(); func = f; if (argumentExprs.Count < 1) { throw new VMException("it takes at least 1 argument", ha); } }
public SENum(SExprAtomic ha, SExprComp c, bool asc) : base(ha, c) { if (c.Atomics.Count != 1) { throw new VMException("it takes 1 argument"); } argument = SExpression.Cast(c.Atomics.Pop()); convertAsc = asc; }
public SEPrint(SExprAtomic ha, SExprComp c, string d) : base(ha, c) { delim = d; if (c.Atomics.Count == 0) { throw new VMException("it takes at least 1 argument", ha); } arguments = (from a in c.Atomics select SExpression.Cast(a)).ToList(); }
public SEDel(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 2) { throw new VMException("it takes 2 arguments", ha); } host = SExpression.Cast(c.Atomics.Pop()); index = SExpression.Cast(c.Atomics.Pop()); }
public SEFor(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count < 2) { throw new VMException("it takes 2 arguments", ha); } list = SExpression.Cast(c.Atomics.Pop()); body = SExpression.Cast(c.Atomics.Pop()); }
public SEInteropGetSetMember(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count < 2) { throw new VMException("it takes at least 2 arguments", ha); } obj = SExpression.Cast(c.Atomics.Pop()); propName = SExpression.Cast(c.Atomics.Pop()); }
public SESplit(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 2) { throw new VMException("it takes 2 arguments", ha); } text = SExpression.Cast(c.Atomics.Pop()); delim = SExpression.Cast(c.Atomics.Pop()); }
public SEStr(SExprAtomic ha, SExprComp c, bool chr) : base(ha, c) { if (c.Atomics.Count != 1) { throw new VMException("it takes 1 argument"); } argument = SExpression.Cast(c.Atomics.Pop()); convertChr = chr; }
public SEDict(SExprAtomic ha, SExprComp c) : base(ha, c) { values = c.Atomics.Select(a => { if (!(a is SExprComp) || (a as SExprComp).Atomics.Count != 2) { throw new VMException("each element of the dict must be a list with 2 elements", ha); } return(SExpression.Cast(a)); }).ToList(); }
public SEInteropInvokeStaticMethod(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count < 2) { throw new VMException("it takes at least 2 arguments", ha); } type = SExpression.Cast(c.Atomics.Pop()); methodName = SExpression.Cast(c.Atomics.Pop()); arguments = c.Atomics.Select(a => SExpression.Cast(a)).ToList(); }
public SEEval(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count != 1 && c.Atomics.Count != 2) { throw new VMException("it takes 1 or 2 arguments"); } text = SExpression.Cast(c.Atomics.Pop()); if (c.Atomics.Count > 0) { env = SExpression.Cast(c.Atomics.Pop()); } }
public SELambda(SExprAtomic ha, SExprComp c) { if (c.Atomics.Count < 2) { throw new VMException("missing lambda body", ha); } if (!(c.Atomics[0] is SExprComp)) { throw new VMException("the first argument must be the declaration", ha); } arguments = SELambda.CompoundToArguments(c.Atomics.Pop() as SExprComp, ha); body = SExpression.Cast(c.Atomics.Pop()); }
public SEIf(SExprAtomic ha, SExprComp c) { if (c.Atomics.Count == 0) { throw new VMException("missing true branch", ha); } if (c.Atomics.Count == 1) { throw new VMException("missing false branch", ha); } condition = SExpression.Cast(c.Atomics.Pop()); trueBranch = SExpression.Cast(c.Atomics.Pop()); falseBranch = SExpression.Cast(c.Atomics.Pop()); }
public static SExprComp MakeLambda(string func, params object[] atoms) { var comp = new SExprComp(); comp.Atomics.AddRange(atoms.Select(a => { if (a is string) { return((SExpr) new SExprAtomic(new SToken(SToken.TokenType.ATOMIC, a))); } else { return((SExpr) new SExprAtomic(new SToken(SToken.TokenType.SEXPRESSION, a))); } })); return(comp); }
private static SExprComp wrap(SExprAtomic ha, SExprComp c, bool inc) { if (c.Atomics.Count != 1) { throw new VMException("it takes 1 argument", ha); } SExprComp ret = new SExprComp(); SExprComp op = new SExprComp(); ret.Atomics = c.Atomics.Take(1).ToList(); op.Atomics.Add(new SExprAtomic(new SToken(SToken.TokenType.ATOMIC, inc ? "+" : "-"))); op.Atomics.Add(ret.Clone()); op.Atomics.Add(new SExprAtomic(new SToken(SToken.TokenType.NUMBER, new Decimal(1)))); ret.Atomics.Add(op); return(ret); }
private static SExprComp wrap(SExprAtomic ha, SExprComp c, string o) { if (c.Atomics.Count != 2) { throw new VMException("it takes 2 arguments", ha); } SExprComp ret = new SExprComp(); SExprComp op = new SExprComp(); ret.Atomics = c.Atomics.Take(1).ToList(); op.Atomics.Add(new SExprAtomic(new SToken(SToken.TokenType.ATOMIC, o))); op.Atomics.Add(ret.Clone()); op.Atomics.Add(c.Atomics.Skip(1).Take(1).First().Clone()); ret.Atomics.Add(op); return(ret); }
public SEType(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count == 0) { throw new VMException("it takes 1 argument", ha); } var n = c.Atomics.Pop(); if (n is SExprAtomic && (n as SExprAtomic).Token.TType == SToken.TokenType.ATOMIC) { vname = (string)(n as SExprAtomic).Token.TValue; } else { nameExpr = SExpression.Cast(n); } }
public SERegex(SExprAtomic ha, SExprComp c) : base(ha, c) { if (c.Atomics.Count > 0) { re = SExpression.Cast(c.Atomics.Pop()); if (c.Atomics.Count > 0) { option = SExpression.Cast(c.Atomics.Pop()); } else { option = new SString("None"); } } else { throw new VMException("it takes 1 or 2 arguments", ha); } }
public SERange(SExprAtomic ha, SExprComp c) : base(ha, c) { var args = (from v in c.Atomics select SExpression.Cast(v)).ToList(); if (args.Count == 2) { start = args[0]; end = args[1]; interval = new SNumber(1); } else if (args.Count == 3) { start = args[0]; interval = args[1]; end = args[2]; } else { throw new VMException("it takes 2 or 3 arguments", ha); } }