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, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * parse.c - make and destroy parse trees as driven by the parser
27 static PARSE
*yypsave
;
30 //#include "jamgram.c"
31 #define ParseTOKENTYPE token_t
32 #define ParseARG_PDECL
33 extern void *ParseAlloc(void *(*mallocProc
)(size_t));
35 void *yyp
, /* The parser */
36 int yymajor
, /* The major token code number */
37 ParseTOKENTYPE yyminor
/* The value for the token */
38 ParseARG_PDECL
/* Optional %extra_argument parameter */
40 extern void ParseFree(
41 void *p
, /* The parser to be deleted */
42 void (*freeProc
)(void*) /* Function used to reclaim memory */
45 static int yyparse (void) {
47 void *pp
= ParseAlloc(malloc
);
49 /*ParseTrace(stderr, "**");*/
53 Parse(pp
, tk
, yylval
);
60 void parse_file (const char *f
) {
61 /* suspend scan of current file and push this new file in the stream */
63 /* now parse each block of rules and execute it */
64 /* execute it outside of the parser so that recursive */
65 /* calls to yyrun() work (no recursive yyparse's) */
69 int jmp
= 0; /* JMP_NONE */
70 /* $(<) and $(>) empty in outer scope */
72 /* filled by yyparse() calling parse_save() */
74 /* if parse error or empty parse, outta here */
75 if (yyparse() || !(p
= yypsave
)) break;
76 /* run the parse tree */
77 list_free((*(p
->func
))(p
, &l
, &jmp
));
83 void parse_save (PARSE
*p
) {
89 LIST
*(*func
) (PARSE
*p
, LOL
*args
, int *jmp
),
97 PARSE
*p
= (PARSE
*)malloc(sizeof(PARSE
));
103 p
->string1
= string1
;
110 void parse_refer (PARSE
*p
) {
115 void parse_free (PARSE
*p
) {
116 if (--p
->refs
) return;
117 if (p
->string
) freestr(p
->string
);
118 if (p
->string1
) freestr(p
->string1
);
119 if (p
->left
) parse_free(p
->left
);
120 if (p
->right
) parse_free(p
->right
);
121 if (p
->third
) parse_free(p
->third
);
126 JAMFA_CONST
const char *multiform_suffix (int cnt
) {
127 return (cnt
== 1 ? "" : "s");