fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. INTEGER [+-]?[0-9]+
  6. FLOAT [+-]?([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)(([eE][+-]?[0-9]+)?)
  7. CONSTANT ({INTEGER}|{FLOAT})
  8.  
  9. %%
  10.  
  11. ^{CONSTANT}$ {
  12. printf("✅ The string '%s' is a valid constant.\n", yytext);
  13. }
  14.  
  15. .*\n {
  16. yytext[yyleng-1] = '\0';
  17. printf("❌ The string '%s' is NOT a constant.\n", yytext);
  18. }
  19.  
  20. %%
  21.  
  22. int main() {
  23. printf("Enter a string to check (Ctrl+D to exit):\n");
  24. yylex();
  25. return 0;
  26. }
  27.  
  28. int yywrap() {
  29. return 1;
  30. }
Success #stdin #stdout #stderr 0.03s 6916KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/UWx5jx/prog:30:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit