This repository has been archived by the owner on Dec 21, 2017. It is now read-only.
/
Program.cs
54 lines (46 loc) · 1.48 KB
/
Program.cs
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
using System;
using System.Globalization;
using Antlr.Runtime;
using Antlr.Runtime.Tree;
namespace SimpleC
{
public class Program
{
// "êóëüòóðîíåçàâèñèìûé" ôîðìàò äëÿ ÷èñåë (ñ ðàçäåëèòåëåì òî÷êîé)
public static readonly NumberFormatInfo NFI = new NumberFormatInfo();
public static void Main(string[] args)
{
try
{
// â çàâèñèìîñòè îò íàëè÷èÿ ïàðàìåòðîâ êîìàíäíîé ñòðîêè ðàçáèðàåì
// ëèáî ôàéë ñ èìåíåì, ïåðåäàííûì ïåðâûì ïàðàìåòðîì, ëèáî ñòàíäàðòíûé ââîä
ICharStream input = args.Length == 1 ? (ICharStream)new ANTLRFileStream(args[0])
: (ICharStream)new ANTLRReaderStream(Console.In);
Grammar.SimpleCLexer lexer = new Grammar.SimpleCLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Grammar.SimpleCParser parser = new Grammar.SimpleCParser(tokens);
ITree program = (ITree)parser.program().Tree;
// AstNodePrinter.Print(program);
// Console.WriteLine();
// SimpleCIntepreter.Execute(program);
CommonTreeNodeStream nodeStream = new CommonTreeNodeStream(program);
Grammar.SimpleCTreeWalker treeWalker = new Grammar.SimpleCTreeWalker(nodeStream);
Tree.RootNode rootNode = treeWalker.walk();
#if false
if (rootNode == null)
Console.WriteLine("NULL");
else
rootNode.Print();
#else
Interpreter.Interpreter.Shared.Prepare(rootNode);
Interpreter.Interpreter.Shared.Run();
#endif
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
}
}
}
}