fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. /* Definitions */
  6. NUMBER [0-9]+(\.[0-9]+)? /* integers or decimals */
  7. WS [ \t]+ /* whitespace */
  8.  
  9. %%
  10.  
  11. {WS} ; /* ignore whitespace */
  12. {NUMBER} { printf("NUMBER(%s)\n", yytext); }
  13. "+" { printf("PLUS(+)\n"); }
  14. "-" { printf("MINUS(-)\n"); }
  15. "*" { printf("MULT(*)\n"); }
  16. "/" { printf("DIV(/)\n"); }
  17. "(" { printf("LPAREN(()\n"); }
  18. ")" { printf("RPAREN())\n"); }
  19. . { printf("UNKNOWN(%s)\n", yytext); }
  20.  
  21. %%
  22.  
  23. int main() {
  24. printf("Enter an arithmetic expression:\n");
  25. yylex();
  26. return 0;
  27. }
  28.  
  29. int yywrap() {
  30. return 1;
  31. }
  32.  
Success #stdin #stdout #stderr 0.03s 6984KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/47kTTr/prog:2:1: Syntax error: Operator expected
ERROR: /home/47kTTr/prog:31:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit