summaryrefslogtreecommitdiff
path: root/Compiler/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Compiler/Program.cs')
-rw-r--r--Compiler/Program.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Compiler/Program.cs b/Compiler/Program.cs
new file mode 100644
index 0000000..b832a53
--- /dev/null
+++ b/Compiler/Program.cs
@@ -0,0 +1,31 @@
+namespace Q1.Compiler;
+
+using Antlr4.Runtime;
+using CommandLine;
+using Parser = CommandLine.Parser;
+
+class Program
+{
+ static void Main(string[] args)
+ {
+ Parser.Default.ParseArguments<Options>(args).WithParsed(Program.Main);
+ }
+
+ static void Main(Options options)
+ {
+ Environment.CurrentDirectory = Path.GetDirectoryName(options.InputFile) ?? Environment.CurrentDirectory;
+ options.InputFile = Path.GetFileName(options.InputFile);
+
+ AntlrFileStream inputStream = new(options.InputFile);
+ CGrammarLexer lexer = new(inputStream);
+ lexer.RemoveErrorListeners();
+
+ CommonTokenStream tokenStream = new(lexer);
+ CGrammarParser parser = new(tokenStream);
+ parser.RemoveErrorListeners();
+
+ CCompilerVisitor compiler = new();
+ var result = compiler.Compile(parser.program());
+ File.WriteAllLines(options.OutputFile, result);
+ }
+} \ No newline at end of file