fork download
  1. %{
  2. #include <iostream>
  3. #include <cstdlib>
  4. using namespace std;
  5. %}
  6.  
  7. %option noyywrap
  8.  
  9. %%
  10.  
  11. [ \t\n\r]+ /* Ignore whitespace (spaces, tabs, newlines) */
  12. "+" { cout << "Arithmetic Operator: +" << endl; }
  13. "-" { cout << "Arithmetic Operator: -" << endl; }
  14. "*" { cout << "Arithmetic Operator: *" << endl; }
  15. "/" { cout << "Arithmetic Operator: /" << endl; }
  16.  
  17. ">" { cout << "Relational Operator: >" << endl; }
  18. "<" { cout << "Relational Operator: <" << endl; }
  19. "==" { cout << "Relational Operator: ==" << endl; }
  20.  
  21. [0-9]+ { cout << "Constant: " << yytext << endl; }
  22.  
  23. [a-zA-Z_][a-zA-Z0-9_]* { cout << "Identifier: " << yytext << endl; }
  24.  
  25. %%
  26.  
  27. int main() {
  28. // Start the lexical analyzer
  29. cout << "Enter input for tokenization:" << endl;
  30. yylex(); // Runs the lexical analyzer
  31. return 0;
  32. }
  33.  
Success #stdin #stdout #stderr 0.03s 6904KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/JZjCpD/prog:32:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit