fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4. digit​​[0-9]
  5. letter​​[a-zA-Z]
  6. id​​​{letter}({letter}|{digit})*
  7. num​​{digit}+
  8. keyword​begin|end|int|if|while
  9. relop​​<|<=|>|>=|==|!=
  10. arithop ​\-|\+|\*|\/
  11. assign​​=
  12. %%
  13. {keyword}{printf("keyword:%s\n", yytext);}
  14. {digit}{printf("digit :%s\n",yytext);}
  15. {num}​​{printf("number: %s\n", yytext);}
  16. {id}​​{printf("identifier:%s\n", yytext);}
  17. {relop}{printf("relational op: %s\n", yytext);}
  18. {arithop}{printf("arith op: %s\n", yytext);}
  19. {assign}{printf("assignment op: %s\n", yytext);}
  20. %%
  21. int main(int argc, char *argv[])
  22. {
  23. ​printf("Enter Something:");
  24. ​yylex();
  25. }
  26.  
  27. int yywrap()
  28. {
  29. ​return 1;
  30. }
  31.  
Success #stdin #stdout #stderr 0.03s 6908KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/zuM5r8/prog:31:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit