Browse Source

WIP metatool

master
zelaven 4 years ago
parent
commit
bcfae7097c
5 changed files with 62 additions and 0 deletions
  1. +3
    -0
      .gitignore
  2. +0
    -0
      build.sh
  3. +5
    -0
      build_files/.gitignore
  4. +4
    -0
      build_metatool.sh
  5. +50
    -0
      meta_src/scanner.l

+ 3
- 0
.gitignore View File

@ -20,4 +20,7 @@ acs.err
*.swp
*.swo
# Metaprogram build
*.out
lex.yy.c

+ 0
- 0
build.sh View File


+ 5
- 0
build_files/.gitignore View File

@ -0,0 +1,5 @@
# There should be nothing in this directory except this file itself on the repo.
.
!.gitignore

+ 4
- 0
build_metatool.sh View File

@ -0,0 +1,4 @@
cd meta_src
flex scanner.l
gcc lex.yy.c -o metatool.out

+ 50
- 0
meta_src/scanner.l View File

@ -0,0 +1,50 @@
%{
#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;
}

Loading…
Cancel
Save