private SuperLinkedList <WordInfo> GetInitSegment(string text) { SuperLinkedList <WordInfo> result = new SuperLinkedList <WordInfo>(); Framework.Lexical lexical = new PanGu.Framework.Lexical(text); DFAResult dfaResult; for (int i = 0; i < text.Length; i++) { char c = text[i]; dfaResult = lexical.Input(c, i); switch (dfaResult) { case DFAResult.Continue: continue; case DFAResult.Quit: result.AddLast(lexical.OutputToken); break; case DFAResult.ElseQuit: result.AddLast(lexical.OutputToken); if (lexical.OldState != 255) { i--; } break; } } dfaResult = lexical.Input(0, text.Length); switch (dfaResult) { case DFAResult.Continue: break; case DFAResult.Quit: result.AddLast(lexical.OutputToken); break; case DFAResult.ElseQuit: result.AddLast(lexical.OutputToken); break; } return(result); }
public override void DoThings(int action, DFA <int, LexicalFunction> dfa) { Lexical lexical = (Lexical)dfa; switch (Func) { case LexicalFunction.OutputIdentifier: lexical.OutputToken = new WordInfo(); GetTextElse(dfa); lexical.OutputToken.WordType = WordType.English; break; case LexicalFunction.OutputSpace: lexical.OutputToken = new WordInfo(); GetTextElse(dfa); lexical.OutputToken.WordType = WordType.Space; break; case LexicalFunction.OutputEndOfLine: lexical.OutputToken = new WordInfo(); GetTextElse(dfa); lexical.OutputToken.WordType = WordType.EndOfLine; break; case LexicalFunction.OutputNumeric: lexical.OutputToken = new WordInfo(); GetTextElse(dfa); lexical.OutputToken.WordType = WordType.Numeric; break; case LexicalFunction.OutputChinese: lexical.OutputToken = new WordInfo(); GetTextElse(dfa); lexical.OutputToken.WordType = WordType.SimplifiedChinese; break; case LexicalFunction.Other: lexical.OutputToken = new WordInfo(); GetText(dfa); lexical.OutputToken.WordType = WordType.Symbol; break; } }
private void GetText(DFA <int, LexicalFunction> dfa) { int endIndex = dfa.CurrentToken; Lexical lexical = (Lexical)dfa; if (endIndex == lexical.InputText.Length) { lexical.OutputToken.Position = lexical.beginIndex; lexical.OutputToken.Word = lexical.InputText.Substring(lexical.beginIndex, endIndex - lexical.beginIndex); } else { lexical.OutputToken.Position = lexical.beginIndex; lexical.OutputToken.Word = lexical.InputText.Substring(lexical.beginIndex, endIndex - lexical.beginIndex + 1); } lexical.beginIndex = endIndex + 1; }
private SuperLinkedList<WordInfo> GetInitSegment(string text) { SuperLinkedList<WordInfo> result = new SuperLinkedList<WordInfo>(); Framework.Lexical lexical = new PanGu.Framework.Lexical(text); DFAResult dfaResult; for (int i = 0; i < text.Length; i++) { char c = text[i]; dfaResult = lexical.Input(c, i); switch (dfaResult) { case DFAResult.Continue: continue; case DFAResult.Quit: result.AddLast(lexical.OutputToken); break; case DFAResult.ElseQuit: result.AddLast(lexical.OutputToken); if (lexical.OldState != 255) { i--; } break; } } dfaResult = lexical.Input(0, text.Length); switch (dfaResult) { case DFAResult.Continue: break; case DFAResult.Quit: result.AddLast(lexical.OutputToken); break; case DFAResult.ElseQuit: result.AddLast(lexical.OutputToken); break; } return result; }