编译原理词法
分析
定性数据统计分析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';
oper_Word[6]='!';
oper_Word[7]='~';
oper_Word[8]='+';
oper_Word[9]='*';
oper_Word[10]='&';
oper_Word[11]='*';
oper_Word[12]='%';
oper_Word[13]='<';
oper_Word[14]='=';
oper_Word[15]='>';
oper_Word[16]='^';
oper_Word[17]='|';
oper_Word[18]=',';
oper_Word[19]='.';
oper_Word[20]=':';
oper_Word[21]='?';
oper_Word[22]='/';
leagl_oper[0]=new String("[");
leagl_oper[1]=new String("]");
leagl_oper[2]=new String("(");
leagl_oper[3]=new String(")");
leagl_oper[4]=new String(".");
leagl_oper[5]=new String("->");
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 ();
}
}