blob: b832a531df09ea025e74f3acbe2c53557b541519 (
plain)
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
|
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);
}
}
|