Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <i>
- %{
- #include<stdio.h>
- %}
- %token DIGIT
- %%
- S:E'n' {printf("%dn",$1);
- return 1;
- }
- ;
- E:E'+'T {$$ - $1 + $3;}
- |T
- ;
- T:T'*'T {$$ = $1 * $3;}
- |F
- ;
- F:'('E')' {$$ = $2;}
- |DIGIT
- ;
- %%
- yylex()
- {
- int c;
- c = getchar();
- if(isdigit(c))
- {
- yylval = c- '0';
- return DIGIT;
- }
- return c;
- }
- main()
- {
- printf("enter the expression");
- yyparse();
- return 0;
- }
- E:E'+'T {$$ - $1 + $3;}
- T:T'*'T
- T:T'*'F
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement