fork(2) download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. [0-9]+ { printf("Integer part recognized: %s\n", yytext); return 1; }
  8. [0-9]*\.[0-9]+ { printf("Floating-point number recognized: %s\n", yytext); return 1; }
  9. [0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+) { printf("Floating-point number with exponent recognized: %s\n", yytext); return 1; }
  10. . { return 0; } // Invalid character
  11. \n { /* Do nothing on newline */ }
  12.  
  13. %%
  14.  
  15. int main() {
  16. printf("Enter a string to validate:\n");
  17. int token_type = yylex();
  18. if (token_type == 1) {
  19. printf("String is a valid floating-point number.\n");
  20. } else {
  21. printf("String is NOT a valid floating-point number.\n");
  22. }
  23. return 0;
  24. }
Success #stdin #stdout #stderr 0.03s 7052KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/MqYHcR/prog:2:1: Syntax error: Operator expected
ERROR: /home/MqYHcR/prog:24:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit