首页 编译原理词法分析

编译原理词法分析

举报
开通vip

编译原理词法分析编译原理词法分析 package 词法分析; import java.awt.FileDialog; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.Stack; import javax.swing.JButton; import jav...

编译原理词法分析
编译原理词法 分析 定性数据统计分析pdf销售业绩分析模板建筑结构震害分析销售进度分析表京东商城竞争战略分析 package 词法分析; import java.awt.FileDialog; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.Stack; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField; import 词法分析.key; import 词法分析.operator; import 词法分析.symbol; public class function extends JFrame{ static final long serialVersionUID =1L; int start,end,i=0,j=0,line=0,flag=0,flag1=0; Stack e=new Stack();//()括号的栈 Stack e1=new Stack();//[]的栈 Stack e2=new Stack();//{}的栈 char c,c8; Lexical_Frame f1 =new Lexical_Frame(5); JTextArea f11=new JTextArea(); key k=new key(); operator op=new operator(); symbol sy=new symbol(); String str="",currut="",token=""; FileDialog open,save; JTextField string_Rearch,string_Replace; JButton btn_Search,btn_Search_Next,btn_Replace,btn_Replace_All; function() { ; } public String op(JTextArea file1,Lexical_Frame t,JTextArea file3) { open=new FileDialog(t,"打开",FileDialog.LOAD); open.setVisible(true); try{ File f12=new File(open.getDirectory(),open.getFile()); t.frame.setTitle(""+open.getDirectory()+open.getFile()); FileReader fr=new FileReader(f12); BufferedReader br=new BufferedReader(fr); while((str=br.readLine())!=null) { line++; j=str.length(); file1.append(line+" "+str+'\n'); for(i=0;i255) f11.append("存在非法字符:"+c+"在第"+line+"行"+'\n'); } } if(flag1==1) System.out.println("未找到注释结尾符号"); if(!e.empty()) f11.append("少了 )括号"+'\n'); if(!e1.empty()) f11.append("少了 [ 括号"+'\n'); if(!e2.empty()) f11.append("少了 } 括号"+'\n'); t.filee.setText(f11.getText()); fr.close(); } catch(Exception e1) {} file1.setVisible(true); return open.getDirectory()+open.getFile(); } public boolean is_identifiers_key(JTextArea file3) { if(flag1==0&&((str.charAt(i)>=65&&str.charAt(i)<=90)||(str.charAt(i)>=97&&str.charAt(i)< =122)||str.charAt(i)=='_')) { c=(str.charAt(i)); while(i=48&&str.charAt(i)<=57) { while(i=48&&str.charAt(i)<=57)||str.charAt(i)=='.')) { c=(str.charAt(i)); currut=Character.toString(str.charAt(i)); token=token+currut; i++; } file3.append("("+token+","+"数字常量"+","+line+"行"+")"+'\n'); //c=(str.charAt(i)); token="1"; flag=1; i--; return true; } return false; } public boolean is_oper(JTextArea file3) { if(flag1==0&&op.isoperator(str.charAt(i))) { while(i"); leagl_oper[6]=new String("-"); leagl_oper[7]=new String("++"); leagl_oper[8]=new String("--"); leagl_oper[9]=new String("*"); leagl_oper[10]=new String("&"); leagl_oper[11]=new String("!"); leagl_oper[12]=new String("~"); leagl_oper[13]=new String("/"); leagl_oper[14]=new String("%"); leagl_oper[15]=new String("+"); leagl_oper[16]=new String("-"); leagl_oper[17]=new String("<<"); leagl_oper[18]=new String(">"); leagl_oper[19]=new String(">="); leagl_oper[20]=new String(">>"); leagl_oper[21]=new String(">="); leagl_oper[22]=new String("<="); leagl_oper[23]=new String("=="); leagl_oper[24]=new String("!="); leagl_oper[25]=new String("^"); leagl_oper[26]=new String("|"); leagl_oper[27]=new String("||"); leagl_oper[28]=new String("&&"); leagl_oper[29]=new String("?:"); leagl_oper[30]=new String("="); leagl_oper[31]=new String("/="); leagl_oper[32]=new String("*="); leagl_oper[33]=new String("%="); leagl_oper[34]=new String("+="); leagl_oper[35]=new String("-="); leagl_oper[36]=new String("<<="); leagl_oper[37]=new String(">>="); leagl_oper[38]=new String("&="); leagl_oper[39]=new String("|="); leagl_oper[40]=new String("^="); leagl_oper[41]=new String(","); leagl_oper[42]=new String(":"); leagl_oper[43]=new String("<"); } public boolean isoperator(char c1) { for(i5=0;i5<23;i5++) if(c1==oper_Word[i5]) return true; return false; } public boolean is_leagl_oper(String s) { for(i5=0;i5<44;i5++) if(s.equals(leagl_oper[i5])) return true; return false; } } package 词法分析; public class symbol { int i1=0; char sym[]=new char[6]; public symbol() { sym[0]='\''; sym[1]='"'; sym[2]='}'; sym[3]='{'; sym[4]='#'; sym[5]=';'; } public boolean is_sym(char c2) { for(i1=0;i1<6;i1++) if(sym[i1]==c2) return true; return false; } } package 词法分析; public class play { public static void main(String args[]) { new Lexical_Frame (); } }
本文档为【编译原理词法分析】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_196623
暂无简介~
格式:doc
大小:63KB
软件:Word
页数:0
分类:互联网
上传时间:2017-09-27
浏览量:20