fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. DIGIT [0-9]
  6. LETTER [a-zA-Z]
  7. ID {LETTER}({LETTER}|{DIGIT})*
  8. NUM {DIGIT}+
  9.  
  10. %%
  11. int|float|char|double|if|else|while|for|return|void
  12. { printf("Keyword : %s\n", yytext); }
  13.  
  14. {ID} { printf("Identifier : %s\n", yytext); }
  15.  
  16. {NUM} { printf("Number : %s\n", yytext); }
  17.  
  18. "=="|"="|"+"|"-"|"*"|"/"|"<"|">"|"<="|">="
  19. { printf("Operator : %s\n", yytext); }
  20.  
  21. ";"|","|"("|")"|"{"|"}"
  22. { printf("Separator : %s\n", yytext); }
  23.  
  24. [ \t\n]+ ; /* Ignore spaces */
  25.  
  26. . { printf("Unknown : %s\n", yytext); }
  27. %%
  28.  
  29. int main(void) {
  30. printf("Enter input (press Ctrl+D / EOF after input):\n");
  31. yylex();
  32. return 0;
  33. }
  34.  
  35. int yywrap(void) {
  36. return 1;
  37. }
  38.  
Success #stdin #stdout #stderr 0.03s 6948KB
stdin
int a =10;
stdout
Standard output is empty
stderr
ERROR: /home/N1pfC6/prog:2:1: Syntax error: Operator expected
ERROR: /home/N1pfC6/prog:37:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit