fork download
  1. %{
  2. #include <stdio.h>
  3. #include <ctype.h>
  4.  
  5. int isValid = 1;
  6. %}
  7.  
  8. %%
  9. [ \t\n]+ ;
  10. [a-zA-Z][a-zA-Z0-9]* { printf("Identifier: %s\n", yytext); }
  11. "+"|"-"|"*"|"/" { printf("Operator: %s\n", yytext); }
  12. [0-9]+
  13. "=" { printf("Assignment: %s\n", yytext); }
  14. . { isValid = 0; }
  15. %%
  16.  
  17. int main(void) {
  18. printf("Enter an arithmetic expression:\n");
  19. yylex();
  20.  
  21. if (isValid) {
  22. printf("The expression is valid.\n");
  23. } else {
  24. printf("The expression is invalid.\n");
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30. int yywrap() {
  31. return 1;
  32. }
Success #stdin #stdout #stderr 0.03s 6964KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Eu0qXy/prog:2:1: Syntax error: Operator expected
ERROR: /home/Eu0qXy/prog:32:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit