public override void VisitRepeatNode(RepeatNode w) { var i = genc.DeclareLocal(typeof(int)); w.Expr.Visit(this); genc.Emit(OpCodes.Stloc, i); Label startLoop = genc.DefineLabel(); Label endLoop = genc.DefineLabel(); genc.MarkLabel(startLoop); w.Block.Visit(this); genc.Emit(OpCodes.Ldloc, i); // положить i на стек genc.Emit(OpCodes.Ldc_I4_1); // положить 1 на стек genc.Emit(OpCodes.Sub); genc.Emit(OpCodes.Stloc, i); // i := i - 1; genc.Emit(OpCodes.Ldloc, i); genc.Emit(OpCodes.Ldc_I4_0); genc.Emit(OpCodes.Ble, endLoop); // if i<=0 then goto endLoop genc.Emit(OpCodes.Br, startLoop); genc.MarkLabel(endLoop); }
public IntSet Visit(RepeatNode node, int posOffset) { int innerPosCount = PosCounter.Of(node.Inner); var result = SparseIntSetType.Instance.Mutable(); // Traverse optional + last repetitions int compilationCount = node.InnerCompilationCount; int minCount = Math.Max(node.MinCount, 1); for (int i = minCount - 1; i != compilationCount; ++i) { int offset = posOffset + innerPosCount * i; result.AddAll(node.Inner.Accept(this, offset)); } bool isInnerNullable = node.Inner.Accept(NullableGetter.Instance); if (isInnerNullable) { // Traverse forced but nullable repetitions for (int i = 0; i != node.MinCount; ++i) { int offset = posOffset + innerPosCount * i; result.AddAll(node.Inner.Accept(this, offset)); } } return(result.CompleteAndDestroy()); }
public void DFA_triggers_actions_correctly() { // Given alphabet const int A = 0; const int B = 1; // Given actions const int Action0 = 1001; const int Action1 = 1002; const int Action2 = 1003; GivenRegularExpression( AstNode.Or( AstNode.Cat( CharSetNode.Create(A), // 0 ActionNode.Create(Action0)), // 1 AstNode.Cat( // CharSetNode.Create(A), // 2 CharSetNode.Create(B), // 3 CharSetNode.Create(B), // 4 ActionNode.Create(Action1) // 5 ), AstNode.Cat( RepeatNode.ZeroOrMore(CharSetNode.Create(A)), // 6 RepeatNode.OneOrMore(CharSetNode.Create(B)), // 7, 8 ActionNode.Create(Action2)) // 9 )); CreateDfa(); DfaShouldTriggerAction(Action0, A); DfaShouldTriggerAction(Action1, A, B, B); DfaShouldTriggerAction(Action2, A, B); DfaShouldTriggerAction(Action2, A, B, B, B); }
public override void VisitRepeatNode(RepeatNode repeatnode) { var i = genc.DeclareLocal(typeof(int)); repeatnode.Expr.Visit(this); genc.Emit(OpCodes.Stloc, i); Label startLoop = genc.DefineLabel(); Label endLoop = genc.DefineLabel(); genc.MarkLabel(startLoop); foreach (var st in repeatnode.StList) { st.Visit(this); } genc.Emit(OpCodes.Ldloc, i); genc.Emit(OpCodes.Ldc_I4_1); genc.Emit(OpCodes.Sub); genc.Emit(OpCodes.Stloc, i); genc.Emit(OpCodes.Ldloc, i); genc.Emit(OpCodes.Ldc_I4_0); genc.Emit(OpCodes.Ble, endLoop); genc.Emit(OpCodes.Br, startLoop); genc.MarkLabel(endLoop); }
public void dfa_provides_correct_serialization_information() { // Given alphabet const int A = 0; const int B = 1; // Given actions const int Action0 = 1001; const int Action1 = 1002; const int Action2 = 1003; GivenRegularExpression( AstNode.Or( AstNode.Cat( CharSetNode.Create(A), ActionNode.Create(Action0)), AstNode.Cat( CharSetNode.Create(A), CharSetNode.Create(B), CharSetNode.Create(B), ActionNode.Create(Action1) ), AstNode.Cat( RepeatNode.ZeroOrMore(CharSetNode.Create(A)), RepeatNode.OneOrMore(CharSetNode.Create(B)), ActionNode.Create(Action2)) )); CreateDfa(); var output = new StringBuilder(); serialization.Print(output); // DUBUG: Console.WriteLine(output); }
protected override void OnDispose() { base.OnDispose(); _repeatNode?.Dispose(); _repeatNode = null; _sequenceNode = null; }
void Start() { var delay = DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒")); var repeatNode = new RepeatNode(delay, 10); this.ExecuteNode(repeatNode); }
public object Visit(RepeatNode node, object value) { for (int i = 0; i != node.InnerCompilationCount; ++i) { node.Inner.Accept(this, null); } return(this); }
public void ReturnsFailureImmediately() { var n = new InMemoryVariable <int>(0); var child = new ReturnXNode(NodeStatus.FAILURE); var node = new RepeatNode(child, n); var status = node.Tick(); Assert.That(status, Is.EqualTo(NodeStatus.FAILURE)); Assert.That(child.Ticks, Is.EqualTo(1)); }
public void HaltsAfterFailure() { var n = new InMemoryVariable <int>(0); var child = new ReturnXNode(NodeStatus.FAILURE); var node = new RepeatNode(child, n); var status = node.Tick(); Assert.That(status, Is.EqualTo(NodeStatus.FAILURE)); Assert.That(child.Halts, Is.EqualTo(1)); }
public void HaltsAfterSuccess() { var n = new InMemoryVariable <int>(0); var child = new ReturnXNode(NodeStatus.SUCCESS); var node = new RepeatNode(child, n); var status = node.Tick(); Assert.That(status, Is.EqualTo(NodeStatus.SUCCESS)); Assert.That(child.Halts, Is.EqualTo(1)); }
public void Visit(RepeatNode repeatNode) { repeatNode.Count.Parent = repeatNode; repeatNode.Count.Accept(this); var loop = _currentLoop; _currentLoop = LoopType.Loop; repeatNode.Body.Parent = repeatNode; repeatNode.Body.Accept(this); _currentLoop = loop; }
public override void VisitRepeatNode(RepeatNode c) { Text += IndentStr() + "repeat "; Text += Environment.NewLine; IndentPlus(); c.Stlist.Visit(this); IndentMinus(); Text += Environment.NewLine; Text += IndentStr() + "until "; c.Expr.Visit(this); }
protected override void OnDispose() { base.OnDispose(); if (null != mRepeatNode) { mRepeatNode.Dispose(); } mRepeatNode = null; mSequenceNode = null; }
public override void VisitRepeatNode(RepeatNode c) { Label startLoop = genc.DefineLabel(); Label endLoop = genc.DefineLabel(); genc.MarkLabel(startLoop); c.Block.Visit(this); c.Сondition.Visit(this); genc.Emit(OpCodes.Brfalse, endLoop); genc.Emit(OpCodes.Br, startLoop); genc.MarkLabel(endLoop); }
public override void VisitRepeatNode(RepeatNode repeat_node) { Label startRepeat = genc.DefineLabel(); Label endRepeat = genc.DefineLabel(); genc.MarkLabel(startRepeat); repeat_node.StList.Visit(this); repeat_node.Expr.Visit(this); genc.Emit(OpCodes.Brfalse, endRepeat); genc.Emit(OpCodes.Br, startRepeat); genc.MarkLabel(endRepeat); }
public void DoesNotHaltAfterRunning(int n) { var child = new ReturnXNode(NodeStatus.RUNNING); var node = new RepeatNode(child, new InMemoryVariable <int>(n)); for (int i = 0; i < n; i++) { var status = node.Tick(); Assert.That(status, Is.EqualTo(NodeStatus.RUNNING)); } Assert.That(child.Ticks, Is.EqualTo(n)); Assert.That(child.Halts, Is.EqualTo(0)); }
//[UnityTest] public IEnumerator RepeatNodeTest() { var callCount = 0; var delayAction = DelayAction.Allocate(1.0f, () => { callCount++; }); var repeatNode = new RepeatNode(delayAction, 2); while (!repeatNode.Execute(Time.deltaTime)) { yield return(null); } Debug.Log(callCount); }
public void ReturnsSuccessAfterNSuccesses(int n) { var child = new ReturnXNode(NodeStatus.SUCCESS); var node = new RepeatNode(child, new InMemoryVariable <int>(n)); for (int i = 0; i < n; i++) { Assert.That(node.Tick(), Is.EqualTo(NodeStatus.RUNNING)); } Assert.That(node.Tick(), Is.EqualTo(NodeStatus.SUCCESS)); // ticked once at the beginning and once more for every tick that returned success until n Assert.That(child.Ticks, Is.EqualTo(n + 1)); }
public object Visit(RepeatNode node, int posOffset) { FillFollowPos( posOffset, positions, Enumerable.Repeat(node.Inner, node.InnerCompilationCount)); if (node.MaxCount == int.MaxValue) { FillFollowPosClosure( posOffset + node.MinCount * PosCounter.Of(node.Inner), node.Inner); } return(this); }
public override void VisitRepeatNode(RepeatNode c) { var i = genc.DeclareLocal(typeof(int)); // переменная цикла cycle Label startLoop = genc.DefineLabel(); genc.MarkLabel(startLoop); c.Stlist.Visit(this); // выполнить тело цикла c.Expr.Visit(this); // сгенерировать команды, связанные с вычислением количества итераций цикла genc.Emit(OpCodes.Stloc, i); genc.Emit(OpCodes.Ldloc, i); genc.Emit(OpCodes.Ldc_I4_0); genc.Emit(OpCodes.Bgt, startLoop); // if i<=0 then goto endLoop }
private void RecycleInner() { if (_tv != null && !_tv.recyled) { _tv.Recyle(); _tv = null; } if (_seq != null && !_seq.recyled) { _seq.Recyle(); _seq = null; } if (_repeat != null && !_repeat.recyled) { _repeat.Recyle(); _repeat = null; } }
public void DFA_matches_input_correctly() { // Given alphabet const int A = 0; const int B = 1; GivenRegularExpression( new CatNode(new List <AstNode> { RepeatNode.ZeroOrMore( new OrNode(new List <AstNode> { CharSetNode.Create(A), CharSetNode.Create(B) })), CharSetNode.Create(A), CharSetNode.Create(B), CharSetNode.Create(B) }) ); CreateDfa(); DfaShouldMatch(A, B, B); DfaShouldMatch(A, A, A, A, B, B); DfaShouldMatch(B, B, B, A, B, B); DfaShouldMatch(A, B, B, A, B, B); DfaShouldNotMatch(); DfaShouldNotMatch(A, B); DfaShouldNotMatch(A, B, B, A); DfaShouldNotMatch(A, B, B, B); DfaShouldMatchBeginning(A, B, B); DfaShouldMatchBeginning(A, A, A, A, B, B); DfaShouldMatchBeginning(B, B, B, A, B, B); DfaShouldMatchBeginning(A, B, B, A, B, B); DfaShouldMatchBeginning(A, B, B, A); DfaShouldMatchBeginning(A, B, B, B); DfaShouldNotMatchBeginning(); DfaShouldNotMatchBeginning(A, B, A, B); DfaShouldNotMatchBeginning(A, A, A, A); DfaShouldNotMatchBeginning(B, B, B, B); }
public void input_equivalence_classes_are_used() { // Given alphabet int A = 0; int B = 0x10FFFF; // Unicode max GivenRegularExpression( new CatNode(new List <AstNode> { RepeatNode.ZeroOrMore(CharSetNode.CreateRange(A, B)), CharSetNode.Create(A), CharSetNode.Create(B), CharSetNode.Create(B) }) ); CreateDfa(); DfaShouldMatch(A, B, B); DfaShouldMatch(A, A, A, A, B, B); DfaShouldMatch(B, B, B, A, B, B); DfaShouldMatch(A, B, B, A, B, B); DfaShouldNotMatch(); DfaShouldNotMatch(A, B); DfaShouldNotMatch(A, B, B, A); DfaShouldNotMatch(A, B, B, B); DfaShouldMatchBeginning(A, B, B); DfaShouldMatchBeginning(A, A, A, A, B, B); DfaShouldMatchBeginning(B, B, B, A, B, B); DfaShouldMatchBeginning(A, B, B, A, B, B); DfaShouldMatchBeginning(A, B, B, A); DfaShouldMatchBeginning(A, B, B, B); DfaShouldNotMatchBeginning(); DfaShouldNotMatchBeginning(A, B, A, B); DfaShouldNotMatchBeginning(A, A, A, A); DfaShouldNotMatchBeginning(B, B, B, B); }
public Piece OneOrMore(Piece atom) { return(new Piece { Node = RepeatNode.OneOrMore(atom.Node) }); }
public Piece ZeroOrMore(Piece atom) { return(new Piece { Node = RepeatNode.ZeroOrMore(atom.Node) }); }
public Piece Optional(Piece atom) { return(new Piece { Node = RepeatNode.Optional(atom.Node) }); }
public RepeatNodeChain(int repeatCount) { mSequenceNode = new SequenceNode(); mRepeatAction = new RepeatNode(mSequenceNode, repeatCount); }
public virtual void VisitRepeatNode(RepeatNode w) { }
public int Visit(RepeatNode node) { return(node.Inner.Accept(this) * node.InnerCompilationCount); }