Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. %option noyywrap
  2.  
  3. %{
  4.     int Nr=1;
  5.     int Licz=0;
  6.     int pom = 0;
  7.     char liczby = '0';
  8.     void komunikat1(char);
  9.     void komunikat2();
  10.     void komunikat3();
  11.     void komunikat4();
  12. %}
  13.  
  14. %start slc10
  15. %start slc16
  16. %start slrst
  17. %start slrzm
  18. %start blad
  19. Lc10 [0-9]+
  20. Lc16 [0-9A-F]+
  21. Lrst [0-9]+\.[0-9]+
  22. Lrzm [0-9]+\.[0-9]+E(\+|\-)[0-9]+
  23.  
  24. %%
  25. <INITIAL>{Lc10} {Licz++; BEGIN(slc10); };
  26. <INITIAL>{Lc16} {Licz++; BEGIN(slc16); };
  27. <INITIAL>{Lrst} {Licz++; BEGIN(slrst); };
  28. <INITIAL>{Lrzm} {Licz++; BEGIN(slrzm); };
  29. <INITIAL>\n {komunikat2(); };
  30.  
  31. <slc10>{Lc10} {Licz++; BEGIN(slc10); };
  32. <slc10>{Lc16} {komunikat3(); };
  33. <slc10>{Lrst} {komunikat3(); };
  34. <slc10>{Lrzm} {komunikat3(); };
  35. <slc10>\n {komunikat1('a'); };
  36.  
  37. <slc16>{Lc10} {komunikat3(); };
  38. <slc16>{Lc16} {Licz++; BEGIN(slc16); };
  39. <slc16>{Lrst} {komunikat3(); };
  40. <slc16>{Lrzm} {komunikat3(); };
  41. <slc16>\n {komunikat1('b'); };
  42.  
  43. <slrst>{Lc10} {komunikat3(); };
  44. <slrst>{Lc16} {komunikat3(); };
  45. <slrst>{Lrst} {Licz++; BEGIN(slrst); };
  46. <slrst>{Lrzm} {komunikat3(); };
  47. <slrst>\n {komunikat1('c'); };
  48.  
  49. <slrzm>{Lc10} {komunikat3(); };
  50. <slrzm>{Lc16} {komunikat3(); };
  51. <slrzm>{Lrst} {komunikat3(); };
  52. <slrzm>{Lrzm} {Licz++; BEGIN(slrzm); };
  53. <slrzm>\n {komunikat1('d'); };
  54.  
  55. [\r\t]  ;
  56. %%
  57.  
  58. void komunikat1(char c)
  59. {
  60.     printf("wiersz: %d; liczby: %c; ilosc: %d\n", Nr++, c, Licz);
  61.     Licz=0;
  62.     BEGIN INITIAL;
  63. }
  64.  
  65. void komunikat2()
  66. {
  67.     printf("To jest wiersz pusty\n");
  68.     Nr++;
  69.     BEGIN INITIAL;
  70. }
  71.  
  72. void komunikat3()
  73. {
  74.     printf("Wiersz ma niejednorodna postac\n");
  75.     Nr++;
  76.     Licz++;
  77.     BEGIN INITIAL;
  78. }
  79.  
  80. void komunikat4()
  81. {
  82.     printf("To nie jest liczba kategorii a, b, c lub d\n");
  83.     Nr++;
  84.     BEGIN INITIAL;
  85. }
  86.  
  87. int main()
  88. {
  89.     yylex();
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement