public void SetNextLexemTypeToTreater() { SetNextWordToTreater(); switch (currentWord) { case "begin": currentLexemType = LexemsType.Begin; return; case "end": currentLexemType = LexemsType.End; return; case "if": currentLexemType = LexemsType.If; return; case "do": currentLexemType = LexemsType.Do; return; case "while": currentLexemType = LexemsType.While; return; default: if (currentWord.Length > 1) { currentLexemType = LexemsType.SimpleWord; return; } else { currentLexemType = LexemsType.SyntaxLexem; return; } } }
public void SetNextLexemTypeToTreater() { SetNextWordToTreater(); switch (currentWord) { case "begin": currentLexemType = LexemsType.Begin; break; case "end": currentLexemType = LexemsType.End; break; case "if": currentLexemType = LexemsType.If; break; case "do": currentLexemType = LexemsType.Do; break; case "while": currentLexemType = LexemsType.While; break; case "iden": currentLexemType = LexemsType.Iden; break; case "numb": currentLexemType = LexemsType.Number; break; default: if (IsWord(currentWord)) { currentLexemType = LexemsType.SimpleWord; break; } else { currentLexemType = LexemsType.SyntaxLexem; break; } } }
public static void Main(string[] args) { string pathToResourceFile = "..\\..\\resources\\resource.db"; string pathToResultFile = "..\\..\\result.db"; InstructionsTreatment treater = new InstructionsTreatment(pathToResourceFile); ResultsWriter writer = new ResultsWriter(pathToResultFile); while (true) { treater.SetNextLexemTypeToTreater(); LexemsType type = treater.CurrentLexem; string word = treater.CurrentWord; writer.WriteResultToFile(type, word); if (word.Trim() == "@") { break; } } treater.Finish(); writer.Finish(); }
public void WriteResultToFile(LexemsType type, string word) { fileWriter.WriteLine(type.ToString() + " - " + word); }
private void SetNextLexem() { treater.SetNextLexemTypeToTreater(); currentLexemType = treater.CurrentLexem; currentWord = treater.CurrentWord; }