⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errormsg.java

📁 编译原理大作业---tiger编译器 包括semant,translate,mipsframe,regalloc等所有phase 懂的人自会知道
💻 JAVA
字号:
package ErrorMsg;public class ErrorMsg {   private LineList linePos = new LineList(-1,null);   private int lineNum=1;   private String filename;   public boolean anyErrors;   public static int num_error=0;   private java.io.FileInputStream inp=null;   private java.io.BufferedReader buf=null;   public ErrorMsg(String f) {       filename = f;       try {          inp = new java.io.FileInputStream(f);          buf =new java.io.BufferedReader(new java.io.InputStreamReader(inp));          buf.mark(inp.available()+1);       }       catch (Exception e) {          System.out.println("File error : " + e);          System.exit(-1);       }   }   public void newline(int pos) {      lineNum++;      linePos = new LineList(pos,linePos);   }   public void error(int pos, String msg) {      int n = lineNum;      LineList p = linePos;      String sayPos = "0.0";      anyErrors = true;      try {         // resetto il buffer         buf.reset();         while (p!=null) {            if (p.head<pos) {               sayPos = "(linea " + String.valueOf(n) + ")";               break;            }            p = p.tail;            n--;         }         System.out.println("\n> "+ filename + " " + sayPos + ": " + msg +"\n");         // scorre fino ad arrivare alla linea         buf.skip((long)p.head+1);         // salva la linea         String linea = buf.readLine();         // stampa la linea ( togliendo gli spazi tipo tab!! )         System.out.println("\t" +linea.trim() );         // toglie 1 spazio in eccesso (c'e' sempre in quando si fa il trim!?)         if(linea.length()!=linea.trim().length()) pos=pos-1;         // stampa ^ sotto l'errore         System.out.print("\t");         for(int i=0;i<pos-p.head-1;i++) System.out.print(" ");         System.out.println("^");      }     catch (Exception ex) { System.out.println("Eccezione (errorMsg.error()): " + ex); }     // incrementa il num. totale degli errori trovati.     num_error++;   }}class LineList {   int head;   LineList tail;   LineList(int h, LineList t) { head = h; tail = t; }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -