fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int valid = 1;
  5. %}
  6.  
  7. %%
  8. [0-9]+ { /* number */ }
  9. [+\-*/] { /* operators */ }
  10. [ \t\n] { /* skip whitespace */ }
  11. . { valid = 0; /* invalid character */ }
  12. %%
  13.  
  14. int main(int argc, char **argv) {
  15. printf("Enter an arithmetic expression:\n");
  16. yylex();
  17. if (valid)
  18. printf("Valid expression (syntactically simple check).\n");
  19. else
  20. printf("Invalid expression (unrecognized characters found).\n");
  21. return 0;
  22. }
  23.  
  24. int yywrap() {
  25. return 1;
  26. }
  27.  
Success #stdin #stdout #stderr 0.02s 6948KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/cs6tNa/prog:2:1: Syntax error: Operator expected
ERROR: /home/cs6tNa/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit