private void TestKeyword(int readed, string text) { if (readed == 0) { handler.Fail(FMSG.F1); return; } else if (typeMap.Contains(text)) { // ParseType(text); current = new Token(text, TokenType.type, line, row); goto ex2; } IEnumeratorPair <string, TokenType> e1 = ids; while (e1.MoveNext()) { if (e1.Item1 == text) { current = new Token(text, e1.Item2, line, row); goto exit; } } current = new Token(text, TokenType.id, line, row); exit: e1.Reset(); ex2: row += readed; }
public void Reset() { sr.BaseStream.Seek(0, SeekOrigin.Begin); sys.Reset(); current = null; }
private unsafe int LexSymbol(char read, out string temp, out TokenType type) { // step 1. 한 문자 읽기 // step 2. StartsWith이 일치하는 모든 심볼 찾기 // step 3-true. 단 1개의 심볼만 일치하는 경우 반환 // step 3-false. 실패 CStreamReader sr = this.sr; char *ptr = stackalloc char[4]; // 최대 4개의 심볼을 인식한다 ptr[0] = read; IEnumeratorPair <string, TokenType> e1 = sys; string key = null; TokenType tt = 0; int ptrcnt = 1; bool found = false; loop: int swcnt = 0; while (e1.MoveNext()) { if (e1.Item1.StartsWith(ptr, ptrcnt)) { swcnt++; if (FnCHAR.Equals(ptr, ptrcnt, e1.Item1)) { found = true; key = e1.Item1; tt = e1.Item2; } } } e1.Reset(); if (swcnt == 0 && !found) { handler.Fail(FMSG.L_C2); temp = null; type = 0; return(-1); } else if (swcnt > 1) { ptr[ptrcnt] = (char)sr.Peek(ptrcnt - 1); ptrcnt++; goto loop; } else if (swcnt == 1 && ptrcnt > 1) { sr.Move(ptrcnt - 1); } temp = key; type = tt; return(key.Length); }