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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. %union {
  2. int nombre;
  3. char id[30];
  4. }
  5. %{
  6. #include <stdio.h>
  7. %}
  8. %token tMAIN
  9. %token tOBRACKET tCBRACKET
  10. %token tOBRACE tCBRACE
  11. %token tINT
  12. %token tCONST
  13. %token tPV tCOMA
  14. %token tMUL tDIV tADD tSUB tEQ
  15. %token<nombre> tNB tNBEXP
  16. %token<id> tID
  17. %token tPRINTF
  18. %token tERROR
  19. %token tIF tWHILE tELSE
  20. %token tLT tGT tEQCOND
  21. %token tAND tOR
  22. //%type<nombre> E
  23. %%
  24. Main : tINT tMAIN tOBRACE Params tCBRACE Body { printf("Main reconnu\n"); } ;
  25. Params : { printf("Sans Params\n"); } ;
  26. Params : Param SuiteParams ;
  27. Param : tINT tID { printf("Prametre : %s\n", $2); };
  28. SuiteParams : tCOMA Param SuiteParams ;
  29. SuiteParams : ;
  30. Body : tOBRACKET Instructions tCBRACKET { printf("Body reconnu\n"); } ;
  31. Instructions : Instruction Instructions ;
  32. Instructions : ;
  33. Instruction : Aff ;
  34. Instruction : Decl ;
  35. Instruction : Invocation tPV ;
  36. Instruction : If;
  37. Instruction : While;
  38. If : tIF tOBRACE Cond tCBRACE Body Else { printf("If reconnu\n"); };
  39. Else : tELSE If { printf("Else if reconnu\n"); };
  40. Else : tELSE Body { printf("Else reconnu\n"); };
  41. Else : ;
  42. While : tWHILE tOBRACE Cond tCBRACE Body { printf("While reconnu\n"); };
  43. Cond : E SuiteCond ;
  44. SuiteCond : ;
  45. SuiteCond : tAND E SuiteCond;
  46. SuiteCond : tOR E SuiteCond;
  47. Aff : tID tEQ E tPV { printf("%s prend une valeur\n", $1); } ;
  48. E : tNB ;
  49. E : tNBEXP ;
  50. E : tID ;
  51. E : E tADD E ;
  52. E : E tMUL E ;
  53. E : E tSUB E ;
  54. E : E tDIV E ;
  55. E : Invocation ;
  56. E : tOBRACE E tCBRACE ;
  57. E : tSUB E ;
  58. E : E tEQCOND E;
  59. E : E tGT E;
  60. E : E tLT E;
  61. Decl : tINT tID SuiteDecl FinDeclaration { printf("Declaration de %s\n", $2); } ;
  62. Decl : tCONST tINT tID SuiteDecl tEQ E tPV { printf("Declaration de %s (CONSTANTE)\n", $3); } ;
  63. SuiteDecl : tCOMA tID SuiteDecl { printf("Declaration de %s\n", $2); } ;
  64. SuiteDecl : ;
  65. FinDeclaration : tEQ E tPV { printf("Declaration avec valeur\n"); };
  66. FinDeclaration : tPV { printf("Declaration sans valeur\n"); };
  67. Invocation : tPRINTF tOBRACE tID tCBRACE { printf("Appel de printf sur %s\n", $3); } ;
  68. /*S : E tPV
  69. { printf("RES: %d\n", $1); }
  70. S
  71. | { printf("END\n"); }
  72. ;
  73. E : E tADD E { $$ = $1 + $3; }
  74. | E tSUB E { $$ = $1 - $3; }
  75. | tOB E tCB { $$ = $2; }
  76. | tNB { $$ = $1; }
  77. ;*/
  78. %%
  79. #include <stdio.h>
  80. void main(void) {
  81. yyparse();
  82. }