Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace ConsoleApp1
- {
- internal class Program
- {
- static void Main()
- {
- string operators = $@"\s*[-+/*]\s*";
- string num = @"([1-9]\d*|0)";
- string name = @"[a-z]\w*";
- string simpleOperation = $@"({num}|{name})({operators}({num}|{name}))+";
- string function = $@"{name}\s*\(\s*({num}|{name}|{simpleOperation})(\s*,\s*({num}|{name}|{simpleOperation}))*\s*\)";
- string arr = $@"{name}\[\s*({name}|{num}|{simpleOperation}|{function})\s*\]";
- string operation = $@"({num}|{name}|{arr})({operators}({num}|{name}|{arr}|{function}))+";
- string assign = $@"({name}|{arr})\s*=\s*({num}|{name}|{arr}|{operation}|{function})\s*;";
- //Console.WriteLine(assign);
- string input = Console.ReadLine();
- Regex reg = new Regex(assign);
- while (input != null)
- {
- MatchCollection matches = reg.Matches(input);
- for (int count = 0; count < matches.Count; count++)
- {
- Console.WriteLine(matches[count].Value);
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment