regex ir opt is almost done

This commit is contained in:
Youmu Liu
2026-06-30 20:14:30 +08:00
parent e60eb0ada6
commit 1cd0257c93
12 changed files with 552 additions and 377 deletions
+9 -3
View File
@@ -40,6 +40,7 @@ namespace StgSharp
{
private static string[] regexSource = [
@"http|https|ftp|ftps",
@"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz",
@"get_name|get_value|get_type|set_name|set_value|set_type",
@@ -51,8 +52,8 @@ namespace StgSharp
{
foreach (string regex in regexSource)
{
RegexAnalyzer interpreter = RegexAnalyzer.Analyze(regex);
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree = interpreter.Tree;
TextRegexSource interpreterSource = RegexAnalyzer.Analyze(regex);
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree = interpreterSource.Ast;
Console.WriteLine($"result of \"{regex}\"");
TreeEnumerator<RegexAstNode, RegexElementLabel> enumerator = new(tree);
while (enumerator.MoveNext())
@@ -61,11 +62,16 @@ namespace StgSharp
Console.Write(new string('|', enumerator.Depth));
Console.WriteLine($"\t{node.Source.Value}\t{node.Source.Flag}");
}
List<RegexIR> ir = RegexAnalyzer.GenerateIR(tree);
Console.WriteLine("-----IR-----");
List<RegexIR> ir = interpreterSource.BaseIR;
for (int i = 0; i < ir.Count; i++) {
Console.WriteLine(ir[i].AsCommand(i));
}
Console.WriteLine("-----Optimized once-----");
List<RegexIR> opt_ir = interpreterSource.IRs;
for (int i = 0; i < opt_ir.Count; i++) {
Console.WriteLine(opt_ir[i].AsCommand(i));
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();