fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4. %%
  5. "int"|"float"|"char"|"for"|"if"|"else"|"if else"|"return"|"while"|"break"|"double" {printf("keyword:%s\n",yytext);}
  6. [a-zA-Z_][a-zA-Z0-9]* {printf("identifier:%s\n",yytext);}
  7. [0-9]+ {printf("Numbers:%s\n",yytext);}
  8. "+"|"*"|"-"|"/"|"=" {printf("operator:%s\n",yytext);}
  9. "!"|"@"|"#"|"$"|"&"|";"|"," {printf("Special character:%s\n",yytext);}
  10. [ \t\n] ;
  11. . {printf("invalid%s\n",yytext);}
  12. %%
  13. int yywrap()
  14. {
  15. return 1;
  16. }
  17. int main()
  18. {
  19. printf("Enter a string:\n");
  20. yylex();
  21. return 0;
  22. }
  23.  
Success #stdin #stdout #stderr 0.02s 6796KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/EBARzO/prog:2:1: Syntax error: Operator expected
ERROR: /home/EBARzO/prog:22:2: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit