Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- int cout_count = 0;
- int header_count = 0;
- int assignment_count = 0;
- int function_count = 0;
- %}
- headers #include<
- out_command cout
- out_sign <<
- tab_char \t
- new_line \n
- string [" /new_linetab_char|A-Za-z0-9+_=-]*
- operand [-a-zA-Z0-9]+
- numeric [0-9]+
- operator [+\-*/]
- assign_op ->
- s_col ;
- comma "
- tab_space [\t]
- data_type [natural|point|sentence|large|symbol|empty]
- front_encloser {
- back_encloser }
- given_function [main]
- return return
- %%
- {data_type}[ ]+{given_function} {function_count++;fprintf(yyout, "Main function call");}
- [\n] {fprintf(yyout,"\n");}
- {operand}[ ]*{assign_op}[ ]*({operand}|{numeric})[ ]*({operator}[ ]*({operand}|{numeric}))*{s_col} {assignment_count++;fprintf(yyout,"Assignment operator");}
- {headers}{string}[>] {header_count++;fprintf(yyout,"A Header Included");}
- tab_char+ {fprintf(yyout,"%s",yytext);}
- {out_command}[ ]*({out_sign}[ ]*{string})*{s_col} {cout_count++;fprintf(yyout,"Output Command",yytext);}
- [{}()#] {}
- {tab_space}+ {fprintf(yyout," ");}
- [\t]{return}[ ][0-9]{s_col} {fprintf(yyout, "Returns with %c\n", yytext[8]);}
- %%
- int yywrap(){
- return 1;
- }
- int main()
- {
- yyin = fopen("m.c", "r");
- yyout = fopen("o.txt","w");
- yylex();
- fprintf(yyout, "\nNumber of cout(s): %d\n",cout_count);
- fprintf(yyout,"\nNumber of header(s): %d\n",header_count);
- fprintf(yyout,"\nNumber of assignment(s): %d\n",assignment_count);
- fprintf(yyout,"\nNumber of function(s): %d\n",function_count);
- fclose(yyin);
- fclose(yyout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement