static void Main(string[] args) { string filename = args[0]; string outfile = filename + ".s"; AntlrInputStream ais = new AntlrInputStream(File.Open(filename, FileMode.Open)); ITokenSource lexer = new llangLexer(ais); ITokenStream tokens = new CommonTokenStream(lexer); llangParser parser = new llangParser(tokens); parser.BuildParseTree = true; IParseTree tree = parser.prog(); ASTBuilder b = new ASTBuilder(); ASTNode root = b.Visit(tree); TypeMaker tm = new TypeMaker(); tm.Visit(root); SemanticChecker sc = new SemanticChecker(); int errors = 0; if ((errors = sc.Check(root)) > 0) { Console.WriteLine("{0} Error(s) - Aborting", errors); Console.ReadKey(); return; } (new AstPrinter()).Visit(root); Interpreter interp = new Interpreter(root); try { interp.Run(); } catch (Interpreter.ExecutionTerminatedException e) { Console.WriteLine($"Execution Terminated by exit({e.ExitCode}) call"); } //(new MIPSCodeGenerator(outfile)).Visit(root); //Console.ReadKey(); }
public override object VisitFieldAccessNode(FieldAccessNode n) { Visit(n.basestruct); if (n.basestruct.Type.Kind == TypeSymbol.TypeKind.STRUCT) { semanticChecker.CheckAndReport(n.basestruct.Type.Fields.ContainsKey(n.fieldname), n.sourceLoc, $"Undeclared Field {n.fieldname} in {n.basestruct.Type.Name}"); } else if (n.basestruct.Type.Kind == TypeSymbol.TypeKind.POINTER) { var structsymbol = TypeMaker.MakeTypeSymbolForString(n.basestruct.Type.Name); semanticChecker.CheckAndReport(structsymbol.Fields.ContainsKey(n.fieldname), n.sourceLoc, $"Undeclared Field {n.fieldname} in {structsymbol.Name}"); } else if (n.basestruct.Type.Kind == TypeSymbol.TypeKind.ENUM) { semanticChecker.CheckAndReport(n.basestruct.Type.EnumItems.ContainsKey(n.fieldname), n.sourceLoc, $"Enum {n.basestruct.Type.Name} has no item {n.fieldname}"); } else { semanticChecker.CheckAndReport(n.basestruct.Type.Kind == TypeSymbol.TypeKind.STRUCT, n.sourceLoc, "Struct not typeof struct or pointer"); } return(null); }