Home > Back-end >  Don't know where is wrong
Don't know where is wrong

Time:09-28

Always prompt error C2146: syntax error: missing '; 'before the identifier' I '
Fatal error C1004: unexpected end of file found



# include & lt; stdio.h>
# include & lt; Stdlib. H>
# include & lt; String. H>
# define NULL 0
# define OK 1
# define the ERROR - 1
# define STACK_INIT_SIZE 100
# define STACKINCREMENT 20
# pragma warning (4518) disable:
/* defined character type stack */
Typedef struct {
int stacksize;
Char * base;
Char * top;
} the Stack;
/* define integer stack */
Typedef struct {
int stacksize;
Int * base;
Int * top;
} Stack2;
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a global variable -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
Stack OPTR;/* define operators stack */
Stack2 OPND;/* define the operand stack */
Char expr [255]=""; Deposit/* * expression string/
Char * PTR=expr;

Int InitStack (Stack * s)//Stack structure operator

{
S - & gt; The base=(char *) malloc (STACK_INIT_SIZE * sizeof (char));
if(! S - & gt; Base) return the ERROR;
S - & gt; Top=s - & gt; The base;
S - & gt; Stacksize=STACK_INIT_SIZE;
return OK;
}
Int InitStack2 Stack2 * (s)//constructs the operand stack

{
S - & gt; The base=(int *) malloc (STACK_INIT_SIZE * sizeof (int));
if(! S - & gt; Base) return the ERROR;
S - & gt; Stacksize=STACK_INIT_SIZE;
S - & gt; Top=s - & gt; The base;
return OK;
}
Int (char ch)//In judging character is operator, the operator that returns 1
{
Return (ch=='+' | | ch=='-' | | ch=='*' | | ch=='/' | | ch=='(' | | ch==') '| | ch==' # ');
}
Int Push (Stack * s, char ch)//operator insert ch for the new Stack top element

{
* s - & gt; Top=ch;
S - & gt; Top++;
return 0;
}
Int Push2 Stack2 * s, int (ch)//operand stack element insert ch for the new stack

{
* s - & gt; Top=ch;
S - & gt; Top++;
return 0;
}
Pop (Stack is char * s)//delete operator s of Stack elements, use p returns its value

{
Char p;
S - & gt; Top -;
P=* s - & gt; Top;
return p;
}
Int Pop2 Stack2 * (s)//delete the operand stack s stack elements, use p returns its value

{
Int p;
S - & gt; Top -;
P=* s - & gt; Top;
return p;
}
Char GetTop Stack (s)//p back to operator's Stack top element

{
Char * p=(s.t op - 1);
return p;
}
Int GetTop2 Stack2 (s)//p element returns the operand stack s stack

{
Int p=* (s.t op - 1);
return p;
}
/* operator priority, returns the high priority */

Char Precede (char char c1, c2)

Int I=0, j=0;
The static char array [49]={
'& gt; ', '& gt; ', '<', '<', '<', '& gt; ', '& gt; '
'& gt; ', '& gt; ', '<', '<', '<', '& gt; ', '& gt; '
'& gt; ', '& gt; ', '& gt; ', '& gt; ', '<', '& gt; ', '& gt; '
'& gt; ', '& gt; ', '& gt; ', '& gt; ', '<', '& gt; ', '& gt; '
'<', '<', '<', '<', '<'and'=', '! '
'& gt; ', '& gt; ', '& gt; ', '& gt; ', '! ', '& gt; ', '& gt; '
'<', '<', '<', '<', '<', '! 'and'='};
The switch (c1)
{
/* I for the following array of abscissa */
A case of '+' : I=0; break;
Case '-' : I=1; break;
Case '*' : I=2; break;
Case '/' : I=3; break;
Case '(' : I=4; break;
Case ') : I=5; break;
Case '#' : I=6; break;
}
The switch (c2)
{
/* j in the array of ordinate */
Case '+' : j=0; break;
Case '-' : j=1; break;
Case '*' : j=2; break;
Case '/' : j=3; break;
Case '(' : j=4; break;
Case ') : j=5; break;
Case '#' : j=6; break;
}
Return (array (7 * I + j]);/* return operator */
}
/* * operation function/
Int Operate (int a, char op, int b)
{
The switch (op)
{
Case: '+' return (a + b);
Case '-' : return (a - b);
Case: '*' return (a * b);
Case '/' : return (a/b);
}
return 0;
}
Int num (int n)//returns the length of the operand

{
Char [10] p;

Itoa (n, p, 10);//convert the integer to a string type


N=strlen (p);

Return n.
}
Int EvalExpr ()//major operating function

{
Char c, theta, x; Int n, m;
int a,b;
C=* ptr++;
While (c!='#' | | GetTop (OPTR)!='#')
{
if(! In (c))
{ if(! (*) (PTR - 1)) In PTR=PTR - 1;
M=atoi (PTR);//take a string in front of the Numbers to

N=num (m);
Push2 (& amp; OPND, m);
PTR=PTR + n.
C=* ptr++;
}
The else
The switch (Precede (GetTop (OPTR), c))
{
Case '& lt; ':
Push (& amp; OPTR, c);
C=* ptr++;
break;
Case: '='
X=Pop (& amp; OPTR);
C=* ptr++;
break;
Case '& gt; ':
Theta=Pop (& amp; OPTR);
B=Pop2 (& amp; OPND); A=Pop2 (& amp; OPND);
Push2 (& amp; OPND to Operate (a, theta, b));
break;
}
}
Return GetTop2 (OPND);
}
Int main ()
{
Printf (" please input the correct expression end with a '#' : ");
Do {
Gets (expr);
}while(! * expr);
InitStack (& amp; OPTR);/* stack initialization operator */
Push (& amp; OPTR, '#'); Press the #/* into the stack operator */
InitStack2 (& amp; OPND);/* initializes the operand stack */
Printf (" expression result is: % d \ n ", EvalExpr ());
return 0;
}

CodePudding user response:

Char Precede (char char c1, c2) behind the less a semicolon;

CodePudding user response:

And post code you can use the format, the drop down menu on the left side of the smiling face icon icon Angle brackets,
  • Related