/// <summary> /// 根据状态转移函数获取结果信息 /// </summary> /// <param name="statue">当前状态</param> /// <param name="read">读取字符</param> /// <param name="write">写入字符</param> /// <param name="direction">转移方向</param> /// <param name="nextstatue">下一个状态</param> /// <returns></returns> public int GetJmpInfo(int statue, char read, ref char write, ref int direction, ref int nextstatue) { if (statue < 0 || statue > length) { return(-1); } JmpTab jmp = jmpTabs[statue]; while (jmp.next != null) { if (jmp.read == read) { write = jmp.write; direction = jmp.direction; nextstatue = jmp.statue; return(0); } jmp = jmp.next; } return(-1); }
/// <summary> /// 构建跳转函数表 /// </summary> /// <param name="str"></param> /// <returns></returns> private int BuildJmpTab() { jmpTabs = new JmpTab[length]; for (int i = 0; i < length; i++) { jmpTabs[i] = new JmpTab(); } for (int i = 0; i < Jmpfuncs.Length; i += 6) { int x = GetOrder(Jmpfuncs[i + 1]); if (x < 0 || x > length) { return(-1); } JmpTab jmp = jmpTabs[x]; while (jmp.next != null) { jmp = jmp.next; } jmp.read = Jmpfuncs[i + 2][0]; jmp.write = Jmpfuncs[i + 4][0]; if (Jmpfuncs[i + 5][0] == 'l' || Jmpfuncs[i + 5][0] == 'L') { jmp.direction = -1; } else if (Jmpfuncs[i + 5][0] == 'r' || Jmpfuncs[i + 5][0] == 'R') { jmp.direction = 1; } else { jmp.direction = 0; } jmp.statue = GetOrder(Jmpfuncs[i + 3]); jmp.next = new JmpTab(); } return(0); }
public JmpTab() { next = null; }