-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (53 loc) · 1.82 KB
/
Program.cs
File metadata and controls
61 lines (53 loc) · 1.82 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
using Antlr4.Runtime;
using Delphi.Generated;
using System;
using System.IO;
using System.Text;
namespace Delphi
{
class Program
{
static string TranslatePascalToCSharp(string pascal)
{
var inputStream = new AntlrInputStream(pascal);
var speakLexer = new DelphiLexer(inputStream);
var commonTokenStream = new CommonTokenStream(speakLexer);
var pascalParser = new DelphiParser(commonTokenStream);
var listener = new DelphiListener();
pascalParser.AddParseListener(listener);
pascalParser.file();
return listener.Code;
}
static void Main(string[] args)
{
Console.WriteLine("Start...");
try
{
var files = Directory.GetFiles(@"delphi\", "*.pas");
foreach (var f in files)
{
try
{
var source = File.ReadAllText(f);
var csharp = TranslatePascalToCSharp(source);
File.WriteAllLines(Path.Combine(@"csharp", Path.GetFileNameWithoutExtension(f) + ".cs"), new[] { csharp }, Encoding.UTF8);
}
catch (Exception ex)
{
Console.Write($"[{f}] ");
if (ex.InnerException != null)
Console.WriteLine(ex.InnerException.Message);
else
Console.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
Console.WriteLine("Hit enter to exit...");
Console.ReadLine();
}
}
}