fork download
  1. /* program name is lexp.l */
  2. %{
  3. /* program to recognize a c program */ int COMMENT=0;
  4. %}
  5. identifier [a-zA-Z][a-zA-Z0-9]*
  6. %%
  7. #.* { printf("\n%s is a PREPROCESSOR DIRECTIVE",yytext);} int |
  8. float | char | double | while | for |
  9. do | if |
  10. break | continue | void | switch | case | long | struct | const | typedef | return | else |
  11. goto {printf("\n\t%s is a KEYWORD",yytext);} "/*" {COMMENT = 1;}
  12. "*/" {COMMENT = 0;}
  13. {identifier}\( {if(!COMMENT)printf("\n\nFUNCTION\n\t%s",yytext);}
  14. \{ {if(!COMMENT) printf("\n BLOCK BEGINS");}
  15. \} {if(!COMMENT) printf("\n BLOCK ENDS");}
  16. {identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s IDENTIFIER",yytext);}
  17. \".*\" {if(!COMMENT) printf("\n\t%s is a STRING",yytext);}
  18. [0-9]+ {if(!COMMENT) printf("\n\t%s is a NUMBER",yytext);}
  19. \)(\;)? {if(!COMMENT) printf("\n\t");ECHO;printf("\n");}
  20. \( ECHO;
  21. = {if(!COMMENT)printf("\n\t%s is an ASSIGNMENT OPERATOR",yytext);}
  22. \<= |
  23. \>= |
  24. \< |
  25. == |
  26. \> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);}
  27. %%
  28. int main(int argc,char **argv)
  29. {
  30. if (argc > 1)
  31. {
  32. FILE *file;
  33. file = fopen(argv[1],"r"); if(!file)
  34. {
  35. printf("could not open %s \n",argv[1]); exit(0);
  36. }
  37. yyin = file;
  38. }
  39. yylex(); printf("\n\n"); return 0;
  40. } int yywrap()
  41. {
  42. return 0;
  43. }
  44.  
  45.  
Success #stdin #stdout #stderr 0.02s 6936KB
stdin
$vi var.c
 #include<stdio.h> 
main()
{
int a,b;
}
stdout
Standard output is empty
stderr
ERROR: /home/mdEbiQ/prog:44: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 ? 
	Exception term: error(existence_error(procedure,program/0),context('$toplevel':'$runtoplevel'/0,_1808))
	       Message: '$runtoplevel'/0: Undefined procedure: program/0
   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 ? ERROR: Unknown option (h for help)
   Exception: (3) program ? EOF: exit