⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c097b0ae424d001a1c109388f3cd13fa

📁 这只是我做课程设计的时候做的一个小的分析器 希望对你们有用
💻
字号:

import  java.awt.*;
import  java.awt.event.*;
public class analyse 
{
	static TextArea t1=new TextArea();
  static TextArea t2=new TextArea();
 static String save[]={"program","type","var","procedure","begin","end","array","of"
		,"record","if","then","else","fi","while","do","endwh","read","write","return",
		"integer","char"};
 //static int zl=0;
 //static int wz=0;
public static void main(String[] args)
{
	 analyse a1=new analyse();
	  Frame f=new Frame();
	  Button b=new Button("词法分析");	 
Panel p1=new Panel();
Panel p2=new Panel();
//  TextArea t1=new TextArea();
// TextArea t2=new TextArea();
f.setLayout(new BorderLayout());
f.add("North",p1);
f.add("Center",p2);
f.addWindowListener(new wla());

p1.setLayout(new GridLayout(1,2));
p2.setLayout(new GridLayout(1,2));
p1.add(b);
p2.add(t1);
//analyse.t1.setText("请输入SNL");
p2.add(t2);
b.addActionListener(new ActionListener()
		{
	    String ha=new String();
	    String h=new String();
	    int n=0;   //判断位
	  //  Node no=new Node();
	    tklist tk=new tklist();
		 public void actionPerformed(ActionEvent e)
		{
	      ha=t1.getText();
	     
//			 tk.insert(tk);
// 			tk.zl=1;
// 			tk.wz=2;
// 			t2.setText(""+tk.zl+tk.wz); 
			 
	   //  char c[]=ha.toCharArray();
        for(int i=0;i<ha.length();i++)
        {
        	switch (ha.charAt(i))
        	{
        		case ' ':
        		//	t2.setText()
        		h=ha.substring(n,i);
//        		t2.setText(""+save.length);
 //       		t2.setText(h);
        		for(int i1=0;i1<save.length;i1++)
        		{
        			if(h==save[i1])
        			{
        				
        			tk.insert(tk);
        			tk.zl=1;
        			tk.wz=i1;
        			t2.setText(""+tk.zl+tk.wz);
        			}
           		}
              	n=i;
        	
        	}
        	
        }
		}
	});
f.setSize(200,160);
f.setVisible(true);
}
}


 class Node
{
 Object data;
 Node next;
 
 Node(Object d) 
{ 
  data=d; 
  next=null; 
}
 //public void insert(Object d) 
// { 
 //Node e=new Node(d); 
 //}
}
 
 class Nodelist 
{
	private Node Head=null; 
	private Node Tail=null; 
	private Node Pointer=null; 
	private int Length=0; 

private Node cursor()
{
if(Head==null) 
throw new java.lang.NullPointerException(); 
else if(Pointer==null) 
return Head; 
else 
return Pointer.next; 
} 

public void insert(Object d)
{
Node e=new Node(d); 
if(Length==0) 
{
	Head=e;
	Tail=e;  
}
else
{
Node temp=cursor();
e.next=temp;
if(Pointer==null)
Head=e; 
else
   Pointer.next=e;
} 
    Length++;
} 	
}
 
class tklist extends Nodelist
{
	int line=0;
	int zl=0;
	int wz=0;
/*	
tklist(Object d)
{
line=0;
zl=0;
wz=0;
}*/
}
 
class wla extends WindowAdapter
{
	public void windowClosing(WindowEvent e)
    {
	System.exit(1);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -