private void ExecuteTest(Stream stream, string fileName) { string astData; Stream astDataStream = null; string irData; Stream irDataStream = null; try { MiniParser miniParser = new MiniParser(stream); AstProgram astProgram = miniParser.ParseProgram(); stream.Close(); astProgram.GenerateAstData(true); // Output AST data to UI OnAstOut(new AstOutEventArgs(astProgram.AstData)); Ast.ResetAstData(); // Present AST data to AST parser as a stream AstParser astPsr = new AstParser(astDataStream = CreateMemoryStream(astProgram.AstData)); AstProgram p2 = AstParser.Program(); astDataStream.Close(); // ------------------------------------------------------- SymbolVisitor sv = new SymbolVisitor(); sv.visit(p2); //sv.symTable.show(); TypeVisitor tv = new TypeVisitor(sv.symTable); tv.visit(p2); IrgenVisitor iv = new IrgenVisitor(sv.symTable, tv); IrProg ir0 = iv.visit(p2); Canon cv = new Canon(); Ir.Clear(); IrProg irProg = cv.visit(ir0); irProg.GenerateIrData(); // Output AST data to UI OnIrOut(new IrOutEventArgs(irData = Ir.IrData)); Ir.Clear(); // ------------------------------------------------------- IrProg irProgram = null; try { //stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); irProgram = (new IrParser(irDataStream = CreateMemoryStream(irData))).Program(); } catch (InterpException ex) { OnAppException(new AppExceptionEventArgs(ex)); } catch (Exception ex) { OnAppException(new AppExceptionEventArgs(ex)); } finally { if (stream != null) stream.Close(); } if (irProgram != null) { try { InterpVisitor interpreter = new InterpVisitor(); interpreter.AddOnSystemOut(Interpreter_OnSystemOut); interpreter.visit(irProgram); } catch (Exception ex) { OnAppException(new AppExceptionEventArgs(ex)); } } } catch (TypeException ex) { OnAppException(new AppExceptionEventArgs(ex)); } catch (SymbolException ex) { OnAppException(new AppExceptionEventArgs(ex)); } catch (Exception ex) { OnAppException(new AppExceptionEventArgs(ex)); } }
private void ExecuteIrTest(Stream stream, string fileName) { IrProg p = null; try { p = (new IrParser(stream)).Program(); } catch (InterpException ex) { OnAppException(new AppExceptionEventArgs(ex)); } catch (Exception ex) { OnAppException(new AppExceptionEventArgs(ex)); } finally { if (stream != null) stream.Close(); } if (p != null) { try { InterpVisitor iv = new InterpVisitor(); iv.AddOnSystemOut(Interpreter_OnSystemOut); iv.visit(p); } catch (Exception ex) { OnAppException(new AppExceptionEventArgs(ex)); } } }