fork download
  1. %{
  2. #include<stdio.h>
  3. #include<conio.h>
  4. %}
  5.  
  6. %%
  7. "int" { printf("INT\n"); }
  8. "void" { printf("VOID\n"); }
  9. "printf" { printf("PRINTF\n"); }
  10. "(" { printf("LPAREN\n"); }
  11. ")" { printf("RPAREN\n"); }
  12. "{" { printf("LBRACE\n"); }
  13. "}" { printf("RBRACE\n"); }
  14. "=" { printf("ASSIGN\n"); }
  15. ";" { printf("SEMICOLON\n"); }
  16. "+" { printf("PLUS\n"); }
  17. "," { printf("COMMA\n"); }
  18. "\"%d\"" { printf("FORMAT\n"); }
  19. [0-9]+ { printf("NUM: %s\n", yytext); }
  20. [a-zA-Z][a-zA-Z0-9]* { printf("ID: %s\n", yytext); }
  21. [ \t\n] ; /* Skip whitespace and newline */
  22. . { printf("ERROR: Unexpected character: %s\n", yytext); }
  23. %%
  24.  
  25. int main()
  26. {
  27. yyin = fopen("input.c", "r");
  28. yylex();
  29. fclose(yyin);
  30. return 0;
  31. }
  32.  
Success #stdin #stdout #stderr 0.02s 6768KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/e3n0Ho/prog:2:1: Syntax error: Operator expected
ERROR: /home/e3n0Ho/prog:31:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit