private void GetString(DFA <int, LexicalFunction> dfa) { int endIndex = dfa.CurrentToken; Lexical lexical = (Lexical)dfa; lexical.OutputToken.Row = lexical.Row; lexical.OutputToken.Col = lexical.beginIndex - lexical.LastLineStart; lexical.OutputToken.Text = lexical.InputText.Substring(lexical.beginIndex + 1, endIndex - lexical.beginIndex - 2); if (lexical.DoubleQuotationCount > 0) { lexical.OutputToken.Text = lexical.OutputToken.Text.Replace("''", "'"); lexical.DoubleQuotationCount = 0; } lexical.beginIndex = endIndex; }
private void GetText(DFA <int, LexicalFunction> dfa) { int endIndex = dfa.CurrentToken; Lexical lexical = (Lexical)dfa; lexical.OutputToken.Row = lexical.Row; lexical.OutputToken.Col = lexical.beginIndex - lexical.LastLineStart; if (endIndex == lexical.InputText.Length) { lexical.OutputToken.Text = lexical.InputText.Substring(lexical.beginIndex, endIndex - lexical.beginIndex); } else { lexical.OutputToken.Text = lexical.InputText.Substring(lexical.beginIndex, endIndex - lexical.beginIndex + 1); } lexical.beginIndex = endIndex + 1; }
public override void DoThings(int action, DFA <int, LexicalFunction> dfa) { Lexical lexical = (Lexical)dfa; switch (Func) { case LexicalFunction.OutputIdentifier: lexical.OutputToken = new Lexical.Token(); GetTextElse(dfa); if (!Lexical.KeywordsTbl.TryGetValue(lexical.OutputToken.Text.ToUpper(), out lexical.OutputToken.SyntaxType)) { lexical.OutputToken.SyntaxType = SyntaxType.Identifer; } break; case LexicalFunction.DoSpace: DoSpace(action, dfa); break; case LexicalFunction.OutputSpace: lexical.OutputToken = new Lexical.Token(); GetTextElse(dfa); lexical.OutputToken.SyntaxType = SyntaxType.Space; break; case LexicalFunction.OutputNumeric: lexical.OutputToken = new Lexical.Token(); GetTextElse(dfa); lexical.OutputToken.SyntaxType = SyntaxType.Numeric; break; case LexicalFunction.OutputComment: lexical.OutputToken = new Lexical.Token(); GetText(dfa); if (lexical.OutputToken.Text[0] == '-') { lexical.Row++; lexical.LastLineStart = lexical.CurrentToken + 1; } lexical.OutputToken.SyntaxType = SyntaxType.Comment; break; case LexicalFunction.OutputArithmeticOpr: lexical.OutputToken = new Lexical.Token(); GetTextElse(dfa); lexical.OutputToken.SyntaxType = Lexical.ArithmeticTbl[lexical.OutputToken.Text]; break; case LexicalFunction.DoubleQuotation: lexical.DoubleQuotationCount++; break; case LexicalFunction.OutputString: lexical.OutputToken = new Lexical.Token(); GetString(dfa); lexical.OutputToken.SyntaxType = SyntaxType.String; break; case LexicalFunction.OutputComparisonOpr: lexical.OutputToken = new Lexical.Token(); GetTextElse(dfa); lexical.OutputToken.SyntaxType = Lexical.ComparisonOprTbl[lexical.OutputToken.Text]; break; case LexicalFunction.OutputBracketSymbol: lexical.OutputToken = new Lexical.Token(); GetText(dfa); lexical.OutputToken.SyntaxType = Lexical.BracketSymbolTbl[lexical.OutputToken.Text]; break; } }