fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. DIGIT [0-9] /* Definition for single digit */
  6. ID [a-zA-Z_][a-zA-Z0-9_]* /* Definition for identifiers: Starts with a letter or underscore, followed by letters, digits, or underscores */
  7. OP [+\-*/=<>] /* Definition for operators: +, -, *, /, =, <, > */
  8.  
  9. %%
  10. {DIGIT} { printf("Digit: %s\n", yytext); }
  11. {ID} { printf("Identifier: %s\n", yytext); }
  12. {OP} { printf("Operator: %s\n", yytext); }
  13. \n { /* Skip newlines */ }
  14. [ \t]+ { /* Skip spaces and tabs */ }
  15. . { printf("Invalid character: %s\n", yytext); } /* Handles invalid characters */
  16. %%
  17.  
  18. int main() {
  19. printf("Enter a string of characters:\n");
  20. yylex();
  21. return 0;
  22. }
  23.  
  24. int yywrap() {
  25. return 1;
  26. }
  27.  
Success #stdin #stdout #stderr 0.02s 6944KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/oTvnLj/prog:2:1: Syntax error: Operator expected
ERROR: /home/oTvnLj/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit