|
@ -2,49 +2,74 @@ |
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
FILE* outfile1 = NULL; |
|
|
#define p(f) (fprintf(f, "%s", yytext)); |
|
|
FILE* outfile2 = NULL; |
|
|
#define ps(f, s) (fprintf(f, s)); |
|
|
FILE* interface_file = NULL; |
|
|
|
|
|
|
|
|
FILE* code_common = NULL; |
|
|
|
|
|
FILE* code_g = NULL; |
|
|
|
|
|
FILE* code_w = NULL; |
|
|
|
|
|
FILE* interface_common = NULL; |
|
|
|
|
|
FILE* interface_w = NULL; |
|
|
|
|
|
FILE* interface_g = NULL; |
|
|
|
|
|
|
|
|
%} |
|
|
%} |
|
|
|
|
|
|
|
|
%option noyywrap |
|
|
%option noyywrap |
|
|
%option nounput |
|
|
|
|
|
%option noinput |
|
|
|
|
|
|
|
|
|
|
|
%x LEX_STATE_EXPORT |
|
|
%x LEX_STATE_EXPORT_COMMON |
|
|
%x LEX_STATE_EXPORT_FUNCTION |
|
|
%x LEX_STATE_EXPORT_SPLIT |
|
|
|
|
|
%x LEX_STATE_EXPORT_SPLIT_FUNCTION |
|
|
|
|
|
%x LEX_STATE_EXPORT_SPLIT_FUNCTION_BODY |
|
|
|
|
|
|
|
|
%% |
|
|
%% |
|
|
|
|
|
|
|
|
<INITIAL,LEX_STATE_EXPORT>. fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext); |
|
|
<INITIAL>. p(code_common); |
|
|
<INITIAL>\n fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext); |
|
|
<INITIAL>\n p(code_common); |
|
|
<INITIAL>"$export_split" BEGIN(LEX_STATE_EXPORT); |
|
|
|
|
|
|
|
|
<INITIAL>"$export_common " BEGIN(LEX_STATE_EXPORT_COMMON); |
|
|
|
|
|
<INITIAL>"$$export_split " BEGIN(LEX_STATE_EXPORT_SPLIT); |
|
|
|
|
|
|
|
|
|
|
|
<LEX_STATE_EXPORT_COMMON>. p(code_common); p(interface_common); |
|
|
|
|
|
<LEX_STATE_EXPORT_COMMON>\n p(code_common); p(interface_common); BEGIN(INITIAL); |
|
|
|
|
|
|
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT>"function" p(code_g); p(code_w); p(interface_g); p(interface_w); BEGIN(LEX_STATE_EXPORT_SPLIT_FUNCTION); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT>"@" ps(code_g,"g"); ps(code_w,"w"); ps(interface_g,"g"); ps(interface_w,"w"); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT>"$$" BEGIN(INITIAL); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT>. p(code_g); p(code_w); p(interface_g); p(interface_w); |
|
|
|
|
|
|
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT_FUNCTION>"{" p(code_g); p(code_w); ps(interface_g, "{return 0;}"); ps(interface_w, "{return 0;}"); BEGIN(LEX_STATE_EXPORT_SPLIT_FUNCTION_BODY); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT_FUNCTION>"@" ps(code_g,"g"); ps(code_w,"w"); ps(interface_g,"g"); ps(interface_w,"w"); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT_FUNCTION>(.|\n) p(code_g); p(code_w); p(interface_g); p(interface_w); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT_FUNCTION_BODY>"@" ps(code_g,"g"); ps(code_w,"w"); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT_FUNCTION_BODY>"$$" BEGIN(INITIAL); |
|
|
|
|
|
<LEX_STATE_EXPORT_SPLIT_FUNCTION_BODY>. p(code_g); p(code_w); |
|
|
|
|
|
|
|
|
<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) |
|
|
int main(int argn, char** argv) |
|
|
{ |
|
|
{ |
|
|
if(argn < 4) |
|
|
if(argn < 7) |
|
|
{ |
|
|
{ |
|
|
printf("Give output file as argument.\n"); |
|
|
printf("Give output file as argument.\n"); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
outfile1 = fopen(argv[1], "w"); |
|
|
code_common = fopen(argv[1], "w"); |
|
|
outfile2 = fopen(argv[2], "w"); |
|
|
code_g = fopen(argv[2], "w"); |
|
|
interface_file = fopen(argv[3], "w"); |
|
|
code_w = fopen(argv[3], "w"); |
|
|
|
|
|
interface_common = fopen(argv[4], "w"); |
|
|
|
|
|
interface_g = fopen(argv[5], "w"); |
|
|
|
|
|
interface_w = fopen(argv[6], "w"); |
|
|
|
|
|
|
|
|
yylex(); |
|
|
yylex(); |
|
|
|
|
|
|
|
|
fclose(outfile1); |
|
|
fclose(code_common); |
|
|
fclose(outfile2); |
|
|
fclose(code_g); |
|
|
fclose(interface_file); |
|
|
fclose(code_w); |
|
|
|
|
|
fclose(interface_common); |
|
|
|
|
|
fclose(interface_g); |
|
|
|
|
|
fclose(interface_w); |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|