public Ast.Block ParseString(string Chunk) { ParseTree parseTree = parser.Parse(Chunk); ParseTreeNode root = parseTree.Root; if (root == null) { Irony.LogMessage msg = parseTree.ParserMessages[0]; throw new LuaException("", msg.Location.Line, msg.Location.Column, msg.Message); } return(ParseBlock(root)); }
public Ast.Block ParseFile(string Filename) { string source = System.IO.File.ReadAllText(Filename); ParseTree parseTree = parser.Parse(source, Filename); ParseTreeNode root = parseTree.Root; if (root == null) { Irony.LogMessage msg = parseTree.ParserMessages[0]; throw new LuaException(Filename, msg.Location.Line, msg.Location.Column, msg.Message); } return(ParseBlock(root)); }
public static ParseTreeNode analizar(String cadena) { Gramatica gramatica = new Gramatica(); LanguageData lenguaje = new LanguageData(gramatica); Parser parser = new Parser(lenguaje); // MessageBox.Show("parser"); //Error de Gramatica ParseTree arbol = parser.Parse(cadena); ParseTreeNode raiz = arbol.Root; //foreach (var item in arbol.ParserMessages) //{ // // Irony.LogMessage log = arbol.ParserMessages[item]; // //log.Location.Line.ToString(); //} for (int i = 0; i < arbol.ParserMessages.Count; i++) { Irony.LogMessage log = arbol.ParserMessages[i]; String[] dato = log.Level.ToString().Split(':'); String tipo = ""; String mensaje = log.Message.ToString(); if (dato[0] == "Invalid character") { tipo = "Error Lexico"; mensaje = mensaje.Replace("Invalid character", "Caracter invalido:"); } else { tipo = "Error Sintactico"; mensaje = mensaje.Replace("Syntax error, expected:", "Se esperaba:"); } Reporte.agregarError(mensaje, tipo, log.Location.Line, log.Location.Column); } if (raiz == null) { return(raiz); } else { generarArbol(raiz); return(raiz); } }