Advertisement
HCHexY

.y

May 6th, 2020
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1.  
  2.  
  3. %{
  4. #include <stdio.h>
  5. #include <string.h>
  6. extern int yylex();
  7. extern int yylineno;
  8. extern char *yytext;
  9. int yyerror();
  10. %}
  11.  
  12. %union{
  13. int ivalue;
  14. char cvalue;
  15. }
  16. %token ERRO HALT PRINT READ SHOW num id
  17. %type <ivalue> num
  18. %type <cvalue> id
  19. %%
  20.  
  21. Calc
  22. : ListaComandos
  23. ;
  24.  
  25. ListaComandos
  26. : ListaComandos Comando
  27. | Comando
  28. ;
  29.  
  30. Comando
  31. : Print
  32. | Read
  33. | Show
  34. | Halt
  35. | Atrib
  36. ;
  37.  
  38. Print
  39. : PRINT Exp
  40. ;
  41.  
  42. Read
  43. : READ id
  44. ;
  45.  
  46. Show
  47. : SHOW
  48. ;
  49.  
  50. Halt
  51. : HALT
  52. ;
  53.  
  54. Atrib
  55. : id '=' Exp
  56. ;
  57.  
  58. Exp
  59. : Exp '+' Termo
  60. | Exp '_' Termo
  61. | Termo
  62. ;
  63.  
  64. Termo
  65. : Termo '/' Fator
  66. | Termo '*' Fator
  67. | Fator
  68. ;
  69.  
  70. Fator
  71. : id
  72. | num
  73. | '(' Exp ')'
  74. ;
  75.  
  76. %%
  77. int main(){
  78. yyparse();
  79. return 0;
  80. }
  81.  
  82. int yyerror(){
  83. printf("Erro Sintático ou Léxico na linha: %d, com o texto: %s\n", yylineno, yytext);
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement