fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. char targetWord[] = "jai";
  6. int wordPosition = 0;
  7. %}
  8.  
  9. %%
  10.  
  11. [a-zA-Z]+ {
  12. if (strcmp(yytext, targetWord) == 0) {
  13. printf("Found '%s' at position %d.\n", yytext, wordPosition);
  14. }
  15. wordPosition++;
  16. }
  17.  
  18. [ \t\n]+ ;
  19.  
  20. . {
  21.  
  22. }
  23.  
  24. %%
  25.  
  26. int main() {
  27. printf("Enter a sentence: ");
  28. yylex();
  29. return 0;
  30. }
  31.  
  32.  
  33. int yywrap()
  34. {
  35. return 1;
  36. }
Success #stdin #stdout #stderr 0.03s 6892KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/4ztGYr/prog:2:1: Syntax error: Operator expected
ERROR: /home/4ztGYr/prog:36:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit