import java.util.regex.*;
import java.util.*;
import java.io.*;
public class project_1{
public static void main(String args[]) throws Exception{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String x=input.readLine();
x=x.trim();
String [] s=x.split(" ");
for(int i=0;i<s.length;i++){
int start=0,end=s[i].length()-1;
String a;
while( start <= end ){
a=s[i].substring(start,end+1);
//System.out.println("++++++++++++++"+a+" start="+start+" end="+end);
int temp=Choose(a);
if(temp>0 && temp<15){
System.out.println(a+" "+temp );
start=end+1;
end=s[i].length()-1;
}else{
end--;
}
}
}
}
public static int Choose(String x){
String str="[a-zA-Z_][\\w]*";
String str2="[\\d]*";
if("DIM".equals(x)){
return 1;
}else if("IF".equals(x)){
return 2;
}else if("DO".equals(x)){
return 3;
}else if("STOP".equals(x)){
return 4;
}else if("END".equals(x)){
return 5;
}else if(x.matches(str)){
return 6;
}else if(x.matches(str2)){
return 7;
}else if("=".equals(x)){
return 8;
}else if("+".equals(x)){
return 9;
}else if("*".equals(x)){
return 10;
}else if("**".equals(x)){
return 11;
}else if(",".equals(x)){
return 12;
}else if("(".equals(x)){
return 13;
}else if(")".equals(x)){
return 14;
}else{
return 15;
}
}
}
Java简单词法分析器
最新推荐文章于 2021-04-25 19:31:38 发布