internal NState GetNext(int sym) { NState rslt = null; ulong key = checked(((ulong)this.serialNumber << 32) + (ulong)sym); myNfsa.next.TryGetValue(key, out rslt); return rslt; }
/// <summary> /// Add a transition from NState "this" /// to NState "nxt", for each character /// value in the leaf range list. /// If the characters are packed, transform /// from character ordinal to equivalence class /// ordinal. /// </summary> /// <param name="leaf">The regex leaf node</param> /// <param name="nxt">The destination state</param> public void AddClsTrans(Leaf leaf, NState nxt) { BitArray cls = new BitArray(myNfaInst.MaxSym); if (myNfaInst.Pack) { foreach (int ord in leaf.rangeLit.equivClasses) { cls[ord] = true; } } else { foreach (CharRange rng in leaf.rangeLit.list.Ranges) { for (int i = rng.minChr; i <= rng.maxChr; i++) { cls[i] = true; } } if (leaf.rangeLit.list.IsInverted) { cls = cls.Not(); } } AddClsTrans(cls, nxt); }
/// <summary> /// Add a transition from NState "this" /// to NState "nxt", for each character /// value in the leaf range list. /// If the characters are packed, transform /// from character ordinal to equivalence class /// ordinal. /// </summary> /// <param name="leaf">The regex leaf node</param> /// <param name="nxt">The destination state</param> public void AddClsTrans(Leaf leaf, NState nxt) { if (myNfaInst.parent.task.CaseAgnostic) { leaf.rangeLit.list = leaf.rangeLit.list.MakeCaseAgnosticList(); leaf.rangeLit.list.Canonicalize(); } BitArray cls = new BitArray(myNfaInst.MaxSym); if (myNfaInst.Pack) { foreach (int ord in leaf.rangeLit.equivClasses) { cls[ord] = true; } } else { foreach (CharRange rng in leaf.rangeLit.list.Ranges) { for (int i = rng.minChr; i <= rng.maxChr; i++) { cls[i] = true; } } if (leaf.rangeLit.list.IsInverted) { cls = cls.Not(); } } AddClsTrans(cls, nxt); }
internal NState GetNext(int sym) { NState rslt = null; uint key = (this.serialNumber << 16) + (ushort)sym; myNfsa.next.TryGetValue(key, out rslt); return(rslt); }
public bool StateTransition(EState state) { movementState.ExitState(); movementState = movementStates[(int)state]; movementState.EnterState(); this.state = state; return(true); }
internal NState MkState() { NState s = new NState(this); s.ord = nStates.Count; if (s.ord >= maxE) maxE *= 2; nStates.Add(s); return s; }
private void AddTrns(int chr, NState nxt) { if (myNfaInst.Pack) { chr = myNfaInst.parent.task.partition[chr]; } AddRawTransition(chr, nxt); }
// // For version 1.0.1 recognize any line-end character if /unicode // static void AddAnchorContext(NfsaInstance nInst, NState endS, RuleDesc rule) { NState nEnd = nInst.MkState(); Leaf temp = new Leaf(RegOp.charClass); temp.rangeLit = RangeLiteral.RightAnchors; nInst.MakePath(temp, endS, nEnd); nInst.MarkAccept(nEnd, rule); nEnd.rhCntx = 1; }
/// <summary> /// Add an epsilon transition from "this" to "nxt" /// </summary> /// <param name="nxt">Destination state</param> public void AddEpsTrns(NState nxt) { int count = epsilons.Count; if (count < myNfaInst.MaxEps) epsilons.Length = myNfaInst.MaxEps; if (!epsilons[nxt.ord]) { epsList.Add(nxt); epsilons[nxt.ord] = true; } }
/// <summary> /// Add a transition from "this" to "next" /// for every true bit in the BitArray cls /// </summary> /// <param name="cls">The transition bit array</param> /// <param name="nxt">The destination state</param> private void AddClsTrans(BitArray cls, NState nxt) { for (int i = 0; i < cls.Count; i++) { if (cls[i]) { AddRawTransition(i, nxt); } } }
/// <summary> /// Add a transition to the NState. /// Assert: if the symbol ordinals are packed /// the mapping has already been performed /// </summary> /// <param name="ord">The symbol index</param> /// <param name="nxt">The destination state</param> private void AddRawTransition(int ord, NState nxt) { if (GetNext(ord) == null) SetNext(ord, nxt); else // state must have overlapping alternatives { NState temp = myNfaInst.MkState(); this.AddEpsTrns(temp); temp.AddRawTransition(ord, nxt); } }
public NfsaInstance(StartState ss, NFSA parent) { myStartCondition = ss; this.parent = parent; this.pack = parent.task.ChrClasses; if (pack) maxS = parent.task.partition.Length; // Number of equivalence classes else maxS = parent.task.TargetSymCardinality; // Size of alphabet entryState = MkState(); }
internal NState MkState() { NState s = new NState(this); s.ord = nStates.Count; if (s.ord >= MaxEps) { MaxEps *= 2; } nStates.Add(s); return(s); }
void Start() { rigidBody = GetComponent <Rigidbody2D>(); boxCollider = GetComponent <BoxCollider2D>(); animator = GetComponent <Animator>(); spriteRenderer = GetComponent <SpriteRenderer>(); fireParticles = transform.GetChild(0).GetComponent <ParticleSystem>(); bloodParticles = transform.GetChild(1).GetComponent <ParticleSystem>(); joystick = ReInput.players.GetPlayer(playerNumber); movementBools = new Dictionary <string, bool>(); movementBools["pushed"] = false; movementBools["succed"] = false; movementBools["bounced"] = false; movementBools["frozen"] = false; movementBools["ashed"] = false; movementBools["spiked"] = false; movementBools["slipped"] = false; movementBools["doubled"] = false; movementBools["active"] = false; NStateInfo info = new NStateInfo(this, rigidBody, boxCollider, joystick, animator, spriteRenderer, balanceData); movementStates = new NState[13]; movementStates[0] = new NStateNormal(info, EState.normal); movementStates[1] = new NStateJump1(info, EState.jump1); movementStates[2] = new NStateJump2(info, EState.jump2); movementStates[3] = new NStateAshes(info, EState.ashes); movementStates[4] = new NStateAirborne(info, EState.airborne); movementStates[5] = new NStateSucc(info, EState.succ, transform.position); movementStates[6] = new NStatePushed(info, EState.pushed, Vector2.zero); movementStates[7] = new NStateBounced(info, EState.bounced, info.bd.bouncedInitialVelocity, info.bd.bouncedTransitionLockoutFrames); movementStates[8] = new NStateSpiked(info, EState.spiked, Vector2.zero); movementStates[9] = new NStateSlipped(info, EState.slipped); movementStates[10] = new NStateSlam(info, EState.slam); movementStates[11] = new NStateBounced(info, EState.boinked, info.bd.boinkedInitialVelocity, info.bd.boinkedTransitionLockoutFrames); movementStates[12] = new NStateInactive(info, EState.inactive); movementState = movementStates[12]; weapons = new SortedList <EElement, Queue <NWeapon> >(6); weapons[EElement.air] = new Queue <NWeapon>(weaponCounts[0]); weapons[EElement.fire] = new Queue <NWeapon>(weaponCounts[1]); weapons[EElement.water] = new Queue <NWeapon>(weaponCounts[2]); weapons[EElement.earth] = new Queue <NWeapon>(weaponCounts[3]); weapons[EElement.plasma] = new Queue <NWeapon>(weaponCounts[4]); weapons[EElement.none] = new Queue <NWeapon>(1); weaponEquipped = EElement.air; weapon = null; totem = null; totemDist = Mathf.Infinity; living = true; avatar = false; }
/// <summary> /// Add a transition from NState "this" /// to NState "nxt", for the character "chr". /// If the characters are packed, transform /// from character ordinal to equivalence class /// ordinal. /// </summary> /// <param name="chr">The character value</param> /// <param name="nxt">The destination state</param> public void AddChrTrns(int chr, NState nxt) { if (myNfaInst.parent.task.CaseAgnostic && chr < Char.MaxValue) { char c = (char)chr; char lo = Char.ToLower(c); char hi = Char.ToUpper(c); if (lo != hi) { AddTrns(lo, nxt); AddTrns(hi, nxt); return; } } AddTrns(chr, nxt); }
public void SetState(NPCState s, bool instant = false) { if (State != null && State.State == s) { return; } if (!States.ContainsKey(s)) { Debug.Log("ATTEMPTED TO USE INVALID STATE: " + s); return; } if (State != null) { State.OnEnd(this); } State = States[s]; State.OnStart(this, instant); }
//获取新闻、公告状态信息 by nstateid public NState GetNStateById(int nstateid) { //sql连接字符串 string sql = "select * from NState where NStateId=@nstateid"; //参数赋值 SqlParameter[] para = new SqlParameter[] { new SqlParameter("@nstateid", nstateid), }; //执行sql SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, sql, para); NState nstate = null; if (reader.Read()) { nstate = new NState(); nstate.NStateId = (int)reader["NStateId"]; nstate.NStateName = (string)reader["NStateName"]; } return(nstate); }
internal void SetNext(int sym, NState dstState) { ulong key = checked (((ulong)this.serialNumber << 32) + (ulong)sym); myNfsa.next.Add(key, dstState); }
/// <summary> /// Build the NFSA from the abstract syntax tree. /// There is an NfsaInstance for each start state. /// Each rule starts with a new nfsa state, which /// is the target of a new epsilon transition from /// the real start state, nInst.Entry. /// </summary> /// <param name="ast"></param> public void Build(AAST ast) { int index = 0; DateTime time0 = DateTime.Now; nfas = new NfsaInstance[ast.StartStateCount]; foreach (KeyValuePair <string, StartState> p in ast.startStates) { StartState s = p.Value; string name = p.Key; if (!s.IsAll) { NfsaInstance nInst = new NfsaInstance(s, this); nfas[index++] = nInst; nInst.key = name; // for each pattern do ... for (int i = 0; i < s.rules.Count; i++) { RuleDesc rule = s.rules[i]; RegExTree tree = rule.Tree; // This test constructs the disjoint automata // that test code points for predicate evaluation. if (rule.isPredDummyRule) { NState entry = nInst.Entry; nInst.MakePath(tree, entry, entry); } else { NState start = nInst.MkState(); NState endSt = nInst.MkState(); if (tree.op == RegOp.leftAnchor) // this is a left anchored pattern { nInst.AnchorState.AddEpsTrns(start); tree = ((Unary)tree).kid; } else // this is not a left anchored pattern { nInst.Entry.AddEpsTrns(start); } // // Now check for right anchors, and add states as necessary. // if (tree.op == RegOp.eof) { // // <<EOF>> rules are always emitted outside // of the usual subset construction framework. // We ensure that we do not get spurious warnings. // rule.useCount = 1; nInst.eofAction = rule.aSpan; nInst.MakePath(tree, start, endSt); nInst.MarkAccept(endSt, rule); } else if (tree.op == RegOp.rightAnchor) { tree = ((Unary)tree).kid; nInst.MakePath(tree, start, endSt); AddAnchorContext(nInst, endSt, rule); } else { nInst.MakePath(tree, start, endSt); nInst.MarkAccept(endSt, rule); } } } } } if (task.Verbose) { Console.Write("GPLEX: NFSA built"); Console.Write((task.Errors ? ", errors detected" : " without error")); Console.Write((task.Warnings ? "; warnings issued. " : ". ")); Console.WriteLine(TaskState.ElapsedTime(time0)); } if (task.Summary) { WriteSummary(time0); } }
/// <summary> /// Create a transition path in the NFSA from the given /// start state to the given end state, corresponding to the /// RegEx tree value. The method may (almost always does) /// create new NFSA states and recurses to make paths for /// the subtrees of the given tree. /// </summary> /// <param name="tree">The tree to encode</param> /// <param name="start">The start state for the pattern</param> /// <param name="end">The end state for the pattern</param> internal void MakePath(RegExTree tree, NState startState, NState endState) { NState tmp1 = null; switch (tree.op) { case RegOp.eof: break; // Binary nodes =================================== case RegOp.context: case RegOp.concat: case RegOp.alt: // Binary nodes =================================== Binary binNode = tree as Binary; switch (tree.op) { case RegOp.context: int rLen = binNode.rKid.contextLength(); int lLen = binNode.lKid.contextLength(); if (rLen <= 0 && lLen <= 0) { throw new StringInterpretException("variable right context '/' not implemented"); } else { endState.rhCntx = rLen; endState.lhCntx = lLen; tmp1 = MkState(); MakePath(binNode.lKid, startState, tmp1); MakePath(binNode.rKid, tmp1, endState); } break; case RegOp.concat: tmp1 = MkState(); MakePath(binNode.lKid, startState, tmp1); MakePath(binNode.rKid, tmp1, endState); break; case RegOp.alt: tmp1 = MkState(); MakePath(binNode.lKid, startState, tmp1); tmp1.AddEpsTrns(endState); tmp1 = MkState(); MakePath(binNode.rKid, startState, tmp1); tmp1.AddEpsTrns(endState); break; } break; // Unary nodes =================================== case RegOp.closure: case RegOp.finiteRep: // Unary nodes =================================== Unary unaryNode = tree as Unary; switch (tree.op) { case RegOp.closure: NState tmp2 = MkState(); if (unaryNode.minRep == 0) { tmp1 = MkState(); startState.AddEpsTrns(tmp1); } else { NState dummy = startState; for (int i = 0; i < unaryNode.minRep; i++) { tmp1 = MkState(); MakePath(unaryNode.kid, dummy, tmp1); dummy = tmp1; } } MakePath(unaryNode.kid, tmp1, tmp2); tmp2.AddEpsTrns(tmp1); tmp1.AddEpsTrns(endState); break; case RegOp.finiteRep: { NState dummy = tmp1 = startState; for (int i = 0; i < unaryNode.minRep; i++) { tmp1 = MkState(); MakePath(unaryNode.kid, dummy, tmp1); dummy = tmp1; } tmp1.AddEpsTrns(endState); for (int i = unaryNode.minRep; i < unaryNode.maxRep; i++) { tmp1 = MkState(); MakePath(unaryNode.kid, dummy, tmp1); dummy = tmp1; dummy.AddEpsTrns(endState); } } break; } break; // Leaf nodes =================================== case RegOp.litStr: case RegOp.primitive: case RegOp.charClass: // Leaf nodes =================================== Leaf leafNode = tree as Leaf; switch (tree.op) { case RegOp.litStr: { // Make a linear sequence of states with successive // transitions on successive string characters. // string text = leafNode.str; NState dummy = startState; // Need to deal with special case of empty string if (text.Length == 0) { dummy.AddEpsTrns(endState); } else { // This code is complicated by the fact that unicode // escape substitution may have inserted surrogate // pairs of characters in the string. We need // one transition for every unicode codepoint, // not one for every char value in this string. // int index = 0; int code = CharacterUtilities.CodePoint(text, ref index); // First character int next = CharacterUtilities.CodePoint(text, ref index); // Next, possibly -1 while (next >= 0) { tmp1 = MkState(); dummy.AddChrTrns(code, tmp1); dummy = tmp1; code = next; next = CharacterUtilities.CodePoint(text, ref index); } // Postcondition ==> "code" is the last char. dummy.AddChrTrns(code, endState); } } break; case RegOp.primitive: startState.AddChrTrns(leafNode.chVal, endState); break; case RegOp.charClass: startState.AddClsTrans(leafNode, endState); break; } break; default: throw new GplexInternalException("unknown tree op"); } }
internal void MarkAccept(NState acpt, RuleDesc rule) { acpt.accept = rule; acceptStates.Add(acpt.ord); }
public Cursor(GState g, STable klass, RxFrame feedback, NState ns, Choice xact, int pos, CapInfo captures) { this.mo = this.save_klass = klass; this.xact = xact; this.nstate = ns; this.feedback = feedback; this.global = g; this.pos = pos; this.captures = captures; }
public NState(NState f) { next = f.next; name = f.name; cut_to = f.cut_to; quant = f.quant; klass = f.klass; }
public void AddState(NState s) { States.Add(s.State, s); }
internal void SetNext(int sym, NState dstState) { uint key = (this.serialNumber << 16) + (ushort)sym; myNfsa.next.Add(key, dstState); }
public NState(Choice cut_to, string name, NState proto) { next = proto; this.cut_to = cut_to; this.name = name; if (proto != null) klass = proto.klass; }
public Cursor(GState g, DynMetaObject klass, NState ns, Choice xact, int pos, CapInfo captures) { this.mo = klass; this.xact = xact; this.nstate = ns; this.global = g; this.pos = pos; this.captures = captures; }