📄 mainframe.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package compilerphase1;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.StringTokenizer;/** * * @author group */public class mainframe extends JFrame implements ActionListener { //*************global decleration*********************** JTextArea commands = new JTextArea(""); JButton compile = new JButton("Compile"); JButton clear = new JButton("Clear"); JButton exit = new JButton("E x i t"); JScrollPane scroll_in_text = new JScrollPane(commands); JTextArea output = new JTextArea(" Tokens Type \n================================\n"); JScrollPane scroll_in_output = new JScrollPane(output); Check check; StringBuffer str; java.awt.List list1; String sourceString; JLabel inp = new JLabel("Input The Code Here :"); JLabel lout = new JLabel("output :"); JLabel tout = new JLabel("Symbol Table :"); //****************************************************** public mainframe() { super("Lexical_Analysis"); setSize(350, 440); getContentPane().setLayout(null); setResizable(false); setLocation(220, 100); tout.setVisible(false); scroll_in_output.setVisible(false); //*********labels********************* inp.setBounds(40, 10, 200, 20); inp.setFont(new java.awt.Font("Serif", 3, 16)); inp.setForeground(Color.blue); getContentPane().add(inp); inp.setVisible(true); lout.setBounds(40, 250, 100, 20); tout.setBounds(40, 205, 100, 20); tout.setFont(new java.awt.Font("Serif", 3, 16)); tout.setForeground(Color.blue); getContentPane().add(tout); tout.setVisible(true); //*****************to text area 1*********************** scroll_in_text.setBounds(40, 40, 260, 100); commands.setFont(new java.awt.Font("Serif", 1, 16)); commands.setForeground(Color.red); getContentPane().add(scroll_in_text); scroll_in_text.setVisible(true); //*****************to text area 2*********************** scroll_in_output.setBounds(40, 235, 260, 150); output.setFont(new java.awt.Font("Serif", 1, 14)); output.setForeground(Color.black); //output.setBackground(new Color(150,200,170)); getContentPane().add(scroll_in_output); scroll_in_output.setVisible(true); //*********to button******************** compile.setBounds(40, 145, 130, 23); getContentPane().add(compile); compile.setVisible(true); compile.addActionListener(this); clear.setBounds(170, 145, 130, 23); getContentPane().add(clear); clear.setVisible(true); clear.addActionListener(this); exit.setBounds(170, 168, 130, 23); getContentPane().add(exit); exit.setForeground(Color.red); exit.setVisible(true); exit.addActionListener(this); check = new Check(); //*******************list************************** list1 = new java.awt.List(); list1.setBounds(450, 40, 300, 200); //**************************************** setVisible(true); tout.setVisible(false); scroll_in_output.setVisible(false); clear.setEnabled(false); } //***************************************************************** //********************actionPerformed******************************* public void actionPerformed(ActionEvent e) { JButton c = (JButton) e.getSource(); if (c == compile) { tout.setVisible(true); scroll_in_output.setVisible(true); clear.setEnabled(true); list1.clear(); output.setText(" Tokens Tabel \n================================\n"); output.append("Token Token Token \n"); output.append("class value name \n"); sourceString = commands.getText(); str = new StringBuffer(sourceString); int in1 = str.indexOf("/*"); int in2 = str.indexOf("*/"); while ((in1 != -1) && (in2 != -1)) { System.out.println(in1 + " " + in2); if ((in1 == -1) || (in2 == -1)) { } else { sourceString = (str.delete(in1, in2 + 2)).toString(); } in1 = str.indexOf("/*"); in2 = str.indexOf("*/"); } boolean p = true; StringTokenizer st = new StringTokenizer(sourceString); while (st.hasMoreTokens()) { list1.addItem(st.nextToken()); } System.out.print(list1.countItems()); for (int i = 0; i < list1.countItems(); i++) { if ((list1.getItem(i)).equals(" ")) { } else if ((list1.getItem(i)).equals("\n")) { } else if (check.isoperator((list1.getItem(i)).trim())) { int z = i; z = z + 1; if (check.isoperator((list1.getItem(z)).trim())) { System.out.println(list1.getItem(i) + list1.getItem(z) + " operator"); output.append("3 " + list1.getItem(i) + list1.getItem(z) + " Operator\n"); i++; } else { System.out.println(list1.getItem(i) + " operator"); output.append("3 " + list1.getItem(i) + " Operator\n"); } } else if (check.isspecial((list1.getItem(i)).trim())) { System.out.println(list1.getItem(i) + " special"); output.append("6 " + list1.getItem(i) + " Special Char.\n"); } else if (check.isnum((list1.getItem(i)).trim())) { System.out.println(list1.getItem(i) + " number"); output.append("4 " + list1.getItem(i) + " Constant Num.\n"); } else if (check.iskeywords((list1.getItem(i)).trim())) { System.out.println(list1.getItem(i) + " keyword"); output.append("1 " + list1.getItem(i) + " Keyword\n"); } else { System.out.println(list1.getItem(i) + " identifer"); output.append("2 " + list1.getItem(i) + " Identifer\n"); } } } if (c == clear) { commands.setText(" "); tout.setVisible(false); scroll_in_output.setVisible(false); clear.setEnabled(false); } if (c == exit) { System.exit(0); } }}//**********************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -