fork download
  1. %%
  2. "if" |
  3. "else" |
  4. "while" |
  5. "for" |
  6. "do" |
  7. "switch" |
  8. "goto" |
  9. "break" |
  10. "case" |
  11. "const" |
  12. "float" |
  13. "double" |
  14. "int" |
  15. "long" |
  16. "short" |
  17. "signed" |
  18. "unsigned" |
  19. "register" |
  20. "typedef" |
  21. "return" |
  22. "enum" |
  23. "sizeof" |
  24. "static" |
  25. "struct" |
  26. "union" |
  27. "void" |
  28. "main" |
  29. "continue" |
  30. "default" |
  31. "printf" |
  32. "scanf" {printf("%s is a keyword\n",yytext);}
  33. [a-zA-Z][a-zA-Z0-9_]* {printf("%s is a identifier\n",yytext);}
  34. [0-9]+ {printf("%s is a number",yytext);}
  35. [+/*%\-] {printf("%s is an arithmetic operator\n",yytext);}
  36. [< >][=]? |
  37. [!=][=] {printf("%s is a relational operator\n",yytext);}
  38. [&][&]|[|][|]|[!] {printf("%s is a logical operator\n",yytext);}
  39. [&][~][|][^][<<][>>] {printf("%s is a bitwise operator\n",yytext);}
  40. [,] {printf("%s is a seperator\n",yytext);}
  41. [;] {printf("%s is a terminator\n",yytext);}
  42. [()] {printf("%s is a braces\n",yytext);}
  43. [{}] {printf("%s is a paranthesis\n",yytext);}
  44. [[]] {printf("%s is a squarebrace\n",yytext);}
  45. "%d" |
  46. "%c" |
  47. "%s" |
  48. "%f" {printf("%s is a formatspecifier\n",yytext);}
  49. [/][/][a-zA-Z]* {printf("%s is a line comment\n",yytext);}
  50. [/][*][a-z0-9A-Z #()%&+-<>!~;".,]*[*][/] {printf("%s is a block comment\n",yytext);}
  51. ["][a-z0-9A-Z #()%&+-<>!~;".,]*["] {printf("%s is a string\n",yytext);}
  52. [@#$] {printf("%s is a special character\n",yytext);}
  53. "\\n" {printf("%s is a new line character\n",yytext);}
  54. "#include<stdio.h>" |
  55. "#include<stdbool.h>" |
  56. "#include<string.h>" |
  57. "#include<math.h>" {printf("%s is a header file\n",yytext);}
  58. %%
  59.  
  60.   main()
  61.   {
  62.   yylex();
  63.   }
  64.  
Success #stdin #stdout #stderr 0.02s 6936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/H2j60i/prog:2:1: Syntax error: Operator expected
ERROR: /home/H2j60i/prog:18:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit