ATree pATerm() { char c; ATree al = pASimple(false); while ("+-0123456789#'$./?".IndexOf(scn.C) != -1) { if (al == null) { al = new ATree('.', 0, "", null); } if (scn.C == '+' || scn.C == '-') { c = scn.C; pChar(); } else { c = '+'; } ATree ar = pASimple(true); if (ar == null) { ar = new ATree('0', 1, "", null); } ATree x = new ATree(c, 0, "", null); x.l = al; x.r = ar; al = x; } return(al); }
// remove for non-windowed version */ void CheckNoAddr(ATree a) { if (a != null) { throw new ssException("command takes no address"); } }
private void BuildTreeUI(ATree tree) { AddRootNodeUI(tree.Root); AddSubTreeUI(tree.Root); this.nodeContainer.UpdateLayout(); ConnectSubTreeUI(tree.Root); }
public void TestAdd() { ATree <int> tree = new ATree <int>(); tree.Add(50); tree.Add(25); tree.Add(39); tree.Add(15); tree.Add(10); tree.Add(70); tree.Add(60); tree.Print(); //Assert.AreEqual(15, tree.Head.Left.Item); //Assert.AreEqual(25, tree.Head.Left.Right.Item); //Console.WriteLine(tree.Head.BalanceFactor); }
ssAddress xRelAddr(ssAddress rt, char dir, ATree ar) { switch (ar.op) { case '#': if (dir == '+') { rt.rng.To(rt.rng.r + ar.n); } else { rt.rng.To(rt.rng.l - ar.n); } if (!rt.txt.Contains(rt.rng)) { throw new ssException("address range"); } return(rt); case '/': return(Search(rt, ar.s, dir == '+')); case '?': return(Search(rt, ar.s, dir == '-')); case '0': if (dir == '+') { return(new ssAddress (rt.txt.FindLine(rt.rng.r, ar.n, 1), rt.txt)); } else { return(new ssAddress (rt.txt.FindLine(rt.rng.l, ar.n, -1), rt.txt)); } default: throw new ssException("address"); } }
public void TestRemove() { ATree <int> tree = new ATree <int>(); tree.Add(50); tree.Add(25); tree.Add(39); tree.Add(15); tree.Add(10); tree.Add(70); tree.Add(60); tree.Add(8); tree.Print(); tree.Remove(70); tree.Print(); tree.Remove(15); tree.Print(); }
ATree pARange() { ATree al = pATerm(); while (scn.C == ',' || scn.C == ';') { char c = scn.C; if (al == null) { al = new ATree('#', 0, "", null); } pChar(); ATree ar = pATerm(); if (ar == null) { ar = new ATree('$', 0, "", null); } ATree x = new ATree(c, 0, "", null); x.l = al; x.r = ar; al = x; } return(al); }
public CTree(ATree adr, char c) { a = adr; cmd = c; }
void pCmd() { if (txt != null) { txt.SyncTextToForm(); } ATree a = pARange(); CTree t = null; char c = scn.C; switch (c) { case '{': t = new CTree(a, c); pAppend(t); PushCmd(tail, false); t.sub = new CTree(null, listHead); tail = t.sub; pChar(); if (!scn.EOT()) { pCmd(); } CheckEOT(); return; case '}': CheckEOT(); tail = PopCmd(); if (cts != null && cts.compound) { tail = PopCmd(); } return; case 'a': case 'i': case 'c': CheckTxt(); t = new CTree(a, c); pChar(); if (scn.EOT()) { swallowing = true; stomach = t; } else { scn.SetDelim(pDelim()); scn.GetChar(); t.s = Unescape(scn.GetStr()); t.subs = PrepForSub(ref t.s, c == 'c'); } CheckEOT(); break; case 't': case 'm': CheckTxt(); t = new CTree(a, c); pChar(); t.ad = pARange(); if (t.ad == null) { throw new ssException("address"); } CheckEOT(); break; case 'x': case 'y': case 'g': case 'v': case 'X': case 'Y': t = new CTree(a, c); if (t.cmd != 'X' && t.cmd != 'Y') { CheckTxt(); } pAppend(t); PushCmd(t, true); pChar(); scn.SetDelim(pDelim()); scn.GetChar(); t.s = SetPat(PreEscape(scn.GetStr())); t.sub = new CTree(null, listHead); tail = t.sub; int group = grouping; pCmd(); if (group == grouping) { tail = PopCmd(); } return; case 's': t = new CTree(a, c); pChar(); if (char.IsDigit(scn.C)) { t.n = scn.GetNum(); } else { t.n = 1; } scn.SetDelim(pDelim()); scn.GetChar(); t.s = SetPat(PreEscape(scn.GetStr())); t.rep = Unescape(scn.GetStr()); t.subs = PrepForSub(ref t.rep, true); t.opt = scn.C; if (t.opt != 'g' && t.opt != '\0') { throw new ssException("expected newline"); } CheckEOT(); break; case 'D': case 'B': case 'b': CheckNoAddr(a); t = new CTree(a, c); pChar(); if (scn.C == '<') { pChar(); scn.SetDelim('\0'); string cmd = scn.GetStr(); scn.Init(ShellCmd(cmd, null), false); pChar(); t.fs = pFileList(false); } else { if (!scn.EOT()) { t.fs = pFileList(false); } } break; case 'f': case 'e': case 'r': case 'w': if (c != 'w') { CheckNoAddr(a); } t = new CTree(a, c); pSpOrEot(); pChar(); t.fs = pFileList(true); CheckEOT(); break; case '=': case 'p': case 'd': case 'k': case 'h': CheckEOT(); CheckTxt(); t = new CTree(a, c); break; case 'n': case 'q': case 'Q': case 'H': CheckEOT(); t = new CTree(a, c); break; case 'u': CheckTxt(); t = new CTree(a, c); pChar(); t.n = scn.GetNum(); if (scn.Nothing) { t.n = 1; } CheckEOT(); break; case '!': case '<': case '>': case '|': if (c == '!') { CheckNoAddr(a); } else { CheckTxt(); } t = new CTree(a, c); pChar(); scn.SetDelim('\0'); t.s = scn.GetStr(); break; case '\0': t = new CTree(a, noCmd); break; case 'T': CheckNoAddr(a); CheckTxt(); //win remove for non-windowed version CheckFrm(); // remove for non-windowed version */ t = new CTree(a, c); pChar(); t.n = scn.GetNum(); if (t.n == 0) { t.n = 4; // default spaces in tab } CheckEOT(); break; case 'L': CheckNoAddr(a); CheckTxt(); t = new CTree(a, c); pChar(); t.s = scn.GetStrSpDelim(); if (t.s == "") { t.s = "\r\n"; // default line ending for Windows } t.s = Unescape(t.s); CheckEOT(); break; case 'F': CheckNoAddr(a); CheckTxt(); t = new CTree(a, c); pChar(); t.n = scn.GetNum(); CheckEOT(); break; case 'C': t = new CTree(a, c); pChar(); t.opt = scn.C; if ("si".IndexOf(t.opt) < 0) { CheckTxt(); } if ("ultsi\0".IndexOf(t.opt) < 0) { throw new ssException("bad option or expected newline"); } if (t.opt == '\0') { t.opt = 'l'; } CheckEOT(); break; case 'E': CheckNoAddr(a); t = new CTree(a, c); pChar(); t.opt = scn.C; if ("au387\0".IndexOf(t.opt) < 0) // letters for encodings: ascii, unicode, utf-32, etc. { throw new ssException("bad option or expected newline"); } if (t.opt == '\0') { t.opt = '8'; } CheckEOT(); break; default: throw new ssException("unknown command '" + scn.C + "'"); } pAppend(t); }
ssAddress xAddr(ATree a) { if (a == null) { return(null); } ssText atxt = txt; if (a.fnm != null) { TList fs = FindText(true, a.fnm, true, true); if (fs == null) { throw new ssException("file search"); } atxt = fs.t; } switch (a.op) { case '#': CheckTxt(atxt); CheckRange(atxt, a.n); return(new ssAddress(a.n, a.n, atxt)); case '0': CheckTxt(atxt); ssRange r = atxt.FindLine(0, a.n, 1); return(new ssAddress(r, atxt)); case '.': CheckTxt(atxt); return(new ssAddress(atxt.dot, atxt)); case '\'': CheckTxt(atxt); return(new ssAddress(atxt.mark, atxt)); case '$': CheckTxt(atxt); return(new ssAddress(atxt.Length, atxt.Length, atxt)); case '/': CheckTxt(atxt); return(Search(new ssAddress(atxt.dot, atxt), a.s, true)); case '?': CheckTxt(atxt); return(Search(new ssAddress(atxt.dot, atxt), a.s, false)); case ',': case ';': ssAddress al = xAddr(a.l); if (a.op == ';') { txt = al.txt; txt.dot = al.rng; } ssAddress ar = xAddr(a.r); if (al.txt != ar.txt || ar.rng.l < al.rng.l) { throw new ssException("addresses out of order"); } al.rng.r = ar.rng.r; return(al); case '+': case '-': al = xAddr(a.l); al = xRelAddr(al, a.op, a.r); return(al); default: throw new ssException("address"); } }