diff --git a/.gitignore b/.gitignore index 48393a5..14e404c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ acs.err *.swp *.swo +# Metaprogram build +*.out +lex.yy.c diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/build_files/.gitignore b/build_files/.gitignore new file mode 100644 index 0000000..49a8e78 --- /dev/null +++ b/build_files/.gitignore @@ -0,0 +1,5 @@ +# There should be nothing in this directory except this file itself on the repo. +. +!.gitignore + + diff --git a/build_metatool.sh b/build_metatool.sh new file mode 100755 index 0000000..aa8793a --- /dev/null +++ b/build_metatool.sh @@ -0,0 +1,4 @@ +cd meta_src + +flex scanner.l +gcc lex.yy.c -o metatool.out diff --git a/meta_src/scanner.l b/meta_src/scanner.l new file mode 100644 index 0000000..aa00cc3 --- /dev/null +++ b/meta_src/scanner.l @@ -0,0 +1,50 @@ +%{ + +#include + +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 + +%% + +. fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext); +\n fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext); +"$export_split" BEGIN(LEX_STATE_EXPORT); + +"function" fprintf(outfile1, "function"); fprintf(outfile2, "function"); fprintf(interface_file, "function"); BEGIN(LEX_STATE_EXPORT_FUNCTION); +"{" fprintf(outfile1, "{"); fprintf(outfile2, "{"); fprintf(interface_file, "{return 0;}"); BEGIN(INITIAL); +(.|\n) fprintf(outfile1, "%s", yytext); fprintf(outfile2, "%s", yytext); fprintf(interface_file, "%s", yytext); +\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; +}