No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cross.y 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. %{
  2. #include <stdio.h>
  3. #include "cross_instructions.h"
  4. int yylex();
  5. void yyerror(char*);
  6. int yydebug = 1;
  7. extern int yylineno;
  8. reg_instructions reg_array;
  9. %}
  10. /* Union for yylval */
  11. %union {
  12. int nb;
  13. }
  14. %token tADD tMUL tSOU tDIV tCOP tAFC
  15. %token <nb> tNB
  16. %%
  17. %start File;
  18. File:
  19. Instructions;
  20. Instructions:
  21. /* epsilon */
  22. | Instructions Instruction
  23. ;
  24. Instruction:
  25. tADD tNB tNB tNB
  26. {
  27. add_reg_oriented_instructions(&reg_array,LOAD, 1, $3, 0);
  28. add_reg_oriented_instructions(&reg_array,LOAD, 2, $4, 0);
  29. add_reg_oriented_instructions(&reg_array,ADD, 3, 1, 2);
  30. add_reg_oriented_instructions(&reg_array,STORE, $2, 3, 0);
  31. }
  32. | tMUL tNB tNB tNB
  33. {
  34. add_reg_oriented_instructions(&reg_array,LOAD, 1, $3, 0);
  35. add_reg_oriented_instructions(&reg_array,LOAD, 2, $4, 0);
  36. add_reg_oriented_instructions(&reg_array,MUL, 3, 1, 2);
  37. add_reg_oriented_instructions(&reg_array,STORE, $2, 3, 0);
  38. }
  39. | tSOU tNB tNB tNB
  40. {
  41. add_reg_oriented_instructions(&reg_array,LOAD, 1, $3, 0);
  42. add_reg_oriented_instructions(&reg_array,LOAD, 2, $4, 0);
  43. add_reg_oriented_instructions(&reg_array,SOU, 3, 1, 2);
  44. add_reg_oriented_instructions(&reg_array,STORE, $2, 3, 0);
  45. }
  46. | tDIV tNB tNB tNB
  47. {
  48. add_reg_oriented_instructions(&reg_array,LOAD, 1, $3, 0);
  49. add_reg_oriented_instructions(&reg_array,LOAD, 2, $4, 0);
  50. add_reg_oriented_instructions(&reg_array,DIV, 3, 1, 2);
  51. add_reg_oriented_instructions(&reg_array,STORE, $2, 3, 0);
  52. }
  53. | tCOP tNB tNB
  54. {
  55. add_reg_oriented_instructions(&reg_array,LOAD, 1, $3, 0);
  56. add_reg_oriented_instructions(&reg_array,STORE, $2, 1, 0);
  57. }
  58. | tAFC tNB tNB
  59. {
  60. add_reg_oriented_instructions(&reg_array,AFC, 1, $3, 0);
  61. add_reg_oriented_instructions(&reg_array,STORE, $2, 1, 0);
  62. }
  63. ;
  64. %%
  65. void yyerror(char* str) {
  66. extern int yylineno;
  67. fprintf(stderr, "ERROR yyparse : Line %d: %s\n", yylineno, str);
  68. }
  69. int main(int argc, char *argv[]) {
  70. init_reg_oriented_instructions(&reg_array);
  71. yyparse();
  72. printf("INFO yyparse : Parsing End\n");
  73. output_reg_oriented_instructions(&reg_array);
  74. return 0;
  75. }