Advertisement
MagnusArias

LM | Zad 5

Jun 4th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Zad_5
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string pattern = @"^([-+]?[\(]?[0-9]*\.?[0-9]+[\)]?[-+*^/])+([-+]?[\(]?[0-9]*\.?[0-9]+[\)]?)$";
  11.             /* GRAMATYKA
  12.              * S ::= -A | A
  13.              * A ::= B | (B)
  14.              * B ::= C Z A
  15.              * C ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  16.              * Z ::= + | - | * | / | ^
  17.              */
  18.             while(true)
  19.             {
  20.                 Console.ForegroundColor = ConsoleColor.Gray;
  21.                 Console.WriteLine("\nPodaj wyrazenie do sprawdzenia (\"end\" konczy dzialanie): ");
  22.                 string str = Console.ReadLine();
  23.                 if (str == "end") break;
  24.  
  25.                 Match match = new Regex(pattern).Match(str);
  26.                
  27.                 if (match.Success) Console.ForegroundColor = ConsoleColor.Green;
  28.                 else Console.ForegroundColor = ConsoleColor.Red;
  29.                 Console.WriteLine(str);
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement