/// <summary> /// retorna null si ocurrio un error al leer el archivo. /// </summary> /// <param name="path"></param> /// <returns></returns> private StaticEntity CreateStaticEntity(string path) { var src = File.ReadAllText(path); var grammar = new PyUsacGrammar(); var langData = new LanguageData(grammar); var parser = new Irony.Parsing.Parser(langData);//Para evitar conflicto con el namespace Parser var parseTree = parser.Parse(src); bool hasErrors = false; foreach (var error in parseTree.ParserMessages) { if (error.Level == Irony.ErrorLevel.Error) { hasErrors = true; } ErrorFactory.CreateParsingError(error, path); } if (hasErrors) { return(null); } var astBuilder = new PyAstBuilder(new AstContext(langData), path); astBuilder.BuildAst(parseTree); var programNode = (ProgramNode)parseTree.Root.AstNode; var entity = new StaticEntity(programNode); entity.InitVisitor(true); return(entity); }
public static bool InterpretFromFileName(string filePath) { string src; try { src = File.ReadAllText(filePath); } catch (Exception) { //Reprotar error de preprocesador return(false); } var grammar = new PyUsacGrammar(); var langData = new LanguageData(grammar); var parser = new Irony.Parsing.Parser(langData);//Para evitar conflicto con el namespace Parser var parseTree = parser.Parse(src); var root = parseTree.Root; bool hasErrors = false; foreach (var error in parseTree.ParserMessages) { if (error.Level == Irony.ErrorLevel.Error) { hasErrors = true; } ErrorHelper.ErrorFactory.CreateParsingError(error, filePath); } if (hasErrors) { return(false); } //var dotCode = GetDot(root);//Descomentar en debug mode! :) var astBuilder = new PyAstBuilder(new AstContext(langData), filePath); astBuilder.BuildAst(parseTree); var programNode = (ProgramNode)parseTree.Root.AstNode; //GetDot(programNode);//Descomentar en debug mode! :) var entity = new StaticEntity(programNode); entity.InitVisitor(true); entity.InvokeMain(); TypeConstants.ClearTypeHashtable(); return(true); }