Advertisement
raieed

compiler_settings

Sep 25th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. %{
  2. int cout_count = 0;
  3. int header_count = 0;
  4. int assignment_count = 0;
  5. int function_count = 0;
  6. %}
  7.  
  8. headers #include<
  9. out_command cout
  10. out_sign <<
  11. tab_char \t
  12. new_line \n
  13. string [" /new_linetab_char|A-Za-z0-9+_=-]*
  14. operand [-a-zA-Z0-9]+
  15. numeric [0-9]+
  16. operator [+\-*/]
  17. assign_op ->
  18. s_col ;
  19. comma "
  20. tab_space [\t]
  21. data_type [natural|point|sentence|large|symbol|empty]
  22. front_encloser {
  23. back_encloser }
  24. given_function [main]
  25. return return
  26.  
  27. %%
  28. {data_type}[ ]+{given_function} {function_count++;fprintf(yyout, "Main function call");}
  29. [\n] {fprintf(yyout,"\n");}
  30. {operand}[ ]*{assign_op}[ ]*({operand}|{numeric})[ ]*({operator}[ ]*({operand}|{numeric}))*{s_col} {assignment_count++;fprintf(yyout,"Assignment operator");}
  31. {headers}{string}[>] {header_count++;fprintf(yyout,"A Header Included");}
  32. tab_char+ {fprintf(yyout,"%s",yytext);}
  33. {out_command}[ ]*({out_sign}[ ]*{string})*{s_col} {cout_count++;fprintf(yyout,"Output Command",yytext);}
  34. [{}()#] {}
  35. {tab_space}+ {fprintf(yyout," ");}
  36. [\t]{return}[ ][0-9]{s_col} {fprintf(yyout, "Returns with %c\n", yytext[8]);}
  37. %%
  38.  
  39. int yywrap(){
  40. return 1;
  41. }
  42.  
  43. int main()
  44. {
  45. yyin = fopen("m.c", "r");
  46. yyout = fopen("o.txt","w");
  47. yylex();
  48. fprintf(yyout, "\nNumber of cout(s): %d\n",cout_count);
  49. fprintf(yyout,"\nNumber of header(s): %d\n",header_count);
  50. fprintf(yyout,"\nNumber of assignment(s): %d\n",assignment_count);
  51. fprintf(yyout,"\nNumber of function(s): %d\n",function_count);
  52. fclose(yyin);
  53. fclose(yyout);
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement