fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. "#include<stdio.h>" { printf("# include<stdio.h> is a preprocessor\n"); }
  7.  
  8. /* Keywords */
  9. "int"|"void"|"main"|"printf" { printf("A keyword: %s\n", yytext); }
  10.  
  11. /* Identifiers */
  12. [a-zA-Z_][a-zA-Z0-9_]* { printf("An identifier: %s\n", yytext); }
  13.  
  14. /* Numbers */
  15. [0-9]+ { printf("An integer: %s\n", yytext); }
  16.  
  17. /* Operators */
  18. [+\-*/=] { printf("An operator : %s\n", yytext); }
  19.  
  20. /* Punctuation */
  21. [(){};,] { printf("%s is a punctuation\n", yytext); }
  22.  
  23. /* String literal */
  24. \".*\" { printf("%s is a literalstring\n", yytext); }
  25.  
  26. /* Ignore spaces */
  27. [ \t\n] ;
  28.  
  29. /* Anything else */
  30. . { printf("Unknown: %s\n", yytext); }
  31.  
  32. %%
  33.  
  34. int main() {
  35. printf("Enter input:\n");
  36. yylex();
  37. return 0;
  38. }
Success #stdin #stdout #stderr 0.03s 6960KB
stdin
# include<stdio.h>
void main()
{
int a;
A= 10 +2;

12

Printf(“%d”, a);
}
stdout
Standard output is empty
stderr
ERROR: /home/7PrWxp/prog:2:1: Syntax error: Operator expected
ERROR: /home/7PrWxp/prog:38:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?    Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? EOF: exit