fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. /* ---------- KEYWORDS (Highest priority over identifiers) ---------- */
  8. auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while
  9. { printf("Keyword: %s\n", yytext); }
  10.  
  11. /* ---------- IDENTIFIERS ---------- */
  12. [a-zA-Z_][a-zA-Z0-9_]*
  13. { printf("Identifier: %s\n", yytext); }
  14.  
  15. /* ---------- CONSTANTS ---------- */
  16. /* Float constant before integer constant */
  17. [0-9]+"."[0-9]+
  18. { printf("Float Constant: %s\n", yytext); }
  19.  
  20. [0-9]+
  21. { printf("Integer Constant: %s\n", yytext); }
  22.  
  23. /* Character constant */
  24. \'(.|\\.)\'
  25. { printf("Character Constant: %s\n", yytext); }
  26.  
  27. /* String constant */
  28. \"([^\\"]|\\.)*\"
  29. { printf("String Constant: %s\n", yytext); }
  30.  
  31. /* ---------- OPERATORS ---------- */
  32. /* Multi-character operators first */
  33. \=\=|\!=|\<=|\>=|\&\&|\|\||\+\+|\-\-
  34. { printf("Operator: %s\n", yytext); }
  35.  
  36. /* Single-character operators */
  37. [\+\-\*\/\%\=\<\>\!]
  38. { printf("Operator: %s\n", yytext); }
  39.  
  40. /* ---------- SEPARATORS ---------- */
  41. [;,(){}\[\]]
  42. { printf("Separator: %s\n", yytext); }
  43.  
  44. /* ---------- SPECIAL SYMBOLS ---------- */
  45. [@#$^~`]
  46. { printf("Special Symbol: %s\n", yytext); }
  47.  
  48. /* ---------- WHITESPACE (Ignored) ---------- */
  49. [ \t\n]+
  50. { }
  51.  
  52. /* ---------- INVALID / UNKNOWN ---------- */
  53. .
  54. { printf("Unknown Symbol: %s\n", yytext); }
  55.  
  56. %%
  57.  
  58. int main()
  59. {
  60. yylex();
  61. return 0;
  62. }
  63.  
  64. int yywrap()
  65. {
  66. return 1;
  67. }
Success #stdin #stdout #stderr 0.04s 6856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/78LI4k/prog:2:1: Syntax error: End of file in quoted atom
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit