Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. %{
  2. void yyerror (char *s);
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. yydebug=1;
  6. %}
  7. %token BEGINT ENDT PROGRAM OUTPUT INPUT IDENTIFIER INT
  8.  
  9. %%
  10. program : PROGRAM declaration_s BEGINT statement_s ENDT ';' {printf("This is a valid program.\n");
  11. exit(0);
  12. }
  13. ;
  14. declaration_s : type ':' IDENTIFIER declaration
  15. ;
  16. type : INT
  17. ;
  18. declaration : ',' IDENTIFIER declaration
  19. | ';'
  20. ;
  21. statement_s : assign_statement
  22. | output_statement
  23. | input_statement
  24. ;
  25. assign_statement : IDENTIFIER '=' expression ';'
  26. ;
  27. output_statement : OUTPUT IDENTIFIER declaration
  28. ;
  29. input_statement : INPUT IDENTIFIER declaration
  30. ;
  31. expression : expression '+' IDENTIFIER
  32. | IDENTIFIER
  33. ;
  34. %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement