Advertisement
bokunda

FJAJP

May 29th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // LEX
  2.  
  3. %{
  4. #include <stdio.h>
  5. #include "y.tab.h"
  6. extern int yyline;
  7. %}
  8.  
  9. %%
  10. [0-9][0-9]* { yylval.cbroj = atoi(yytext); return CBROJ; }
  11. "ZAR" { return ZAR; }
  12. . { return yytext[0]; }
  13. \n { yyline++; }
  14. %%
  15.  
  16.  
  17. // YACC
  18. %{
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. int yyline;
  22. int yylex();
  23. %}
  24.  
  25. %union
  26. {
  27. int cbroj;
  28. }
  29. %start program
  30. %token <cbroj> CBROJ ZAR
  31.  
  32. %%
  33. program : kraj
  34. kraj : CBROJ ' ' ZAR { printf("%d", $1);}
  35. %%
  36.  
  37. int yyerror(char *s)
  38. {
  39. printf("Error %s, %d\n", s, yyline);
  40. }
  41.  
  42. int main()
  43. {
  44. extern FILE *yyin;
  45. yyin = fopen("input.txt", "r");
  46. if (yyparse() == 0) { printf("Ok"); }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement