X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=parse.y;h=6415b057368a7f6e097c1bc5285185f0ee903024;hb=refs%2Fheads%2Fother;hp=84a62be4733e0062a3d2c80711507ca1b335d383;hpb=ea1ec85fd94e887ad47403458f416d01b2af2213;p=~andy%2Fct diff --git a/parse.y b/parse.y index 84a62be..6415b05 100644 --- a/parse.y +++ b/parse.y @@ -3,19 +3,21 @@ #include #include extern FILE *yyin; +extern int yylineno; int yylex(void); void yyerror(gpointer node, char const *s); +static char *name = NULL; static GList *code = NULL; static GList *data = NULL; %} %error-verbose %parse-param {gpointer root}; -%token START END DATA OUT +%token START END DATA OUT FMT %% input : all | all input ; -all : data | code | print ; +all : data | code | out | fmt ; data : DATA { static int i = 0; @@ -29,16 +31,22 @@ data : DATA { }; code : START DATA END { + code = g_list_prepend(code, g_strdup_printf("#line %d \"%s\"\n", yylineno, name)); code = g_list_prepend(code, g_strdup_printf("%s\n", $2)); }; -print : START OUT DATA END { +out : START OUT DATA END { + code = g_list_prepend(code, g_strdup_printf("printf(\"%%s\", %s);\n", $3)); +}; + +fmt : START FMT DATA END { code = g_list_prepend(code, g_strdup_printf("printf(%s);\n", $3)); }; %% -gpointer parse(FILE *input, GList **_data, GList **_code) { - yyin = input; +gpointer parse(char *_name, FILE *_input, GList **_data, GList **_code) { + name = _name; + yyin = _input; yyparse(NULL); *_data = data; *_code = code;