Tark_Wight

Untitled

Mar 16th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4.  
  5. namespace ConsoleApp1
  6. {
  7. internal class Program
  8. {
  9. static void Main()
  10. {
  11. string operators = $@"\s*[-+/*]\s*";
  12. string num = @"([1-9]\d*|0)";
  13. string name = @"[a-z]\w*";
  14. string simpleOperation = $@"({num}|{name})({operators}({num}|{name}))+";
  15. string function = $@"{name}\s*\(\s*({num}|{name}|{simpleOperation})(\s*,\s*({num}|{name}|{simpleOperation}))*\s*\)";
  16. string arr = $@"{name}\[\s*({name}|{num}|{simpleOperation}|{function})\s*\]";
  17. string operation = $@"({num}|{name}|{arr})({operators}({num}|{name}|{arr}|{function}))+";
  18. string assign = $@"({name}|{arr})\s*=\s*({num}|{name}|{arr}|{operation}|{function})\s*;";
  19. //Console.WriteLine(assign);
  20.  
  21. string input = Console.ReadLine();
  22.  
  23. Regex reg = new Regex(assign);
  24.  
  25. while (input != null)
  26. {
  27. MatchCollection matches = reg.Matches(input);
  28.  
  29. for (int count = 0; count < matches.Count; count++)
  30. {
  31. Console.WriteLine(matches[count].Value);
  32. }
  33.  
  34. input = Console.ReadLine();
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment