欢迎来到天天文库
浏览记录
ID:6651879
大小:114.50 KB
页数:18页
时间:2018-01-21
《编译原理 词法分析》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、package词法分析;importjava.awt.FileDialog;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileReader;importjava.io.FileWriter;importjava.util.Stack;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JTextArea;import
2、javax.swing.JTextField;import词法分析.key;import词法分析.operator;import词法分析.symbol;publicclassfunctionextendsJFrame{staticfinallongserialVersionUID=1L;intstart,end,i=0,j=0,line=0,flag=0,flag1=0;Stacke=newStack();//()括号的栈Stacke1=newStack3、>();//[]的栈Stacke2=newStack();//{}的栈charc,c8;Lexical_Framef1=newLexical_Frame(5);JTextAreaf11=newJTextArea();keyk=newkey();operatorop=newoperator();symbolsy=newsymbol();Stringstr="",currut="",token="";FileDialogopen,save;JTextFieldstring_Rearch,string4、_Replace;JButtonbtn_Search,btn_Search_Next,btn_Replace,btn_Replace_All;function(){;}publicStringop(JTextAreafile1,Lexical_Framet,JTextAreafile3){open=newFileDialog(t,"打开",FileDialog.LOAD);open.setVisible(true);try{Filef12=newFile(open.getDirectory(),open.getFile());t.fram5、e.setTitle(""+open.getDirectory()+open.getFile());FileReaderfr=newFileReader(f12);BufferedReaderbr=newBufferedReader(fr);while((str=br.readLine())!=null){line++;j=str.length();file1.append(line+""+str+'');for(i=0;i6、32)continue;if(str.charAt(i)=='/'&&(str.charAt(i+1)=='*'7、8、str.charAt(i+1)=='/')){if(str.charAt(i)=='/'&&str.charAt(i+1)=='*')flag1=1;elsebreak;}if(flag1==1){for(i=0;i9、ontinue;if(is_digital(file3))continue;if(is_oper(file3))continue;if(is_sym_String(file3))continue;}if(c<010、11、c>255)f11.append("存在非法字符:"+c+"在第"+line+"行"+'');}}if(flag1==1)System.out.println("未找到注释结尾符号");if(!e.empty())f11.append("少了)括号"+'');if(!e1.empty())f11.append("少了[括12、号"+'');if(!e2.empty())f11.append("少了}括号"+'');t.filee.setText(f11.getText());fr.close();}catc
3、>();//[]的栈Stacke2=newStack();//{}的栈charc,c8;Lexical_Framef1=newLexical_Frame(5);JTextAreaf11=newJTextArea();keyk=newkey();operatorop=newoperator();symbolsy=newsymbol();Stringstr="",currut="",token="";FileDialogopen,save;JTextFieldstring_Rearch,string
4、_Replace;JButtonbtn_Search,btn_Search_Next,btn_Replace,btn_Replace_All;function(){;}publicStringop(JTextAreafile1,Lexical_Framet,JTextAreafile3){open=newFileDialog(t,"打开",FileDialog.LOAD);open.setVisible(true);try{Filef12=newFile(open.getDirectory(),open.getFile());t.fram
5、e.setTitle(""+open.getDirectory()+open.getFile());FileReaderfr=newFileReader(f12);BufferedReaderbr=newBufferedReader(fr);while((str=br.readLine())!=null){line++;j=str.length();file1.append(line+""+str+'');for(i=0;i6、32)continue;if(str.charAt(i)=='/'&&(str.charAt(i+1)=='*'7、8、str.charAt(i+1)=='/')){if(str.charAt(i)=='/'&&str.charAt(i+1)=='*')flag1=1;elsebreak;}if(flag1==1){for(i=0;i9、ontinue;if(is_digital(file3))continue;if(is_oper(file3))continue;if(is_sym_String(file3))continue;}if(c<010、11、c>255)f11.append("存在非法字符:"+c+"在第"+line+"行"+'');}}if(flag1==1)System.out.println("未找到注释结尾符号");if(!e.empty())f11.append("少了)括号"+'');if(!e1.empty())f11.append("少了[括12、号"+'');if(!e2.empty())f11.append("少了}括号"+'');t.filee.setText(f11.getText());fr.close();}catc
6、32)continue;if(str.charAt(i)=='/'&&(str.charAt(i+1)=='*'
7、
8、str.charAt(i+1)=='/')){if(str.charAt(i)=='/'&&str.charAt(i+1)=='*')flag1=1;elsebreak;}if(flag1==1){for(i=0;i9、ontinue;if(is_digital(file3))continue;if(is_oper(file3))continue;if(is_sym_String(file3))continue;}if(c<010、11、c>255)f11.append("存在非法字符:"+c+"在第"+line+"行"+'');}}if(flag1==1)System.out.println("未找到注释结尾符号");if(!e.empty())f11.append("少了)括号"+'');if(!e1.empty())f11.append("少了[括12、号"+'');if(!e2.empty())f11.append("少了}括号"+'');t.filee.setText(f11.getText());fr.close();}catc
9、ontinue;if(is_digital(file3))continue;if(is_oper(file3))continue;if(is_sym_String(file3))continue;}if(c<0
10、
11、c>255)f11.append("存在非法字符:"+c+"在第"+line+"行"+'');}}if(flag1==1)System.out.println("未找到注释结尾符号");if(!e.empty())f11.append("少了)括号"+'');if(!e1.empty())f11.append("少了[括
12、号"+'');if(!e2.empty())f11.append("少了}括号"+'');t.filee.setText(f11.getText());fr.close();}catc
此文档下载收益归作者所有