fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4. digit ([0-9])
  5. letter ([a-zA-Z])
  6. id {letter}({letter}|{digit})*
  7. num ([0-9]+)
  8. keywords (if|else|while|and|or|print|elif|char|float)
  9. punctuation (["(" | ")" | "{" , "}" | ";" | ","])
  10. operators ([+*/-=^])
  11.  
  12. %%
  13. {id} {printf("<ID, %s>\n", yytext);}
  14. {keywords} {printf("<Keywords, %s>\n", yytext);}
  15. {punctuation} {printf("<Punctuators, %s>\n", yytext);}
  16. {operators} {printf("Operators, %s>\n", yytext);}
  17. %%
  18. int main()
  19. {
  20. yylex();
  21. return 0;
  22. }
  23. int yywrap()
  24. {
  25. return 1;
  26. }
Success #stdin #stdout #stderr 0.02s 6880KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Mrmxh5/prog:26:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit