Advertisement
Guest User

Untitled

a guest
Nov 4th, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /* (Definitions Section) */
  2. %start program
  3. %token LET INTEGER IN
  4. %token SKIP IF THEN ELSE END WHILE DO READ WRITE
  5. %token NUMBER
  6. %token IDENTIFIER
  7. %left ’-’ ’+’
  8. %left ’*’ ’/’
  9. %right ’ˆ ’
  10.  
  11. %%
  12. /* (Rules Section) */
  13. program : LET declarations IN commands END ;
  14. declarations : /* empty */
  15. | INTEGER id seq IDENTIFIER ’.’
  16. ;
  17. id seq : /* empty */
  18. | id seq IDENTIFIER ’,’
  19. ;
  20. commands : /* empty */
  21. | commands command ’;’
  22. ;
  23. command : SKIP
  24. | READ IDENTIFIER
  25. | WRITE exp
  26. | IDENTIFIER ASSGNOP exp
  27. | IF exp THEN commands ELSE commands FI
  28. | WHILE exp DO
  29. ;
  30. exp : NUMBER
  31. | IDENTIFIER
  32. | exp ’<’ exp
  33. | exp ’=’ exp
  34. | exp ’>’ exp
  35. | exp ’+’ exp
  36. | exp ’−’ exp
  37. | exp ’∗’ exp
  38. | exp ’/’ exp
  39. | exp ’ˆ ’ exp
  40. | ’(’ exp ’)’
  41. ;
  42. %%
  43. /* (C Section) */
  44. main( int argc, char *argv[] )
  45. { extern FILE *yyin;
  46. ++argv; −−argc;
  47. yyin = fopen( argv[0], ”r” );
  48. yydebug = 1;
  49. errors = 0;
  50. yyparse ();
  51. }
  52. yyerror (char *s) /* Called by yyparse on error */
  53. {
  54. printf (”%s\n”, s);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement