Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace Zad_5
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pattern = @"^([-+]?[\(]?[0-9]*\.?[0-9]+[\)]?[-+*^/])+([-+]?[\(]?[0-9]*\.?[0-9]+[\)]?)$";
- /* GRAMATYKA
- * S ::= -A | A
- * A ::= B | (B)
- * B ::= C Z A
- * C ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
- * Z ::= + | - | * | / | ^
- */
- while(true)
- {
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("\nPodaj wyrazenie do sprawdzenia (\"end\" konczy dzialanie): ");
- string str = Console.ReadLine();
- if (str == "end") break;
- Match match = new Regex(pattern).Match(str);
- if (match.Success) Console.ForegroundColor = ConsoleColor.Green;
- else Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(str);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement