getchar.java
来自「可以实现.txt和.pas文件的词法分析,提供给大家参考和学习」· Java 代码 · 共 49 行
JAVA
49 行
package PL0;
import PL0.EventDo;
import PL0.ErrorException;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
public class GetChar{
static String filepath;
static String s;
static char[] line;
public static char ch=' ';
static int current=0;
static int length=0;
static Iterator<String> it;
public GetChar(String fp) throws IOException{
filepath=fp;
LinkedList<String> file=new LinkedList<String>();
BufferedReader in=new BufferedReader(new FileReader(filepath));
while((s=in.readLine())!=null){
file.addLast(s);
}
it=file.iterator();
}
public static int getchar() throws IOException{
BufferedReader in=new BufferedReader(new FileReader(filepath));
if(current==length){
try{
if(!it.hasNext()){
throw new ErrorException();
}
}catch(ErrorException err){
EventDo.errorinfor.setText("dsfdgfdgfdg");
return -1;
}
s=it.next();
current=0;
length=Array.getLength(s.toCharArray());
line=new char[length+1];
line=s.toCharArray();
}
ch=line[current];
current++;
in.close();
return 0;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?