Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. <i>
  2. %{
  3. #include<stdio.h>
  4. %}
  5. %token DIGIT
  6. %%
  7. S:E'n' {printf("%dn",$1);
  8. return 1;
  9. }
  10. ;
  11. E:E'+'T {$$ - $1 + $3;}
  12. |T
  13. ;
  14. T:T'*'T {$$ = $1 * $3;}
  15. |F
  16. ;
  17. F:'('E')' {$$ = $2;}
  18. |DIGIT
  19. ;
  20. %%
  21. yylex()
  22. {
  23. int c;
  24. c = getchar();
  25. if(isdigit(c))
  26. {
  27. yylval = c- '0';
  28. return DIGIT;
  29. }
  30. return c;
  31. }
  32. main()
  33. {
  34. printf("enter the expression");
  35. yyparse();
  36. return 0;
  37. }
  38.  
  39. E:E'+'T {$$ - $1 + $3;}
  40.  
  41. T:T'*'T
  42.  
  43. T:T'*'F
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement