Advertisement
anticlown

Lab #2(lexer)

Dec 10th, 2023 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. //made with flex(GNU)
  2.  
  3.  
  4. %option noyywrap
  5. %{
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. int adminCounter = 0;
  10. int allCounter = 0;
  11. %}
  12.  
  13. %%
  14.  
  15. Admin { printf("Admin"); adminCounter++; allCounter++;}
  16. User { printf("User"); allCounter++;}
  17.  
  18.  
  19. %%
  20.  
  21. int main() {
  22. printf("\tThis program receives a script\n\t\tand returns a percentage of admin`s messages.\n");
  23. printf("\n\t\t\t\tScript:\n\n");
  24. yylex();
  25. printf("\n\nNumber of all messages: %d\n", allCounter);
  26. printf("Number of admin`s messages: %d\n", adminCounter);
  27.  
  28. float ans;
  29. ans = ((double)adminCounter / (double)allCounter) * 100;
  30. printf("Percentage of admin`s messages: %.2f%%\n", ans);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement