using System.Collections.Generic;
using System.Text.RegularExpressions;
static Queue<String> queue = new Queue<String>();
static String[] possibleTokens
= new String[] {"function", "I", "(", ")", ";", ":=", "*", "+", "end"} ;
static void validateNext(String correct, int n = 1) {
for (int i = 0; i < n; ++i)
if (!temp.Equals(correct, StringComparison.OrdinalIgnoreCase))
throw new Exception("Валидация не пройдена: " + correct + " " + n);
static void validate_F() {
validateNext("functionI(I)", 5);
static void validate_S() {
if (queue.Peek().Equals("ε")) {
static void validate_E() {
String token = queue.Peek();
if (prevToken.Equals("I")) {
if (Regex.IsMatch(token, "[*+]{1}"))
throw new Exception("Валидация не пройдена: validate_E!");
public static string readFromConsole() {
Console.WriteLine("Введите программу с клавиатуры\nДля завершения ввода введите пустую строку");
string x = Console.ReadLine();
StringBuilder sb = new StringBuilder();
Console.WriteLine("Программа успешно считана!");
public static string[] detectLexems(string target) {
target = target.Replace(" ", "");
.ForEach(x => target = target.Replace(x, String.Format("${0}$", x)));
.Where(x => x.Length > 0 && !x.Equals(" "))
public static void Main()
String input = readFromConsole();
foreach (String item in detectLexems(input))
Console.WriteLine("Производится анализ...");
Console.WriteLine("Цепочка выводима!");
Console.WriteLine("Цепочка НЕ выводима!");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);