?? getsym.java
字號:
package PL0;
import java.util.*;
import PL0.*;
import java.io.*;
public class GetSym{
static final int MAX=15;
public static String csymbol;
static String s;
static char[] word=new char[MAX];
public static GetChar c;
static Symbol sym=new Symbol();
public static PrintWriter out;
public GetSym(String fp,String wfp) throws IOException{
c=new GetChar(fp);
out=new PrintWriter(new BufferedWriter(new FileWriter(wfp)));
}
public static PrintWriter getout(){
return out;
}
public static int getsym() throws IOException{
while(c.ch==' ' || c.ch==10 || c.ch==9){
if(c.getchar()==-1){
return -1;
}
}
if((c.ch>='a' && c.ch<='z') || (c.ch>='A' && c.ch<='Z')){
int i=0;
do{
word[i]=c.ch;
i++;
if(c.getchar()==-1){
return -1;
}
}while(c.ch>='a' && c.ch<='z' || c.ch>='A' && c.ch<='Z' || c.ch>'0' && c.ch<'9');
s=new String(word);
s=s.substring(0,i);
if(sym.KeyWord.contains(s)){
csymbol=s;
out.write("keyword "+s+"\r\n");
}
else
{
csymbol="ident";
out.write("ident "+s+"\r\n");
}
}
else{
if(c.ch>='0' && c.ch<='9'){
int num=0;
csymbol="number";
do{
num=num*10+c.ch-'0';
if(c.getchar()==-1){
return -1;
}
}while(c.ch>='0' && c.ch<='9');
out.write("number "+num+"\r\n");
}
else{
if(c.ch==':'){
if(c.getchar()==-1){
return -1;
}
if(c.ch=='='){
csymbol="becomes";
out.write(":= "+csymbol+"\r\n");
if(c.getchar()==-1){
return -1;
}
}
else{
csymbol="nul";
out.write("undefined symbol "+csymbol+"\r\n");
}
}
else{
if(c.ch=='<'){
if(c.getchar()==-1){
return -1;
}
if(c.ch=='='){
csymbol="leq";
out.write("<= "+csymbol+"\r\n");
if(c.getchar()==-1){
return -1;
}
}
else{
csymbol="lss";
out.write("< "+csymbol+"\r\n");
}
}
else{
if(c.ch=='>'){
if(c.getchar()==-1){
return -1;
}
if(c.ch=='='){
csymbol="geq";
out.write(">= "+csymbol+"\r\n");
if(c.getchar()==-1){
return -1;
}
}
else{
csymbol="gtr";
out.write("> "+csymbol+"\r\n");
}
}
else{
csymbol=sym.simpleword[c.ch];
out.write("simple word "+csymbol+"\r\n");
if(csymbol!="period"){
if(c.getchar()==-1){
return -1;
}
}
}
}
}
}
}
return -1;
}
public static void dod() throws IOException{
GetSym getsym=new GetSym("c:/testpas.pl0","c:/out.txt");
try{
while(true){
GetSym.getsym();
if(GetSym.csymbol=="period"){
break;
}
}
// GetSym getsym=new GetSym(filename.getText(),"c:/out.txt");
// getsym.dod();
// filename.setText(filename.getText()+"處理完畢");
// if(getsym.c.err.error.isEmpty()){
// errorinfor.setText("錯誤序號:"+getsym.c.err.error.get(0));
// }
}catch(IOException ef){
PL0.EventDo.errorinfor.setText("文件操作錯誤");
}
// while(true){
// if(getsym.csymbol=="period"){
// break;
// }
// }
// getsym.getsym();
out.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -