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

📄 by.java

📁 此程序使用在java环境下开发的
💻 JAVA
字号:
package bianyi;import java.io.*;import java.util.*;public class BY {    public static void main(String[] args) throws IOException {     String cache;     int x=0;     Queue<String> words=new LinkedList<String>();     DefinitionList.setdoubleDelimiter();     DefinitionList.setreserved();     DefinitionList.setsingledelimiter();     File readSource=new File("Hello.txt");     File errorMessage=new File("Error.txt");    if(!errorMessage.exists())  errorMessage.createNewFile();     PrintWriter puterror=new PrintWriter(new FileOutputStream(errorMessage));     File code=new File("Code.txt");     if(!code.exists()) code.createNewFile();     PrintWriter putCode=new PrintWriter(new FileOutputStream(code));     File divided=new File("divided.txt");     if(!divided.exists())  divided.createNewFile();     PrintWriter putwords=new PrintWriter(new FileOutputStream(divided));      System.out.println(readSource.getAbsolutePath());      Scanner in = new Scanner(readSource);       cache="";       int line=0;     while (in.hasNextLine())     {      line++;            String temp = in.nextLine();            int h=0,t=2,i=1,m=temp.length();            while(t<temp.length())                 { if(temp.substring(h,t).equals("/*")) {i*=-1;m=h;break;}h++;t++;                    }            while(t<temp.length())                 { if(temp.substring(h,t).equals("*/")) {i*=-1;}h++;t++;                    }             if(i<0)               {puterror.print("错误"+"\r\t"+"第"+line+"行注释出错"+"\r\n");                 }                temp=temp.substring(0,m);            h=0;t=h;i=1;           while(h<temp.length())                  { if(temp.charAt(h)=='"') {i*=-1;t=h;}h++;                     }            if(i<0)                 {                 puterror.print("错误"+"\r\t"+"第"+line+"行字符串常数错误,缺少引号"+"\r\n");                  String temp2="";                  while(temp.charAt(t)!=')'&&temp.charAt(t)!=';')                          {t++;}                  temp2=temp.substring(t,temp.length());temp=temp.substring(0,t);                  temp+='"';                  temp+=temp2;                 }            h=0;            while(h<temp.length())            {  if(!(Judge.figure(temp.charAt(h))||Judge.letter(temp.charAt(h))||Judge.denotation(temp.charAt(h))||temp.charAt(h)==' '))                  {m=h+1;                   puterror.print("错误"+"\r\t"+"第"+line+"行第"+m+"列出现非法符号"+temp.charAt(h)+"\r\n");                   String temp2=temp.substring(h+1,temp.length());temp=temp.substring(0,h);                   temp+=temp2;                  }               h++;            }           h=0;            while(h<temp.length()-1)            {  if(Judge.figure(temp.charAt(h))&&Judge.letter(temp.charAt(h+1)))                  {m=h;                   puterror.print("错误"+"\r\t"+"第"+line+"行第"+m+"列出现非法标识符"+temp.substring(h,h+2)+"\r\n");                   String temp2=temp.substring(h+1,temp.length());temp=temp.substring(0,h+1);                   temp+=';';                   temp+=temp2;                   }               h+=1;            }            cache += temp;            }       puterror.close();       System.out.println(cache);      int head=0,tail=1;      while(tail<cache.length())       {            if(cache.charAt(head)==' ')             { while(cache.charAt(tail)==' ')                  { tail++;}               head=tail;tail++;              }         if(Judge.letter(cache.charAt(head)))            { while(Judge.letter(cache.charAt(tail))||Judge.figure(cache.charAt(tail)))                    {tail++;}              words.offer(cache.substring(head,tail));              x++;              putwords.print(x+"\t");              putwords.print(cache.substring(head,tail)+"\r\n");head=tail;tail++;             }         if(Judge.figure(cache.charAt(head)))             { while(Judge.figure(cache.charAt(tail)))                   {tail++;}               words.offer(cache.substring(head,tail));              x++;               putwords.print(x+"\t");              putwords.print(cache.substring(head,tail)+"\r\n");head=tail;tail++;              }         if(Judge.denotation(cache.charAt(head)))             { if(Judge.denotation(cache.charAt(tail))&&DefinitionList.doubledelimiter.contains(cache.substring(head,tail+1)))                   {tail++;}               words.offer(cache.substring(head,tail));              x++;               putwords.print(x+"\t");               putwords.print(cache.substring(head,tail)+"\r\n");head=tail;tail++;              }         if(cache.charAt(head)=='"')             { words.offer(cache.substring(head,tail));              x++;               putwords.print(x+"\t");               putwords.print(cache.substring(head,tail)+"\r\n");head=tail;tail++;               while(cache.charAt(tail)!='"')               {                 tail++;}               words.offer(cache.substring(head,tail));              x++;               putwords.print(x+"\t");               putwords.print(cache.substring(head,tail)+"\r\n");head=tail;tail++;               words.offer(cache.substring(head,tail));              x++;               putwords.print(x+"\t");               putwords.print(cache.substring(head,tail)+"\r\n");head=tail;tail++;              }       }       words.offer(cache.substring(head,tail));              x++;       putwords.print(x+"\t");       putwords.print(cache.substring(head,tail)+"\r\n");       putwords.close();        System.out.println(words);       int a=10;      String str;        while((str=words.poll())!=null){         if (DefinitionList.reserved.contains(str))           {     putCode.print(str+"\t\t\t");                putCode.print("(" + (DefinitionList.reserved.indexOf(str) + 1) + ", -)" +"\r\n");            }         else if(!DefinitionList.reserved.contains(str)&&(Judge.letter(str.charAt(0))))            {   putCode.print(str+"\t\t\t");                DefinitionList.setidentifier(str);                putCode.print("(34,"+(DefinitionList.identifier.indexOf(str)+1)+")"+"\r\n");            }         if ((Judge.figure(str.charAt(0))))             {   putCode.print(str+"\t\t\t");                DefinitionList.setfigure(str);                putCode.print("(36,"+(DefinitionList.figure.indexOf(str)+1)+")"+"\r\n");            }            if (DefinitionList.singledelimiter.contains(str))                {    putCode.print(str+"\t\t\t");                    putCode.print("("+(DefinitionList.singledelimiter.indexOf(str)+39)+",-)"+"\r\n"); //单字符39-58;                }             if (DefinitionList.doubledelimiter.contains(str))                 {   putCode.print(str+"\t\t\t");                    putCode.print("("+(DefinitionList.doubledelimiter.indexOf(str)+59)+",-)"+"\r\n");  //双字符59-68;                }                }           putCode.close();         }   }

⌨️ 快捷键说明

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