fork download
  1.  
  2. %option noyywrap
  3. %{
  4. #include<stdio.h>
  5. void yyerror(char *);
  6. %}
  7. letter [a-z A-Z]
  8. digit [0-9]
  9. op [-+*]
  10. %%
  11. else|int|float {printf("%s is a keyword",yytext);}
  12.  
  13. {digit}+ {printf("%s is a number",yytext);}
  14. {letter}({letter}|{digit})* {printf("%s is an identifier",yytext);}
  15. {op}+ {printf("%s is an operator",yytext);}
  16. . yyerror("error");
  17. %%
  18. void yyerror(char *s)
  19. {
  20. fprintf(stderr,"%s\n",s);
  21. }
  22. int main()
  23. {
  24. yylex();
  25. return 0;
  26. }
  27.  
Success #stdin #stdout #stderr 0.03s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/htEJxs/prog:4:9: Syntax error: Operator expected
ERROR: /home/htEJxs/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit