fork download
  1. %{
  2. #include<stdio.h>
  3. #include<string.h>
  4. char key[100][100],head[100][100],dig[100][100],op[100][100],id[100][100];
  5. int i=0,j=0,k=0,l=0,a=0,b=0,c=0,d=0,m=0,n=0;
  6. %}
  7. KW "int"|"while"|"if"|"else"|"for"|"char"|"float"|"case"|"switch"
  8. HF "#include<".*">"
  9. OP "+"|"-"|"*"|"/"|"="
  10. DIG [0-9]*|[0-9]*"."[0-9]+
  11. ID [a-zA-Z][a-zA-Z0-9]*
  12. %%
  13. {KW} {strcpy(key[i],yytext);i++;}
  14. {HF} {strcpy(head[j],yytext);j++;}
  15. {DIG} {strcpy(dig[k],yytext);k++;}
  16. {OP} {strcpy(op[m],yytext);m++;}
  17. {ID} {strcpy(id[n],yytext);n++;}
  18. . {}
  19. %%
  20. main()
  21. {
  22. yyin=fopen("input.c","r+");
  23. yylex();
  24. printf("\nThe keywords are");
  25. for(a=0;a<i;a++)
  26. {
  27. printf("\n%s",key[a]);
  28. }
  29. printf("\nThe headerfiles are ");
  30. for (b=0;b<j;b++)
  31. {
  32. printf("\n%s",head[b]);
  33. }
  34. printf("\nThe digits are");
  35. for(c=0;c<k;c++)
  36. {
  37. printf("\n%s",dig[c]);
  38. }
  39. printf("\noperators ...");
  40. for (d=0;d<m;d++)
  41. {
  42. printf("\n%s",op[d]);
  43. }
  44. printf("\nidentifiers....");
  45. for(d=0;d<n;d++)
  46. {
  47. printf("\n%s",id[d]);
  48. }
  49. }
  50. int yywrap()
  51. {
  52. printf("Errors..\n");
  53. return 1;
  54. }
Success #stdin #stdout #stderr 0.02s 6932KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/rB1nDs/prog:2:1: Syntax error: Operator expected
ERROR: /home/rB1nDs/prog:54:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit