![](https://csdnimg.cn/release/download_crawler_static/86526208/bg4.jpg)
if(l == 0) return ReadALine(); //输入了空字符串,重新输入
if(Buffer[0] == '#') return false; //输入单独的'#'表示不再输入
Buffer[l] = '#'; //最后一个字符用结束标记'#'代替(本来是'\0')
ipBuffer = 0; //初始化缓冲区指针
return true;
}
//从缓冲区取一个字符,返回该字符的同时将它存于全局变量 ch 中
//成功:返回字符;不成功:返回'#'
char GetChar()
{
if((ch = Buffer[ipBuffer]) != '#')
ipBuffer ++;
return ch;
}
附录:词法自动机。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;
class frame extends JFrame implements ActionListener
{
JButton button1=new JButton("打开现有文件");
JButton button2=new JButton("现场输入文件");
Choice ch=new Choice();
JButton button=new JButton("执行");
TextArea ta=new TextArea();
TextArea tb=new TextArea();
JFileChooser chooser=new JFileChooser();
FileInputStream readfile=null;
int b;
byte buffer[]=new byte[25000];
String str=null;
String id[]={"asm","cout","main","FALSE","TRUE","include","boolean","default",
"float","operator","abs","static_cast","union","auto","delete","for","private",
"struct","unsigned","bool","do","friend","protected","switch","using","break","
double","goto","public","template","virtual","case","dynamic_cast","if","regist