fork download
  1. %{
  2. #include <stdio.h>
  3. int tokenCount = 0;
  4. %}
  5.  
  6. %%
  7. [ \t\n]+ ; // Ignore whitespace
  8. [A-Za-z_][A-Za-z0-9_]* { tokenCount++; } // Identifiers
  9. [0-9]+ { tokenCount++; } // Numbers
  10. "+"|"-"|"*"|"/" { tokenCount++; } // Operators
  11. . { tokenCount++; } // Any other single character
  12. %%
  13.  
  14. int main() {
  15. yylex(); // Start lexical analysis
  16. printf("Total Tokens: %d\n", tokenCount);
  17. return 0;
  18. }
  19.  
  20. int yywrap() {
  21. return 1;
  22. }
Success #stdin #stdout #stderr 0.03s 6940KB
stdin
int x = 10;
float y = x + 5;
stdout
Standard output is empty
stderr
ERROR: /home/vVMJmE/prog:2:1: Syntax error: Operator expected
ERROR: /home/vVMJmE/prog:22:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit