fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %option noyywrap
  6.  
  7. %%
  8. [0-9]+ { printf("Number: %s\n", yytext); }
  9. [+\-*/] { printf("Operator: %s\n", yytext); }
  10. [a-zA-Z][a-zA-Z0-9]* { printf("Identifier: %s\n", yytext); }
  11. [ \t\n] ; /* Ignore whitespace */
  12. . { printf("Invalid character: %s\n", yytext); }
  13. %%
  14.  
  15. int main() {
  16. printf("Enter an arithmetic expression: ");
  17. yylex(); // Process the input
  18. return 0;
  19. }
  20.  
  21. int yywrap() {
  22. return 1;
  23. }
  24.  
Success #stdin #stdout #stderr 0.02s 6820KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/cL7Jne/prog:2:1: Syntax error: Operator expected
ERROR: /home/cL7Jne/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit