Advertisement
d_brezoev

pv

Dec 28th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace PHPVariables
  10. {
  11.     class PHPVariables
  12.     {        
  13.         static void Main(string[] args)
  14.         {
  15.             HashSet<string> variables = new HashSet<string>();                        
  16.             StringBuilder line = new StringBuilder(Console.ReadLine());
  17.             string commentPattern = @"([/]{1}[*]{1}.*[*]{1}[/]{1})|([/][/].*)|([#]{1}.*)|(?<multiLineComment>([/]{1}[*]{1}.*))";
  18.             string varPattern = @"([^\\]|[\\]{2})[$]{1}(?<var>[A-Za-z0-9_]+)";
  19.             bool multiLineComment = false;
  20.             while (line.ToString()!="?>")
  21.             {
  22.                 line.Insert(0, ' ');
  23.                 if (multiLineComment)
  24.                 {
  25.                     if (line[line.Length-1]=='/' && line[line.Length-2] == '*')
  26.                     {
  27.                         multiLineComment = false;
  28.                     }
  29.                     line = new StringBuilder(" ");
  30.                 }
  31.                 Match match = Regex.Match(line.ToString(), commentPattern);
  32.                 while (match.Success)
  33.                 {
  34.                     if (match.Groups["multiLineComment"].Success)
  35.                     {
  36.                         multiLineComment = true;
  37.                     }
  38.                     line.Replace(match.ToString(), "");
  39.                     match = match.NextMatch();
  40.                 }
  41.                 Match m = Regex.Match(line.ToString(), varPattern);
  42.                 while (m.Success)
  43.                 {
  44.                     variables.Add(m.Groups["var"].ToString());
  45.                     m = m.NextMatch();
  46.                 }
  47.                 line = new StringBuilder(Console.ReadLine());
  48.             }
  49.             List<string> list = new List<string>();
  50.             Console.WriteLine(variables.Count);
  51.             foreach (var item in variables)
  52.             {
  53.                 list.Add(item);
  54.             }
  55.             string[] arr = list.ToArray();
  56.             Array.Sort(arr);
  57.             for (int i = 0; i < arr.Length; i++)
  58.             {
  59.                 Console.WriteLine(arr[i]);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement