fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. "+" { printf("Arithmetic Operator: +\n"); }
  7. "-" { printf("Arithmetic Operator: -\n"); }
  8. "*" { printf("Arithmetic Operator: *\n"); }
  9. "/" { printf("Arithmetic Operator: /\n"); }
  10.  
  11. "=" { printf("Assignment Operator: =\n"); }
  12. "+=" { printf("Assignment Operator: +=\n"); }
  13. "-=" { printf("Assignment Operator: -=\n"); }
  14. "*=" { printf("Assignment Operator: *=\n"); }
  15. "/=" { printf("Assignment Operator: /=\n"); }
  16. "%=" { printf("Assignment Operator: %=\n"); }
  17.  
  18. "&" { printf("Bitwise Operator: &\n"); }
  19. "|" { printf("Bitwise Operator: |\n"); }
  20. "^" { printf("Bitwise Operator: ^\n"); }
  21. "~" { printf("Bitwise Operator: ~\n"); }
  22.  
  23. "==" { printf("Relational Operator: ==\n"); }
  24. "!=" { printf("Relational Operator: !=\n"); }
  25. ">" { printf("Relational Operator: >\n"); }
  26. "<" { printf("Relational Operator: <\n"); }
  27. ">=" { printf("Relational Operator: >=\n"); }
  28. "<=" { printf("Relational Operator: <=\n"); }
  29.  
  30. "<<" { printf("Shift Operator: <<\n"); }
  31. ">>" { printf("Shift Operator: >>\n"); }
  32.  
  33. "&&" { printf("Logical Operator: &&\n"); }
  34. "||" { printf("Logical Operator: ||\n"); }
  35. "!" { printf("Logical Operator: !\n"); }
  36.  
  37. [ \t\n] { /* Ignore whitespace */ }
  38. . { printf("Other Symbol: %s\n", yytext); }
  39. %%
  40.  
  41. int main() {
  42. printf("Enter the operators: \n");
  43. yylex();
  44. return 0;
  45. }
  46.  
Success #stdin #stdout #stderr 0.02s 6884KB
stdin
flex operators.l
gcc lex.yy.c -lfl
./a.out
stdout
Standard output is empty
stderr
ERROR: /home/PgNTPi/prog:2:1: Syntax error: Operator expected
ERROR: /home/PgNTPi/prog:45:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?       [3] program
   Exception: (3) program ? ERROR: No previous search
   Exception: (3) program ? EOF: exit