Private Static voidSearchChar[] ch) {String s= "" ; intDe = 0; CharA; BooleanIsimport =false;//is a keyword BooleanIsnum =false;//Is a number BooleanIsid =false;//Is a string BooleanIsbi=false;//is a single operator BooleanIsbim =false;//is the dog for the combination operatorString[] Proter = {"int", "main", "char", "if", "Else", "for", "while" }; inti = 0; while(I <ch.length) {String PR= ""; while(Ch[i]! = " ){ if((Ch[i] <= ' z ') && (ch[i]>= ' a ') | | (Ch[i] <= ' Z ') && (ch[i] >= ' A ')) //System.out.print (Ch[i]);Isid =true; if((ch[i]<= ' 9 ') && (ch[i]>= ' 0 '))) //System.out.print (Ch[i]);Isnum =true; Switch(Ch[i]) { Case=: if(ch[i+1] = = ' = ') {de=39; S="=="; Isbim=true; I++; //System.out.print (s); } Elsede= 21; IsBi=true; Break; Case' > ': if(ch[i+1] = = ' = ') {de=37; S= ">="; Isbim=true; I++; //System.out.print (s); } Elsede=35; IsBi=true; Break; Case‘]‘: De=29; IsBi=true; Break; Case‘{‘: De=30; IsBi=true; Break; Case‘}‘: De=31; IsBi=true; Break; Case‘:‘: De=33; IsBi=true; Break; Case‘;‘: De=34; IsBi=true; Break; Case‘.‘: De=32; IsBi=true; Break; Case' < ': if(ch[i+1] = = ' = ') {de=38; S= "<="; Isbim=true; I++; //System.out.print (s); } Elsede=36; IsBi=true; Break; Case‘*‘: De=24; IsBi=true; Break; Case+: De=22; IsBi=true; Break; Case‘-‘: De=23; IsBi=true; Break; Case‘/‘: De=25; IsBi=true; Break; Case‘(‘: De=26; IsBi=true; Break; Case‘)‘: De=27; IsBi=true; Break; Case‘#‘: De=0; IsBi=true; Break; } if((ch[i] = = '! ') && (ch[i+1] = = ' = ')) ) {de=40; S="!="; Isbim=true; I++; } if(isBi) { Break; } PR+ = ch[i++]; } //System.out.print (PR); ////Judging Keywords for(intj = 0; J < Proter.length; J + +) { if(Pr.equals (Proter[j])) {Isimport=true; System.out.println ("(" + (j + 1) + "," + proter[j] + ")"); } } //letters or alphanumeric strings if(Isid &&!)Isimport) System.out.println ("(" +10+ "," + pr+ ")"); //Digital if(!isid &&isnum) System.out.println ("(" +20+ "," + pr+ ")"); //Single special symbol if(IsBi &&!)Isbim) System.out.println ("(" +de+ "," +ch[i]+ ")"); //Combo Symbol if(Isbim) System.out.println ("(" +de+ "," +s+ ")"); //Else System.out.println ("(" +-1+ "," + "Erro" + ")");i++; Isid=false; Isnum=false; Isimport=false; IsBi=false; Isbim=false; //System.out.print ("(" +); } }
Simple lexical analyzer