madvice

comments.l

Nov 19th, 2025 (edited)
63
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | Source Code | 0 0
  1. letter          [a-zA-Z]
  2. digit           [0-9]
  3.  
  4. %{
  5.     #include <stdio.h>    
  6. %}
  7.  
  8. %x comment
  9.  
  10. %%
  11.  
  12. "/*"                            {BEGIN(comment); printf("Comment started\n");}
  13. <comment>[^*]*                  { }
  14. <comment>"*"+[^*/]*             { }
  15. <comment>"*"+"/"                {BEGIN(INITIAL); printf("Comment Ended\n");}
  16.  
  17. {letter}({letter}|{digit})*     {printf("identifier scanned: %s\n", yytext);}
  18.  
  19. [ \t\n]+                       { }
  20. .                              { }
  21.  
  22. %%
  23.  
  24. int yywrap() {
  25.     return 1;
  26. }
  27.  
  28. int main()
  29. {
  30.     yylex();
  31. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment