Home > Back-end >  For bosses to help buy can only judge grammar without parentheses for example: I * I i#, once the br
For bosses to help buy can only judge grammar without parentheses for example: I * I i#, once the br

Time:09-17

The static char a []=new char [50];
The static char [] b=new char [50].
The static char [] d=new char [200];
The static char [] e=new char [50];
The static char ch;
The static String ch1=new String ();
Static int n1, i1=0, flag=1, n=5;
Static int total=0; Public static void main (String [] args) {int f, p, j=0; Char x; D [0]='E'; D [1]==' '; D [2]='& gt; '; D [3]='T'; D [4]='G'; D [5]='#'; System. Out. Println (" please input the length is not more than 50 and and # # of the end of the string: "); Scanner sc=new Scanner (System. In); Ch1=sc. NextLine (); Do {ch=ch1. CharAt (j); A [j]=ch; J++;
//System. Out. Println (a [j] + "-"); } while (ch!='#'); N1=j; Ch=b [0]=[0]; System. The out. Println (" step \ \ t t grammar analysis string t \ \ t t \ \ t remaining string of characters "); F=E1 (); If (f==0) return; If (ch=='#') {System. Out. Println (" Accept! Right Expression!" ); P=0; X=d [p]. While (x!='#') {System. Out. Print (x); P=p + 1; X=d [p]. }} else {System. Out. Println (" Error!!! "); System. The out. Println (" return return "); return; } System. Out. Println ();
} the static int E1 () {int f, t; System. The out. Print (total + "\ tE - & gt; TG \ t "); Total++; flag=1; The input (); Input1 (); F=(T); If (f==0) return 0; T=G (); If (t==0) return 0; The else return 1; {} static int (E)
Int f, t;
System. The out. Print (total + "\ tE - & gt; TG \ t ");
Total++;
E [0]='e'; E [1]==' '; E [2]='& gt; '; E [3]='T'; E [4]='G'; E [5]='#';
The output ();
flag=1;
The input ();
Input1 ();
F=f ();
If (f==0) return 0;
T=G ();
If (t==0) return 0;
The else return 1; }

Static int (T) {
Int f, t;
System. The out. Print (total + "\ tT - & gt; FS \ t ");
Total++;
E [0]='T'. E [1]==' '; E [2]='& gt; '; E [3]='F'; E [4]='S'. E [5]='#';
The output ();
flag=1;
The input ();
Input1 ();
F=f ();
If (f==0) return 0;
T=S ();
If (t==0) return 0;
The else return 1;
}
//E '- & gt; + TE '
Static int G () {
Int f;
If (ch=='+') {b [i1]=ch; System. The out. Print (total + "\ tG - & gt; TG + \ t "); Total++; E [0]='G'; E [1]==' '; E [2]='& gt; '; E [3]='+'; E [4]='T'. E [5]='G'; E [6]='#'; The output (); flag=0; The input (); Input1 (); Ch=a [+ + i1]; F=(T); If (f==0) return 0; (G); Return 1;
}
System. The out. Print (total + "\ tG - & gt; ^ \ t ");
Total++;
E [0]='G'; E [1]==' '; E [2]='& gt; '; E [3]='^'; E [4]='#';
The output ();
flag=1;
The input ();
Input1 ();
return 1;
}
Static int S () {int f, t;
If (ch=='*') {b [i1]=ch; System. The out. Print (total + "\ tS - & gt; * FS \ t "); Total++; E [0]='S'. E [1]==' '; E [2]='& gt; '; E [3]='*'; E [4]='F'; E [5]='S'. E [6]='#'; The output (); flag=0; The input (); Input1 (); Ch=a [+ + i1]; F=f (); If (f==0) return 0; T=S (); If (t==0) return 0; The else return 1; } System. Out. Print (total + "\ tS - & gt; ^ \ t "); Total++; E [0]='S'. E [1]==' '; E [2]='& gt; '; E [3]='^'; E [4]='#'; The output (); flag=1; A [i1]=ch; The input (); Input1 (); return 1; }
Static int F () {
Int f;
If (ch=='(') {b [i1]=ch; System. The out. Print (total + "\ tF - & gt; (E) \ t "); Total++; E [0]='F'; E [1]==' '; E [2]='& gt; '; E='(' [3]; E [4]='e'; E [5]='); E [6]='#'; The output (); flag=0; The input (); Input1 (); Ch=a [+ + i1]; F=(E); If (f==0) return 0; If (ch==') ') {b [i1]=ch; System. The out. Print (total + "\ tF - & gt; (E) \ t "); Total++; flag=0; The input (); Input1 (); Ch=a [+ + i1]; } else {System. Out. The println (); System. Out.println (" Error!!!!!! "); return 0; }} else if (ch=='I') {b [i1]=ch; System. The out. Print (total + "\ tF - & gt; I \ t "); Total++; E [0]='F'; E [1]==' '; E [2]='& gt; '; E [3]='I'; E [4]='#'; The output (); flag=0; The input (); Input1 (); Ch=a [+ + i1]; }
The else {System. Out. Println (); System. Out.println (" Error!" ); return 0;
}
return 1;
}
The static void input () {
Int j=0;
for(; j<=i1 - flag; J++)
System. The out. Print (b [j]);
System. The out. Print (" t \ \ t ");
System. The out. Print (ch + "t \ \ t"); }
The static void input1 () {
Int j;
For (j=i1 + 1 - flag; jSystem.out.println();
}
The static void the output () {
Int j, k, j, q;
int i=0;
M=0; k=0; Q=0;
I=n;
D [n]==' '; D (n + 1)='& gt; ';
D [n + 2]='#';
N=n + 2;
I=n;
I=I - 2;
While (d [I]!='& gt; '& amp; & i!=0) {I=I - 1;
}
i=i+1; While (d [I]!=e [0]) {I=I + 1;
} q=I;
M=q; K=q;
While (d [m].='& gt; ')
{m=m - 1; }
M=m + 1;
While (m! Q)={d [n]=d [m]. M=m + 1; N=n + 1; }
D [n]='#';
For (j=3; E [j].='#'; J++) {d [n]=e [j]; N=n + 1;
}
K=k + 1;
While (d [k]! [n]='=') {d=d [k]. N=n + 1; K=k + 1;
}
D [n]='#';
}
  • Related