private void ResaltarSintaxis() { StringReader input = new StringReader(codigoFuente.Text); TinyMachineLexer lexer = new TinyMachineLexer(input); Symbol sym; int textOffset = 0, lineaActual = 0; codigoFuente.Enabled = false; while ((sym = lexer.next_token()).sym != TokenDef.EOF) { if (sym.sym == TokenDef.FIN_LINEA) { textOffset += codigoFuente.Lines[lineaActual++].Length + 1; continue; } PropiedadesTexto p = ObtenerPropiedadesToken(sym); codigoFuente.Select(textOffset + sym.right - 1, p.longitud); codigoFuente.SelectionColor = p.colorTexto; if (sym.sym == TokenDef.FIN_LINEA || sym.sym == TokenDef.COMENTARIO_LINEA || sym.sym == TokenDef.COMENTARIO_FIN) { textOffset += codigoFuente.Lines[lineaActual++].Length + 1; } } codigoFuente.SelectionStart = 0; codigoFuente.SelectionLength = 0; codigoFuente.Enabled = true; }
public void cargarPrograma(string nombreArchivo) { StreamReader input = null; try { ResetHardware(); input = new StreamReader(nombreArchivo); TinyMachineLexer lexer = new TinyMachineLexer(input); lexer.setNombreArchivo(System.IO.Path.GetFileName(nombreArchivo)); TinyMachineParser parser = new TinyMachineParser(lexer); iMem = (Programa)(parser.parse().value); if (Utilidades.errorList.Count > 0) { throw new ErrorAnalisisException("Se ha producido un error durante el análisis sintáctico"); } SemanticalParser.SemanticalParse(lexer.getNombreArchivo(), iMem); if (Utilidades.errorList.Count > 0) { throw new ErrorAnalisisException("Se ha producido un error durante el análisis semántico"); } programaActual = nombreArchivo; //LLenar diccionario con las líneas físicas de cada instrucción y el numero de operación de la misma. foreach (KeyValuePair <int, Operacion> entry in iMem.Instrucciones) { lineasOperacion.Add(entry.Value.Opcode.left, entry.Value.NumeroOp); } } catch (Exception ex) { programaActual = null; iMem = null; throw ex; } finally { if (input != null) { input.Close(); } } }