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.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; }