%{ #include #include FILE* out; int lastState = 0; #define YY_DECL int yylex() %} %x C_COMMENT %x C_FUNCTION %x C_DESC %x C_PARAM %x C_STRING %x C_MODULE FUNCTEXT [a-zA-z0-9.(), \t]+ STRING [a-zA-z0-9.(), \t\n!?<>/\\\[\]\{\}]+ VAR [a-zA-Z0-9]+ %% "/*" { BEGIN(C_COMMENT); puts("Found a comment"); } "*/" { BEGIN(INITIAL); puts("End of comment"); } [ \t\n*] ; "luamodule" { BEGIN(C_MODULE); puts("Found a luamodule"); } "\\function" { BEGIN(C_FUNCTION); puts("Found a \\function"); } "\\desc" { BEGIN(C_DESC); puts("Found a \\desc"); } "\\param" { BEGIN(C_PARAM); puts("Found a \\param"); } [ \t\n]* ; . ; [ \t\n] ; {VAR} { BEGIN(C_COMMENT); printf("module name: %s\n", yytext); } . ; ";" { BEGIN(C_COMMENT); puts("End of function"); } {FUNCTEXT} { printf("function text: %s\n", yytext); } . ; ";" { BEGIN(C_COMMENT); puts("End of desc"); } "\"" { BEGIN(C_STRING); lastState = C_DESC; puts("Found a String"); } [.\n]+ { printf("desc text: %s\n", yytext); } . ; ";" { BEGIN(C_COMMENT); puts("End of param"); } "\"" { BEGIN(C_STRING); lastState = C_PARAM; puts("Found a string"); } [ \t] ; "float" { printf("foud type: %s\n", yytext); } "vec" { printf("foud type: %s\n", yytext); } "vector" { printf("foud type: %s\n", yytext); } "ent" { printf("foud type: %s\n", yytext); } "entity" { printf("foud type: %s\n", yytext); } {VAR} { printf("foud name: %s\n", yytext); } . ; "\"" { BEGIN(lastState); puts("End of String"); } {STRING} { printf("string text: %s\n", yytext); } . ; "\n" ; . ; %% main(int argc, char *argv[]) { FILE *in; if(argc < 3) { printf("Usage: %s \n", argv[0]); return; } in = fopen(argv[1], "r"); if(!in) { printf("Could not open \'%s\'.\n", argv[1]); return; } out = fopen(argv[2], "a"); if(!out) { fclose(in); printf("Could not open \'%s\'.\n", argv[2]); return; } yyin = in; yylex(); fclose(in); fclose(out); }