%{
#include
#include
#include
%}
%token NUM
%left'-''+'
%left'*''/'
%%
input:
| input line
;
line: '\n'
| exp '\n' { }
;
exp: texp
| exp '+' texp { printf("+ "); }
| exp '-' texp { printf("- "); }
;
texp: fexp
|texp '*' fexp {printf("* ");}
|texp '/' fexp {printf("/ ");}
;
fexp: NUM {printf("%d ",$1);}
| '('exp')'
;
%%
main()
{
printf("\nPlease input your the calculation:\n");
yyparse();
}
yyerror(char *s)
{
printf("error=%s",s);
}
yylex ()
{
int c;
while ((c = getchar ()) == ' ' || c == '\t');
if (isdigit (c))
{
ungetc (c, stdin);
scanf ("%d", &yylval);
return NUM;
}
if (c == EOF)
return 0;
return c;
}
就是不知道 比如我输入5*6+9 他输出是5 6 * 9 +
这个过程具体是怎么样的