Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. %option noyywrap
  2.  
  3. %{
  4. #include <stdlib.h>
  5. char buf[256];
  6. int count, pos;
  7. %}
  8.  
  9. %x STRING COMMENT
  10.  
  11. %%
  12.  
  13. "{" {
  14. BEGIN(COMMENT);
  15. }
  16. <COMMENT>[^}]*
  17. <COMMENT>"}" {
  18. BEGIN(INITIAL);
  19. }
  20. "'" {
  21. BEGIN(STRING);
  22. }
  23. <STRING>"'" {
  24. printf("%d: %s\n", count, buf);
  25. count = pos = 0;
  26. BEGIN(INITIAL);
  27. }
  28. <STRING>[^\'] {
  29. buf[pos++] = *yytext;
  30. count++;
  31. }
  32. <STRING>"''" {
  33. buf[pos++] = *yytext;
  34. count += 2;
  35. }
  36.  
  37. %%
  38.  
  39. int main()
  40. {
  41. yylex();
  42. getchar();
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment