fork download
  1. %{
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. %}
  6.  
  7. %%
  8.  
  9. /* Objective 1: Extract numbers */
  10. [0-9]+ { printf("%s\n", yytext); }
  11.  
  12. /* Objective 2: Replace 'charusat' with 'university' */
  13. [Cc]harusat { printf("university"); }
  14.  
  15. /* Objective 3: Count characters, words, and lines */
  16. . { char_count++; }
  17. \n { line_count++; word_count++; }
  18. [ \t]+ { word_count++; }
  19.  
  20. /* Objective 4: Password validation */
  21. ^[a-zA-Z0-9*;#$@]{9,15}$ {
  22. int has_upper = 0, has_lower = 0, has_digit = 0, has_symbol = 0;
  23. for (int i = 0; i < yyleng; i++) {
  24. if (isupper(yytext[i])) has_upper = 1;
  25. if (islower(yytext[i])) has_lower = 1;
  26. if (isdigit(yytext[i])) has_digit = 1;
  27. if (strchr("*;#$@", yytext[i])) has_symbol = 1;
  28. }
  29. if (has_upper && has_lower && has_digit && has_symbol) {
  30. printf("Valid password\n");
  31. } else {
  32. printf("Invalid password\n");
  33. }
  34. }
  35.  
  36. %%
  37.  
  38. int char_count = 0, word_count = 1, line_count = 0;
  39.  
  40. int main() {
  41. yylex();
  42. printf("Characters: %d\n", char_count);
  43. printf("Words: %d\n", word_count);
  44. printf("Lines: %d\n", line_count);
  45. return 0;
  46. }
  47.  
  48. int yywrap() {
  49. return 1;
  50. }
Success #stdin #stdout #stderr 0.03s 6952KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/R1o2P8/prog:2:1: Syntax error: Operator expected
ERROR: /home/R1o2P8/prog:50:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit