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 606B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. %union {
  2. int nombre;
  3. }
  4. %token tMAIN
  5. %token tOBRACKET tCBRACKET
  6. %token tOBRACE tCBRACE
  7. %token tINT
  8. %token tCONST
  9. %token tPV tCOMA
  10. %token tMUL tDIV tADD tSUB tEQ
  11. %token<nombre> tNB tNBEXP
  12. %token tPRINTF
  13. %token tERROR
  14. //%type<nombre> E
  15. /* 1 + 2 + 3 + 4 */
  16. /* E => E + E => 1 + E => 1 + E + E ... */
  17. /* E => E + E => E + 4 => E + E + 4 ... */
  18. %%
  19. /* S -> E ; S
  20. * S ->
  21. */
  22. S : E tPV
  23. { printf("RES: %d\n", $1); }
  24. S
  25. | { printf("END\n"); }
  26. ;
  27. E : E tADD E { $$ = $1 + $3; }
  28. | E tSUB E { $$ = $1 - $3; }
  29. | tOB E tCB { $$ = $2; }
  30. | tNB { $$ = $1; }
  31. ;
  32. %%
  33. void main(void) {
  34. yyparse();
  35. }