package com.analysis4;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
*1.保留字
*2.运算符
*3.界符
*/
public class Demo {
public static int baoliuzi = 0;
public static int yunsuanfu = 0;
public static int biaoshifu = 0;
public static int jiefu = 0;
public static int elsewords = 0;
//将txt文件转为数组
public String txt2String(File file) throws IOException
{
StringBuilder result =new StringBuilder();
try {
BufferedReader br= new BufferedReader(new FileReader(file));
String s=null;
while((s=br.readLine())!=null){
result.append(System.lineSeparator()+s);
}
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result.toString();
}
//对文本进行预处理
public char[] preTreatment(char[] sourcefile)
{
char []afterfile = new char[10000];
int index=0;
if(sourcefile.length!=0)
{
for(int i=0;i<sourcefile.length;i++)
{
//去掉//注释后的一整行
if(sourcefile[i]=='/'&&sourcefile[i+1]=='/')
{
while(sourcefile[i]!='\n'){
i++;
}
}
//去掉/**/型注释中间的字符,若只检测到/*,未检测到*/,则提示注释有误
if(sourcefile[i]=='/'&&sourcefile[i+1]=='*')
{
i=i+2;
while(sourcefile[i]!='*'||sourcefile[i+1]!='/')
{
i++;
if(i==(sourcefile.length-1))
{
System.out.println("注释有误,未找到注释尾");
return afterfile;
}
}
i=i+2;
}
if(sourcefile[i]!='\n'&&sourcefile[i]!='\r'&&sourcefile[i]!='\t')
{
afterfile[index]=sourcefile[i];
index++;
}
}
index++;
afterfile[index]='\0';
}
return afterfile;
}
//判断是否为字母
public boolean isLetter(char c)
{
if((c>='a'&&c<='z')||(c>='A'&&c<'Z'))
{
return true;
}
else
return false;
}
//判断是否为保留字,并返回编号
public int isReserve(String s,String []reserve)
{
int index=-1;
for(int i=0;i<reserve.length;i++)
{
if(s.equals(reserve[i]))
{
index=i;
break;
}
}