public void Ifc_SemanticModel_ShouldCreateSymbolTable(string path) { var parser = new ExpressParser(); using (var stream = File.Open(path, FileMode.Open, FileAccess.Read)) { var result = parser.Parse(stream); Assert.IsTrue(result.Success); var builder = new SymbolTableBuilder(result.Schemas); var symbolTable = builder.Build(); var declarations = new DeclarationSyntaxWalker(); foreach (var schema in result.Schemas) { schema.Accept(declarations); } foreach (var declaration in declarations.Declarations) { if (declaration is LocalRuleDeclaration) { continue; } var symbolInfo = symbolTable.GetSymbolInfo(declaration); Assert.IsNotNull(symbolInfo, $"Missing ISymbolInfo for {declaration.Name}({declaration.Kind})"); ValidateSymbolInfo(symbolInfo); } } }
public SemanticModel Build() { //create symbol table (constructs mapping Declaration->ISymbolInfo) var builder = new SymbolTableBuilder(schemas_); symbolTable_ = builder.Build(); //initialize state scopes_.Clear(); scopes_.Push(Scope.CreateRootScope(schemas_)); //visit expressions (constructs mapping Reference->TypeInfo and Exoression->TypeInfo) //foreach (var schema in schemas_) // schema.Accept(this); //TODO: expressions return new SemanticModel(symbolTable_); }
static void Main(string[] args) { if (string.IsNullOrEmpty(args[0])) throw new Exception("No file name"); string inputFile = args[0]; string outputFile = GetOutputFilePath(inputFile); Parser p = new Parser(inputFile); Translator t = new Translator(); SymbolTableBuilder b = new SymbolTableBuilder(); List<ParsedCommand> parsedCommands = p.Parse(); Dictionary<string, int> symbolTable = b.Build(parsedCommands); List<string> codedCommands = t.Translate(parsedCommands, symbolTable); File.WriteAllLines(outputFile, codedCommands.ToArray()); }