Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- List<string> rows = new List<string>();
- while (true)
- {
- string row = Console.ReadLine();
- rows.Add(row);
- if (row.StartsWith("?>"))
- {
- break;
- }
- }
- bool inNormalBrackets2 = false;
- bool inNormalBrackets = false;
- bool inComment = false; /* global */
- bool inDoubleQuotes = false; //
- bool inSingleQuotes = false;
- bool inBrackets = false;
- bool isVariable = false; //
- StringBuilder sb = new StringBuilder();
- List<string> variables = new List<string>();
- for (int i = 0; i < rows.Count; i++)
- {
- List<string> buffer = new List<string>();
- string nextRow;
- nextRow = rows[i];
- char nextChar;
- for (int pos = 0; pos < nextRow.Length; pos++)
- {
- nextChar = nextRow[pos];
- string test = nextChar.ToString();
- if (nextChar == ';')
- {
- foreach (var item in buffer)
- {
- if (!variables.Contains(item))
- {
- variables.Add(item);
- }
- }
- }
- if (isVariable == true)
- {
- if (sb.Length == 0)
- {
- if (Regex.Matches(test,"[a-zA-Z_]+").Count > 0)
- {
- }
- else
- {
- isVariable = false;
- continue;
- }
- }
- if (Regex.Matches(test,"\\w+").Count == 0)
- {
- if (sb.Length > 0)
- {
- if (!buffer.Contains(sb.ToString()))
- {
- buffer.Add(sb.ToString());
- }
- sb.Clear();
- }
- isVariable = false;
- }
- else
- {
- sb.Append(nextChar);
- }
- }
- if (nextChar == '#' && inSingleQuotes == false && inDoubleQuotes == false)
- {
- break;
- }
- if (nextChar == '\\') //in test
- {
- pos++;
- continue;
- }
- if (nextChar == '/' && inSingleQuotes == false && inDoubleQuotes == false )
- {
- if (pos < nextRow.Length - 1)
- {
- if (nextRow[pos + 1] == '/') // comment to the end
- {
- break;
- }
- else if (nextRow[pos + 1] == '*') /* */
- {
- inComment = true;
- pos++;
- }
- }
- }
- if (nextChar == '\'') // inSingleQuote
- {
- if (inSingleQuotes == true)
- {
- inSingleQuotes = false;
- }
- else
- {
- inSingleQuotes = true;
- }
- }
- if (nextChar == '{')
- {
- inBrackets = true;
- }
- if (nextChar == '}')
- {
- inBrackets = false;
- }
- if (nextChar == '[')
- {
- inNormalBrackets = true;
- }
- if (nextChar == ']')
- {
- inNormalBrackets = true;
- }
- if (nextChar == '(')
- {
- inNormalBrackets2 = true;
- }
- if (nextChar == ')')
- {
- inNormalBrackets2 = false;
- }
- if (nextChar == '"') //inDoubleQuote
- {
- if (inDoubleQuotes == true)
- {
- inDoubleQuotes = false;
- }
- else
- {
- inDoubleQuotes = true;
- }
- }
- if (nextChar == '*' && inSingleQuotes == false && inDoubleQuotes == false)
- {
- if (pos < nextRow.Length - 1)
- {
- if (nextRow[pos + 1] == '/') // end of comment
- {
- inComment = false;
- pos++;
- }
- }
- }
- if (nextChar == '$' && inComment == false)
- {
- if (inSingleQuotes == false)
- {
- isVariable = true;
- }
- else if (inSingleQuotes == true && inBrackets == true)
- {
- isVariable = true;
- }
- else if (inSingleQuotes == true && inNormalBrackets == true)
- {
- isVariable = true;
- }
- else if (inSingleQuotes == true && inNormalBrackets2 == true)
- {
- isVariable = true;
- }
- }
- }
- }
- Console.WriteLine(variables.Count);
- variables.Sort();
- foreach (var item in variables)
- {
- Console.WriteLine(item);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement