fork download
  1. %{
  2. int COMMENT=0;
  3. %}
  4. identifier [a-zA-Z][a-zA-Z0-9]*
  5. %%
  6. #.* {printf("\n%s is a preprocessor directive",yytext);}
  7. int |
  8. char |
  9. double |
  10. while |
  11. for |
  12. struct |
  13. typedef |
  14. do |
  15. if |
  16. break |
  17. continue |
  18. void |
  19. switch |
  20. return |
  21. else |
  22. goto {printf("\n\t%s is a keyword",yytext);}
  23. "/*" {COMMENT=1;}{printf("\n\t %s is a COMMENT",yytext);}
  24. {identifier}\( {if(!COMMENT)printf("\nFUNCTION \n\t%s",yytext);}
  25. \{ {if(!COMMENT)printf("\n BLOCK BEGINS");}
  26. \} {if(!COMMENT)printf("BLOCK ENDS ");}
  27. {identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s IDENTIFIER",yytext);}
  28. \".*\" {if(!COMMENT)printf("\n\t %s is a STRING",yytext);}
  29. [0-9]+ {if(!COMMENT) printf("\n %s is a NUMBER ",yytext);}
  30. \)(\:)? {if(!COMMENT)printf("\n\t");ECHO;printf("\n");}
  31. \( ECHO;
  32. = {if(!COMMENT)printf("\n\t %s is an ASSIGNMENT OPERATOR",yytext);}
  33. \<= |
  34. \>= |
  35. \< |
  36. == |
  37. \> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);}
  38. %%
  39. int main(int argc, char **argv)
  40. {
  41. FILE *file;
  42. file=fopen("var.c","r");
  43. if(!file)
  44. {
  45. printf("could not open the file");
  46. exit(0);
  47. }
  48. yyin=file;
  49. yylex();
  50. printf("\n");
  51. return(0);
  52. }
  53. int yywrap()
  54. {
  55. return(1);
  56. }
  57.  
  58.  
  59.  
  60.  
Success #stdin #stdout #stderr 0.02s 6892KB
stdin
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
a=1;
b=2;
c=a+b;
printf("Sum:%d",c);
}
stdout
Standard output is empty
stderr
ERROR: /home/huFJAo/prog:60: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: 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 ? % Execution Aborted
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit