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.

as.y 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. %union {
  2. int nombre;
  3. }
  4. %{
  5. #include "../Tables/tables.h"
  6. #include <stdlib.h>
  7. %}
  8. %token tMUL tDIV tADD tSUB tINF tSUP tEQU
  9. %token tAFC tCPY
  10. %token tLOAD tSTORE tLOADI tSTOREI tSTOREA
  11. %token tJMP tJMZ
  12. %token tGET tPRI
  13. %token tCALL tRET
  14. %token tSTOP
  15. %token<nombre> tNB
  16. %%
  17. // Un programme est une suite d'au moins une instruction
  18. Programme : Instruction Programme;
  19. Programme : Instruction;
  20. // Liste de toutes les instructions et conversion
  21. // MUL, ADD, DIV....
  22. Instruction : tMUL tNB tNB tNB {add_instruction(MUL, $2, $3, $4);};
  23. Instruction : tADD tNB tNB tNB {add_instruction(ADD, $2, $3, $4);};
  24. Instruction : tDIV tNB tNB tNB {add_instruction(DIV, $2, $3, $4);};
  25. Instruction : tSUB tNB tNB tNB {add_instruction(SUB, $2, $3, $4);};
  26. Instruction : tINF tNB tNB tNB {add_instruction(INF, $2, $3, $4);};
  27. Instruction : tSUP tNB tNB tNB {add_instruction(SUP, $2, $3, $4);};
  28. Instruction : tEQU tNB tNB tNB {add_instruction(EQU, $2, $3, $4);};
  29. // AFC R val
  30. Instruction : tAFC tNB tNB {add_instruction(AFC, $2, $3, 0);};
  31. // CPY R1 R2
  32. Instruction : tCPY tNB tNB {add_instruction(CPY, $2, $3, 0);};
  33. // LOAD R @
  34. Instruction : tLOAD tNB tNB {add_instruction(LOAD, $2, $3, 0);};
  35. // STORE @ R
  36. Instruction : tSTORE tNB tNB {add_instruction(STORE, $2, $3, 0);};
  37. // LOADI R R
  38. Instruction : tLOADI tNB tNB {add_instruction(LOADI, $2, $3, 0);};
  39. // STOREI R R
  40. Instruction : tSTOREI tNB tNB {add_instruction(STOREI, $2, $3, 0);};
  41. // STOREA @ R
  42. Instruction : tSTOREA tNB tNB {add_instruction(STORE, $2, $3, 0);};
  43. // JMP Ins
  44. Instruction : tJMP tNB {add_instruction(JMP, $2, 0, 0);};
  45. // JMF @ Ins
  46. Instruction : tJMZ tNB {add_instruction(JMZ, $2, 0, 0);};
  47. // GET @
  48. Instruction : tGET tNB {add_instruction(GET, $2, 0, 0);};
  49. // PRI @
  50. Instruction : tPRI tNB {add_instruction(PRI, $2, 0, 0);};
  51. // CALL Ins Val
  52. Instruction : tCALL tNB tNB {add_instruction(CALL, $2, $3, 0);};
  53. // RET
  54. Instruction : tRET {add_instruction(RET, 0, 0, 0);};
  55. // STOP Val
  56. Instruction : tSTOP tNB {add_instruction(STOP, $2, 0, 0);};
  57. %%
  58. int main(int argc, char * argv[]) {
  59. if (argc != 2) {
  60. printf("Specifiez le fichier à interpreter");
  61. exit(2);
  62. }
  63. extern FILE * yyin;
  64. yyin = fopen(argv[1], "r");
  65. yyparse();
  66. execute();
  67. return 0;
  68. }