Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. %{
  2. int yylex();
  3. void yyerror (char *s);
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. %}
  7.  
  8. %start calculation
  9. %token NUMBER
  10. %token IDENTIFIER
  11.  
  12. %%
  13.  
  14. calculation: expression '\n' {printf("=%d\n", $1); return 0;};
  15. ;
  16. expression: expression '+' NUMBER {$$ = $1 + $3;}
  17. | expression '-' NUMBER {$$ = $1 - $3;}
  18. | expression '*' NUMBER {$$ = $1 * $3;}
  19. | expression '/' NUMBER {$$ = $1 / $3;}
  20. | NUMBER
  21. %%
  22.  
  23.  
  24. int main (void) {
  25. return yyparse();
  26. }
  27.  
  28. void yyerror (char *s) {fprintf (stderr, "%s\n", s);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement