allia

4 операторы доделать тест 2

Feb 15th, 2021 (edited)
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Text;  
  3. using System.Text.RegularExpressions;
  4.  
  5. class MainClass
  6. {
  7.    public static void Main (string[] args)
  8.   {
  9.     string chislo = @"([1-9]\d*|[0])";
  10.     string znach = @"[a-z0-9]";
  11.  
  12.     string correct_var = $@"([a-z]{znach}*|{chislo})";
  13.     string in_mas = $@"(\s*{correct_var}\s*[-+*/])";
  14.     string arifmetic_in_mas = $@"({in_mas}*\s*{correct_var}\s*)";
  15.  
  16.     string massiv = $@"[a-z]{znach}*(\[({correct_var}|{arifmetic_in_mas})\])";
  17.    
  18.     string fun = $@"[a-z]{znach}*(\(({correct_var}|{arifmetic_in_mas})\))";
  19.  
  20.     string arifmetic_var = $"({correct_var}|{massiv}|{fun})";
  21.     string pattern_arifmetic = $@"(\s*{arifmetic_var}\s*[-+*/])";
  22.     string long_pattern_arifmetic = $@"(({pattern_arifmetic}*)\s*{arifmetic_var})";
  23.    
  24.     string pattern = $@"([a-z]{znach}*|{massiv}|{fun})\s*=\s*({long_pattern_arifmetic}|{massiv}|{fun}|{chislo})\s*;";
  25.     string str;
  26.  
  27.     while((str = Console.ReadLine())!= null)
  28.       foreach (Match match in Regex.Matches(str, pattern))
  29.          Console.WriteLine(match.Value);
  30.   }
  31. }
  32.  
Add Comment
Please, Sign In to add comment