2 * Copyright 1993, 2000 Christopher Seiwald.
3 * This file is part of Jam - see jam.c for Copyright information.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * parse.c - make and destroy parse trees as driven by the parser
28 static PARSE
*yypsave
;
34 static int yyparse (void) {
36 void *pp
= ParseAlloc(malloc
);
38 /*ParseTrace(stderr, "**");*/
42 Parse(pp
, tk
, yylval
);
49 void parse_file (const char *f
) {
50 /* suspend scan of current file and push this new file in the stream */
52 /* now parse each block of rules and execute it */
53 /* execute it outside of the parser so that recursive */
54 /* calls to yyrun() work (no recursive yyparse's) */
58 int jmp
= 0; /* JMP_NONE */
59 /* $(<) and $(>) empty in outer scope */
61 /* filled by yyparse() calling parse_save() */
63 /* if parse error or empty parse, outta here */
64 if (yyparse() || !(p
= yypsave
)) break;
65 /* run the parse tree */
66 list_free((*(p
->func
))(p
, &l
, &jmp
));
72 void parse_save (PARSE
*p
) {
78 LIST
*(*func
) (PARSE
*p
, LOL
*args
, int *jmp
),
86 PARSE
*p
= (PARSE
*)malloc(sizeof(PARSE
));
99 void parse_refer (PARSE
*p
) {
104 void parse_free (PARSE
*p
) {
105 if (--p
->refs
) return;
106 if (p
->string
) freestr(p
->string
);
107 if (p
->string1
) freestr(p
->string1
);
108 if (p
->left
) parse_free(p
->left
);
109 if (p
->right
) parse_free(p
->right
);
110 if (p
->third
) parse_free(p
->third
);
115 JAMFA_CONST
const char *multiform_suffix (int cnt
) {
116 return (cnt
== 1 ? "" : "s");