Facebook
From xd, 6 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 227
  1. %{
  2.         #define NUMBER 1234
  3.         #define PARZYSTA 1
  4.         #define NIEPARZYSTA 78
  5.  
  6.         int wynik_koncowy = 1;
  7.         int attr;
  8. %}
  9.  
  10. LICZBA_P [0-9]*[02468]
  11. LICZBA_NP [0-9]*[13579]
  12.  
  13. %%
  14. {LICZBA_P} {
  15.         attr = atoi(yytext);
  16.         return PARZYSTA;
  17.         }
  18.  
  19. {LICZBA_NP} {
  20.         attr = atoi(yytext);
  21.         return NIEPARZYSTA;
  22. }
  23. .|\n    ;
  24. %%
  25. int main() {
  26.         int result;
  27.         int wynik_koncowy = 1;
  28.         while((result = yylex()))
  29.         {
  30.                 if(result == PARZYSTA) {
  31.                         wynik_koncowy += attr;
  32.                 }
  33.                 if(result == NIEPARZYSTA) {
  34.                         wynik_koncowy *= attr;
  35.                 }
  36.         }
  37.         printf("Wynik koncowy: %d", wynik_koncowy);
  38. }
  39.