-
Notifications
You must be signed in to change notification settings - Fork 5
/
Emulator.cs
39 lines (34 loc) · 1.05 KB
/
Emulator.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Antlr4.Runtime;
using Antlr4;
namespace iro4cli
{
/// <summary>
/// Emulates running Iro, and generating all surrounding grammars.
/// </summary>
public class Emulator
{
/// <summary>
/// Runs the Iro emulator with a given input.
/// </summary>
public static Dictionary<string, IroVariable> Run(string input)
{
//Create input stream & lexer.
var s_chars = new AntlrInputStream(input);
var s_lexer = new iroLexer(s_chars);
//Make tokens and parser.
var s_tokens = new CommonTokenStream(s_lexer);
var s_parse = new iroParser(s_tokens);
//Parse, execute the visitor.
s_parse.BuildParseTree = true;
var s_tree = s_parse.compileUnit();
var visitor = new IroVisitor();
visitor.VisitCompileUnit(s_tree);
return IroScope.Variables;
}
}
}