Exemple #1
0
        public static void Visual(Regex re, string path)
        {
            path = path.Replace('/', '\\');

            var sb = new StringBuilder();
            var set = new HashSet<string>();
            sb.Append("digraph {\n    rankdir = \"LR\";\n    shape=\"circle\";\n");
            sb.Append($"    {re.End} [shape=\"doublecircle\"];\n");
            Draw(re.Start, sb, set);
            sb.Append("}");
            if (!Directory.Exists("Temp")) {
                Directory.CreateDirectory("Temp");
            }
            var dotFilePath = $"Temp\\{Path.GetFileNameWithoutExtension(path)}.dot";
            File.WriteAllText(dotFilePath, sb.ToString());

            var process = new Process();
            var startInfo = new ProcessStartInfo {
                WindowStyle = ProcessWindowStyle.Hidden,
                FileName = "..\\..\\tools\\Graphviz\\dot.exe",
                Arguments = $"-Tpng {dotFilePath} -o {path}"
            };
            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();
        }
Exemple #2
0
 private void HandleAlt(Token token)
 {
     var n2 = _regexStack.Pop();
     var n1 = _regexStack.Pop();
     var s0 = new RegexState();
     s0.Epsilon.Add(n1.Start);
     s0.Epsilon.Add(n2.Start);
     var s3 = new RegexState();
     n1.End.Epsilon.Add(s3);
     n2.End.Epsilon.Add(s3);
     n1.End.IsFinalStates = false;
     n2.End.IsFinalStates = false;
     var regex = new Regex(s0, s3);
     _regexStack.Push(regex);
 }
Exemple #3
0
 private void HandleConcat(Token token)
 {
     var n2 = _regexStack.Pop();
     var n1 = _regexStack.Pop();
     n1.End.IsFinalStates = false;
     n1.End.Epsilon.Add(n2.Start);
     var regex = new Regex(n1.Start, n2.End);
     _regexStack.Push(regex);
 }
Exemple #4
0
 private void HandleChar(Token token)
 {
     var s0 = new RegexState();
     var s1 = new RegexState();
     s0.Transitions.Add(token.Text.First(), s1);
     var regex = new Regex(s0, s1);
     _regexStack.Push(regex);
 }
Exemple #5
0
 private void HandleRepeat(Token token)
 {
     var s0 = _regexStack.Pop();
     var s1 = new RegexState();
     var s2 = new RegexState();
     s1.Epsilon.Add(s0.Start);
     if (token.Text == "*") {
         s1.Epsilon.Add(s2);
     }
     s0.End.Epsilon.Add(s2);
     s0.End.Epsilon.Add(s0.Start);
     s0.End.IsFinalStates = false;
     var regex = new Regex(s1, s2);
     _regexStack.Push(regex);
 }