fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. DIGIT [0-9]
  6. KEYWORD if|else|while|int
  7. ID [_a-zA-Z][a-zA-Z0-9]*
  8. OP ">"|"<"|"="|"<="|">="|"+"|"-"|"*"|"/"
  9. SC "'"|":"|";"|","|"("|")"
  10.  
  11. %%
  12. {DIGIT}+ { printf("%s is a digit\n", yytext); }
  13. {KEYWORD} { printf("%s is a keyword\n", yytext); }
  14. {ID} { printf("%s is an identifier\n", yytext); }
  15. {OP} { printf("%s is an operator\n", yytext); }
  16. {SC} { printf("%s is a special character\n", yytext); }
  17. [ \t\n]+ { /* skip whitespace */ }
  18. . { printf("%s is an unknown character\n", yytext); }
  19. %%
  20.  
  21. int main()
  22. {
  23. printf("Enter the string:\n");
  24. yylex();
  25. return 0;
  26. }
  27.  
  28. int yywrap()
  29. {
  30. return 1;
  31. }
  32.  
Success #stdin #stdout #stderr 0.02s 6956KB
stdin
int a=5;
stdout
Standard output is empty
stderr
ERROR: /home/nlGfXP/prog:2:1: Syntax error: Operator expected
ERROR: /home/nlGfXP/prog:31:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit