// Begin exec iteration functions public override void Execute(Interpreter inI) { IntStack istack = inI.IntStack(); ObjectStack estack = inI.ExecStack(); if (_stack.Size() > 0 && istack.Size() > 1) { int stop = istack.Pop(); int start = istack.Pop(); object code = _stack.Pop(); if (start == stop) { istack.Push(start); estack.Push(code); } else { istack.Push(start); start = (start < stop) ? (start + 1) : (start - 1); // trh//Made changes to correct errors with code.do*range try { Program recursiveCallProgram = new Program(); recursiveCallProgram.Push(start); recursiveCallProgram.Push(stop); recursiveCallProgram.Push("exec.do*range"); recursiveCallProgram.Push(code); estack.Push(recursiveCallProgram); } catch (Exception) { Console.Error.WriteLine("Error while initializing a program."); } estack.Push(code); } } }
public void StampRepresentation() { istack.Push(1); istack.Push(0); // Assert.AreEqual("[1 0]", istack.ToString()); Assert.AreEqual("[0 1]", istack.ToString()); Assert.AreEqual(0, istack.Pop()); Assert.AreEqual(1, istack.Pop()); // Assert.AreEqual(new [] { 1, 2, 3}, new [] { 1, 0, 4, 5}); }
public override void Execute(Interpreter inI) { IntStack istack = inI.IntStack(); ObjectStack estack = inI.ExecStack(); if (_stack.Size() > 0 && istack.Size() > 0) { if (istack.Top() > 0) { int stop = istack.Pop() - 1; object bodyObj = _stack.Pop(); try { Program doRangeMacroProgram = new Program(); doRangeMacroProgram.Push(0); doRangeMacroProgram.Push(stop); doRangeMacroProgram.Push("exec.do*range"); doRangeMacroProgram.Push(bodyObj); estack.Push(doRangeMacroProgram); } catch (Exception) { Console.Error.WriteLine("Error while initializing a program."); } } } }
public void Test1() { IntStack x = new IntStack(3); x.Push(1); x.Push(2); Assert.Equal(false, x.IsEmpty()); Assert.Equal(2, x.Pop()); }
public override void Execute(Interpreter inI) { ObjectStack codeStack = inI.CodeStack(); IntStack iStack = inI.IntStack(); if (iStack.Size() > 0) { codeStack.Push(iStack.Pop()); } }
public override void Execute(Interpreter inI) { IntStack iStack = inI.IntStack(); if (iStack.Size() > 0) { int index = iStack.Pop(); if (_stack.Size() > 0) { _stack.YankDup(index); } else { iStack.Push(index); } } }
private void MoveForward(IList <DirectedConnection> connList, int currConnIdx) { // If the current node has at least one more outgoing connection leading to an unvisited node, // then update the node's entry on the top of the stack to point to said connection. for (int i = currConnIdx + 1; i < connList.Count && (connList[currConnIdx].SourceId == connList[i].SourceId); i++) { if (!_visitedNodes.Contains(connList[i].TargetId)) { _traversalStack.Poke(currConnIdx + 1); return; } } // No more connections for the current node; pop/remove the current node from the top of the stack. // Traversal will thus continue from its traversal parent node's current position, or will terminate // if the stack is now empty. _traversalStack.Pop(); }
/// <summary> /// Update the stack state to point to the next connection to traverse down. /// </summary> /// <returns>The current connection to traverse down.</returns> private void MoveForward(int[] srcIdArr, int[] tgtIdAr, int currConnIdx) { // If the current node has at least one more outgoing connection leading to an unvisited node, // then update the node's entry on the top of the stack to point to said connection. for (int i = currConnIdx + 1; i < srcIdArr.Length && (srcIdArr[currConnIdx] == srcIdArr[i]); i++) { if (!_visitedNodeBitmap[tgtIdAr[i]]) { _traversalStack.Poke(currConnIdx + 1); return; } } // No more connections for the current node; pop/remove the current node from the top of the stack. // Traversal will thus continue from its traversal parent node's current position, or will terminate // if the stack is now empty. _traversalStack.Pop(); }
public override void Execute(Interpreter inI) { IntStack istack = inI.IntStack(); if (istack.Size() > 0 && _stack.Size() > 0) { int index = istack.Pop(); if (index < 0) { index = 0; } if (index >= _stack.Size()) { index = _stack.Size() - 1; } inI.GetInputPusher().PushInput(inI, index); } }
static void Main(string[] args) { // create a new IntStack IntStack stack = new IntStack(); stack.Push(2); stack.Push(4); stack.Push(8); for (int i = 0; i < 3; i++) { Console.WriteLine("Pop value: {0}", stack.Pop()); } // wait for input before exiting Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
public override void Execute(Interpreter inI) { IntStack istack = inI.IntStack(); ObjectStack estack = inI.ExecStack(); if (_stack.Size() > 0 && istack.Size() > 0) { if (istack.Top() > 0) { object bodyObj = _stack.Pop(); if (bodyObj is Program) { // insert integer.pop in front of program ((Program)bodyObj).Shove("integer.pop", ((Program)bodyObj)._size); } else { // create a new program with integer.pop in front of // the popped object Program newProgram = new Program(); newProgram.Push("integer.pop"); newProgram.Push(bodyObj); bodyObj = newProgram; } int stop = istack.Pop() - 1; try { Program doRangeMacroProgram = new Program(); doRangeMacroProgram.Push(0); doRangeMacroProgram.Push(stop); doRangeMacroProgram.Push("code.quote"); doRangeMacroProgram.Push(bodyObj); doRangeMacroProgram.Push("code.do*range"); estack.Push(doRangeMacroProgram); } catch (Exception) { Console.Error.WriteLine("Error while initializing a program."); } } } }
static void Main(string[] args) { // create an instance from the derived type IntStack intStack = new IntStack(); // upcast to the base type GenericStack <int> gStack = intStack; // push some data into the stack intStack.Push(1); intStack.Push(2); intStack.Push(3); // pop the data back out of the stack for (int i = 0; i < 3; i++) { Console.WriteLine("Popped Value: {0}", intStack.Pop()); } // wait for input before exiting Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
private bool Eval(Mode mode, ref int ref_ptr, int pc) { int ref_ptr2 = ref_ptr; while (true) { ushort num = program[pc]; OpCode opCode = (OpCode)(num & 0xFF); OpFlags opFlags = (OpFlags)(num & 0xFF00); int num13; int num12; bool flag; int num15; int num11; RepeatContext repeatContext; int start; int count; int count2; switch (opCode) { default: continue; case OpCode.Anchor: { num13 = program[pc + 1]; num12 = program[pc + 2]; flag = ((opFlags & OpFlags.RightToLeft) != OpFlags.None); num11 = ((!flag) ? (ref_ptr2 + num12) : (ref_ptr2 - num12)); num15 = text_end - match_min + num12; int num16 = 0; OpCode opCode3 = (OpCode)(program[pc + 3] & 0xFF); if (opCode3 == OpCode.Position && num13 == 6) { switch (program[pc + 4]) { case 2: break; case 3: goto IL_0165; case 4: goto IL_0234; default: goto end_IL_0028; } if (flag || num12 == 0) { if (flag) { ref_ptr2 = num12; } if (TryMatch(ref ref_ptr2, pc + num13)) { goto case OpCode.True; } break; } break; } if (qs != null || (opCode3 == OpCode.String && num13 == 6 + program[pc + 4])) { bool flag4 = (ushort)(program[pc + 3] & 0x400) != 0; if (qs == null) { bool ignore = (ushort)(program[pc + 3] & 0x200) != 0; string @string = GetString(pc + 3); qs = new QuickSearch(@string, ignore, flag4); } while ((flag && num11 >= num16) || (!flag && num11 <= num15)) { if (flag4) { num11 = qs.Search(text, num11, num16); if (num11 != -1) { num11 += qs.Length; } } else { num11 = qs.Search(text, num11, num15); } if (num11 < 0) { break; } ref_ptr2 = ((!flag4) ? (num11 - num12) : (num11 + num12)); if (TryMatch(ref ref_ptr2, pc + num13)) { goto case OpCode.True; } num11 = ((!flag4) ? (num11 + 1) : (num11 - 2)); } break; } if (opCode3 == OpCode.True) { while ((flag && num11 >= num16) || (!flag && num11 <= num15)) { ref_ptr2 = num11; if (TryMatch(ref ref_ptr2, pc + num13)) { goto case OpCode.True; } num11 = ((!flag) ? (num11 + 1) : (num11 - 1)); } break; } for (; (flag && num11 >= num16) || (!flag && num11 <= num15); num11 = ((!flag) ? (num11 + 1) : (num11 - 1))) { ref_ptr2 = num11; if (!Eval(Mode.Match, ref ref_ptr2, pc + 3)) { continue; } ref_ptr2 = ((!flag) ? (num11 - num12) : (num11 + num12)); if (!TryMatch(ref ref_ptr2, pc + num13)) { continue; } goto case OpCode.True; } break; } case OpCode.Position: if (!IsPosition((Position)program[pc + 1], ref_ptr2)) { break; } pc += 2; continue; case OpCode.String: { bool flag5 = (opFlags & OpFlags.RightToLeft) != OpFlags.None; bool flag6 = (opFlags & OpFlags.IgnoreCase) != OpFlags.None; int num17 = program[pc + 1]; if (flag5) { ref_ptr2 -= num17; if (ref_ptr2 < 0) { break; } } else if (ref_ptr2 + num17 > text_end) { break; } pc += 2; for (int k = 0; k < num17; k++) { char c = text[ref_ptr2 + k]; if (flag6) { c = char.ToLower(c); } if (c != program[pc++]) { goto end_IL_0028; } } if (!flag5) { ref_ptr2 += num17; } continue; } case OpCode.Reference: { bool flag2 = (opFlags & OpFlags.RightToLeft) != OpFlags.None; bool flag3 = (opFlags & OpFlags.IgnoreCase) != OpFlags.None; int lastDefined2 = GetLastDefined(program[pc + 1]); if (lastDefined2 < 0) { break; } int index = marks[lastDefined2].Index; int length = marks[lastDefined2].Length; if (flag2) { ref_ptr2 -= length; if (ref_ptr2 < 0) { break; } } else if (ref_ptr2 + length > text_end) { break; } pc += 2; if (flag3) { for (int i = 0; i < length; i++) { if (char.ToLower(text[ref_ptr2 + i]) != char.ToLower(text[index + i])) { goto end_IL_0028; } } } else { for (int j = 0; j < length; j++) { if (text[ref_ptr2 + j] != text[index + j]) { goto end_IL_0028; } } } if (!flag2) { ref_ptr2 += length; } continue; } case OpCode.Character: case OpCode.Category: case OpCode.NotCategory: case OpCode.Range: case OpCode.Set: if (!EvalChar(mode, ref ref_ptr2, ref pc, multi: false)) { break; } continue; case OpCode.In: { int num10 = pc + program[pc + 1]; pc += 2; if (!EvalChar(mode, ref ref_ptr2, ref pc, multi: true)) { break; } pc = num10; continue; } case OpCode.Open: Open(program[pc + 1], ref_ptr2); pc += 2; continue; case OpCode.Close: Close(program[pc + 1], ref_ptr2); pc += 2; continue; case OpCode.BalanceStart: { int ptr = ref_ptr2; if (!Eval(Mode.Match, ref ref_ptr2, pc + 5) || !Balance(program[pc + 1], program[pc + 2], (program[pc + 3] == 1) ? true : false, ptr)) { break; } pc += program[pc + 4]; continue; } case OpCode.IfDefined: { int lastDefined = GetLastDefined(program[pc + 2]); pc = ((lastDefined >= 0) ? (pc + 3) : (pc + program[pc + 1])); continue; } case OpCode.Sub: if (!Eval(Mode.Match, ref ref_ptr2, pc + 2)) { break; } pc += program[pc + 1]; continue; case OpCode.Test: { int cp4 = Checkpoint(); int ref_ptr3 = ref_ptr2; if (Eval(Mode.Match, ref ref_ptr3, pc + 3)) { pc += program[pc + 1]; continue; } Backtrack(cp4); pc += program[pc + 2]; continue; } case OpCode.Branch: while (true) { int cp2 = Checkpoint(); if (Eval(Mode.Match, ref ref_ptr2, pc + 2)) { break; } Backtrack(cp2); pc += program[pc + 1]; if ((ushort)(program[pc] & 0xFF) == 0) { goto end_IL_0028; } } goto case OpCode.True; case OpCode.Jump: pc += program[pc + 1]; continue; case OpCode.Repeat: repeat = new RepeatContext(repeat, ReadProgramCount(pc + 2), ReadProgramCount(pc + 4), (opFlags & OpFlags.Lazy) != OpFlags.None, pc + 6); if (Eval(Mode.Match, ref ref_ptr2, pc + program[pc + 1])) { goto case OpCode.True; } repeat = repeat.Previous; break; case OpCode.Until: repeatContext = repeat; if (deep != repeatContext) { start = repeatContext.Start; count = repeatContext.Count; while (!repeatContext.IsMinimum) { repeatContext.Count++; repeatContext.Start = ref_ptr2; deep = repeatContext; if (!Eval(Mode.Match, ref ref_ptr2, repeatContext.Expression)) { goto IL_09bc; } if (deep == repeatContext) { continue; } goto case OpCode.True; } if (ref_ptr2 == repeatContext.Start) { repeat = repeatContext.Previous; deep = null; if (!Eval(Mode.Match, ref ref_ptr2, pc + 1)) { repeat = repeatContext; break; } } else if (repeatContext.IsLazy) { while (true) { repeat = repeatContext.Previous; deep = null; int cp3 = Checkpoint(); if (Eval(Mode.Match, ref ref_ptr2, pc + 1)) { break; } Backtrack(cp3); repeat = repeatContext; if (repeatContext.IsMaximum) { goto end_IL_0028; } repeatContext.Count++; repeatContext.Start = ref_ptr2; deep = repeatContext; if (!Eval(Mode.Match, ref ref_ptr2, repeatContext.Expression)) { repeatContext.Start = start; repeatContext.Count = count; goto end_IL_0028; } if (deep != repeatContext) { break; } if (ref_ptr2 == repeatContext.Start) { goto end_IL_0028; } } } else { count2 = stack.Count; while (true) { if (!repeatContext.IsMaximum) { int num14 = Checkpoint(); int value = ref_ptr2; int start2 = repeatContext.Start; repeatContext.Count++; repeatContext.Start = ref_ptr2; deep = repeatContext; if (!Eval(Mode.Match, ref ref_ptr2, repeatContext.Expression)) { repeatContext.Count--; repeatContext.Start = start2; Backtrack(num14); } else { if (deep != repeatContext) { break; } stack.Push(num14); stack.Push(value); if (ref_ptr2 != repeatContext.Start) { continue; } } } repeat = repeatContext.Previous; goto IL_0bf5; } stack.Count = count2; } } goto case OpCode.True; case OpCode.FastRepeat: { fast = new RepeatContext(fast, ReadProgramCount(pc + 2), ReadProgramCount(pc + 4), (opFlags & OpFlags.Lazy) != OpFlags.None, pc + 6); fast.Start = ref_ptr2; int cp = Checkpoint(); pc += program[pc + 1]; ushort num2 = program[pc]; int num3 = -1; int num4 = -1; int num5 = 0; OpCode opCode2 = (OpCode)(num2 & 0xFF); if (opCode2 == OpCode.Character || opCode2 == OpCode.String) { OpFlags opFlags2 = (OpFlags)(num2 & 0xFF00); if ((opFlags2 & OpFlags.Negate) == OpFlags.None) { if (opCode2 == OpCode.String) { int num6 = 0; if ((opFlags2 & OpFlags.RightToLeft) != 0) { num6 = program[pc + 1] - 1; } num3 = program[pc + 2 + num6]; } else { num3 = program[pc + 1]; } num4 = (((opFlags2 & OpFlags.IgnoreCase) == OpFlags.None) ? num3 : char.ToUpper((char)num3)); num5 = (((opFlags2 & OpFlags.RightToLeft) != 0) ? (-1) : 0); } } if (fast.IsLazy) { if (!fast.IsMinimum && !Eval(Mode.Count, ref ref_ptr2, fast.Expression)) { fast = fast.Previous; break; } while (true) { int num7 = ref_ptr2 + num5; if (num3 < 0 || (num7 >= 0 && num7 < text_end && (num3 == text[num7] || num4 == text[num7]))) { deep = null; if (Eval(Mode.Match, ref ref_ptr2, pc)) { break; } } if (fast.IsMaximum) { goto IL_0e57; } Backtrack(cp); if (Eval(Mode.Count, ref ref_ptr2, fast.Expression)) { continue; } goto IL_0e8e; } fast = fast.Previous; } else { if (!Eval(Mode.Count, ref ref_ptr2, fast.Expression)) { fast = fast.Previous; break; } int num8 = (fast.Count > 0) ? ((ref_ptr2 - fast.Start) / fast.Count) : 0; while (true) { int num9 = ref_ptr2 + num5; if (num3 < 0 || (num9 >= 0 && num9 < text_end && (num3 == text[num9] || num4 == text[num9]))) { deep = null; if (Eval(Mode.Match, ref ref_ptr2, pc)) { break; } } fast.Count--; if (fast.IsMinimum) { ref_ptr2 -= num8; Backtrack(cp); continue; } goto IL_0fab; } fast = fast.Previous; } goto case OpCode.True; } case OpCode.True: case OpCode.Balance: ref_ptr = ref_ptr2; switch (mode) { case Mode.Match: return(true); case Mode.Count: fast.Count++; if (!fast.IsMaximum && (!fast.IsLazy || !fast.IsMinimum)) { pc = fast.Expression; continue; } return(true); } break; case OpCode.False: case OpCode.Info: break; IL_0fab: fast = fast.Previous; break; IL_0234: if (num11 == scan_ptr) { ref_ptr2 = ((!flag) ? (scan_ptr - num12) : (scan_ptr + num12)); if (TryMatch(ref ref_ptr2, pc + num13)) { goto case OpCode.True; } break; } break; IL_0165: if (num11 == 0) { ref_ptr2 = 0; if (TryMatch(ref ref_ptr2, pc + num13)) { goto case OpCode.True; } num11++; } for (; (flag && num11 >= 0) || (!flag && num11 <= num15); num11 = ((!flag) ? (num11 + 1) : (num11 - 1))) { if (num11 != 0 && text[num11 - 1] != '\n') { continue; } ref_ptr2 = ((!flag) ? ((num11 != 0) ? (num11 - num12) : num11) : ((num11 != num15) ? (num11 + num12) : num11)); if (!TryMatch(ref ref_ptr2, pc + num13)) { continue; } goto case OpCode.True; } break; IL_0c31: repeat = repeatContext; break; IL_09bc: repeatContext.Start = start; repeatContext.Count = count; break; IL_0e57: fast = fast.Previous; break; IL_0e8e: fast = fast.Previous; break; IL_0bf5: while (true) { deep = null; if (Eval(Mode.Match, ref ref_ptr2, pc + 1)) { break; } if (stack.Count != count2) { repeatContext.Count--; ref_ptr2 = stack.Pop(); Backtrack(stack.Pop()); continue; } goto IL_0c31; } stack.Count = count2; goto case OpCode.True; end_IL_0028: break; } break; } switch (mode) { case Mode.Match: return(false); case Mode.Count: if (!fast.IsLazy && fast.IsMinimum) { return(true); } ref_ptr = fast.Start; return(false); default: return(false); } }