fork download
  1. %{
  2. #include <string.h>
  3. %}
  4.  
  5. datatype int|float|double|string|char
  6. L [a-zA-Z]
  7. D [0-9]
  8. %%
  9. [0-9]{10} {printf("This is a Phone Number: %s\n", yytext);}
  10. {datatype} {printf("This is a Datatype: %s\n", yytext);}
  11. {L}({L}|{D})* {printf("This is an Identifier: %s\n", yytext);}
  12. {D}+ {printf("This is a Number: %s\n", yytext);}
  13. [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} {printf("This is an Email Address: %s\n", yytext);}
  14. [0-9]*\.[0-9]+ {printf("This is a Floating-Point Number: %s\n", yytext);}
  15. 0[xX][0-9a-fA-F]+ {printf("This is a Hexadecimal Number: %s\n", yytext);}
  16. [+-]?[0-9]+ {printf("This is an Integer: %s\n", yytext);}
  17. \'[a-zA-Z]\' {printf("This is a Single Character: %s\n", yytext);}
  18. [+\-*/] {printf("This is an Operator: %s\n", yytext);}
  19. \"[^\"]*\" {printf("This is a String Literal: %s\n", yytext);}
  20. %%
  21.  
  22. int main() {
  23. yylex();
  24. return 0;
  25. }
  26.  
  27. int yywrap() {
  28. return 1;
  29. }
  30.  
  31.  
Success #stdin #stdout #stderr 0.03s 6872KB
stdin
121
stdout
Standard output is empty
stderr
ERROR: /home/HlAloT/prog:2:1: Syntax error: End of file in quoted atom
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit