fork download
  1. %{
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. %}
  6. %%
  7. "int"|"float" {printf("%s:keyword\n",yytext);}
  8. [0-9]+ {printf("%s:number\n",yytext);}
  9. [a-zA-Z_][a-zA-Z0-9_]* {printf("%s:identifier\n",yytext);}
  10. "+"|"-"|"*"|"/"|"=" {printf("%s:operator\n",yytext);}
  11. "("|")"|"["|"]"|"{"|"}"|";"|"," {printf("%s:symbol\n",yytext);}
  12. [\t\n]+ ;
  13. . {printf("%s:invalid\n",yytext);}
  14. %%
  15. int main(){
  16. char input[1000]="";
  17. char line[256];
  18. printf("enter the code(type END to stop)\n");
  19. while(fgets(line,sizeof(line),stdin)){
  20. if(strcmp(line,"END\n")==0 || strcmp(line,"END")==0)
  21. break;
  22. strcat(input,line);
  23. }
  24. YY_BUFFER_STATE bp = yy_scan_string(input);
  25. yylex();
  26. yy_delete_buffer(bp);
  27. return 0;
  28. }
  29. int yywrap(){
  30. return 1;
  31. }
Success #stdin #stdout #stderr 0.02s 3176KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/run-20072/prog:2:5: Syntax error: Operator expected
ERROR: /home/run-20072/prog:31:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit