fork download
  1. %{
  2. #include <stdio.h>
  3. int valid = 0;
  4. %}
  5.  
  6. %%
  7. "int"([ \t]+)[a-zA-Z_][a-zA-Z0-9_]*"="[0-9]+; { /* initialization */ }
  8. "while"[ \t]*"("[a-zA-Z_][a-zA-Z0-9_]*[<>=!]+[0-9a-zA-Z_]+")" { /* while condition */ }
  9. "{" { /* opening brace */ }
  10. "printf"[(][^)]*[)][;] { /* statement */ }
  11. [a-zA-Z_][a-zA-Z0-9_]*("++"|"--")[;] { /* increment */ }
  12. "}" { valid=1; }
  13. .|\n { /* ignore other chars */ }
  14. %%
  15.  
  16. int main(int argc,char *argv[])
  17. {
  18. if(argc>1)
  19. yyin=fopen(argv[1],"r");
  20.  
  21. yylex();
  22.  
  23. if(valid==1)
  24. printf("Success\n");
  25. else
  26. printf("Failure\n");
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout #stderr 0.03s 6912KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/8XPwxN/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit