-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (55 loc) · 1.87 KB
/
Copy pathProgram.cs
File metadata and controls
65 lines (55 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.IO;
namespace LLex
{
class Program
{
static void TestCompiler()
{
foreach (var regex in new[]
{
@"<(\?(php)?)|%",
@"<(\?|%)=",
@"(<>)|(!=)",
@"\?|:",
//@"\r|\n|\t|\v|\s",
@"(\?|%)>",
})
{
var regexLexer = new RegexLexer(regex);
var tokens = regexLexer.GetTokens();
var parser = new RegexParser(tokens.ToArray());
var ast = parser.Parse();
var compiler = new RegexCompiler(ast);
var strings = compiler.ExpandRegex();
Console.WriteLine("Regex:\r\n {0}\r\nExpanded:", regex);
foreach (var s in strings)
{
Console.WriteLine(" {0}", s);
}
Console.WriteLine();
}
}
static void Main(string[] args)
{
//TestCompiler();
if (args.Length == 0)
{
Console.WriteLine("No llex or alx file specified");
return;
}
else if (!File.Exists(args[0]))
{
Console.WriteLine("Invalid llex file {0}", args[0]);
return;
}
Console.WriteLine("Generating lexer...");
string outputFile = args.Length > 1 ? args[1] : new FileInfo(args[0]).FullName + ".cs";
var lexer = args[0].ToLower().EndsWith(".alx") ?
AlxFile.Interpret(args[0]) :
LLexFile.Interpret(args[0]);
File.WriteAllText(outputFile, lexer);
Console.WriteLine("Lexer written to {0}", outputFile);
}
}
}