%{
|
|
|
|
#include <stdio.h>
|
|
|
|
FILE* outfile1 = NULL;
|
|
FILE* outfile2 = NULL;
|
|
FILE* interface_file = NULL;
|
|
|
|
%}
|
|
|
|
%option noyywrap
|
|
%option nounput
|
|
%option noinput
|
|
|
|
%x LEX_STATE_EXPORT
|
|
%x LEX_STATE_EXPORT_FUNCTION
|
|
|
|
%%
|
|
|
|
<INITIAL,LEX_STATE_EXPORT>. fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext);
|
|
<INITIAL>\n fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext);
|
|
<INITIAL>"$export_split" BEGIN(LEX_STATE_EXPORT);
|
|
|
|
<LEX_STATE_EXPORT>"function" fprintf(outfile1, "function"); fprintf(outfile2, "function"); fprintf(interface_file, "function"); BEGIN(LEX_STATE_EXPORT_FUNCTION);
|
|
<LEX_STATE_EXPORT_FUNCTION>"{" fprintf(outfile1, "{"); fprintf(outfile2, "{"); fprintf(interface_file, "{return 0;}"); BEGIN(INITIAL);
|
|
<LEX_STATE_EXPORT_FUNCTION>(.|\n) fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext); fprintf(interface_file, "%s", yytext);
|
|
<LEX_STATE_EXPORT>\n fprintf(outfile1, "\n"); fprintf(outfile2, "\n"); fprintf(interface_file, "\n"); BEGIN(INITIAL);
|
|
|
|
%%
|
|
|
|
int main(int argn, char** argv)
|
|
{
|
|
if(argn < 4)
|
|
{
|
|
printf("Give output file as argument.\n");
|
|
return 1;
|
|
}
|
|
|
|
outfile1 = fopen(argv[1], "w");
|
|
outfile2 = fopen(argv[2], "w");
|
|
interface_file = fopen(argv[3], "w");
|
|
|
|
yylex();
|
|
|
|
fclose(outfile1);
|
|
fclose(outfile2);
|
|
fclose(interface_file);
|
|
|
|
return 0;
|
|
}
|