+++ /dev/null
-/*\r
- * sorcerer.c -- support code for SORCERER output\r
- *\r
- * Define your own or compile and link this in.\r
- *\r
- * Terence Parr\r
- * U of MN, AHPCRC\r
- * February 1994\r
- */\r
-\r
-/***********************************************************************\r
- 2-Oct-97 The routine ast_dup() appeared to have a bug in it. Instead\r
- of providing a deep copy of its argument it made a bushy copy\r
- of its argument - by duplicating the nodes pointed to by\r
- its right link. This is certainly not deliberate and does\r
- not match code in PCCTSAST.cpp (which had its own bug). This\r
- has been changed to do a deep copy in the traditional sense.\r
-***********************************************************************/\r
-\r
-#ifdef OLD\r
-/* Given a result pointer, return the same one if *t is NULL,\r
- * else find the end of the sibling list and return the address\r
- * the 'next[write]' field in that last node.\r
- */\r
-AST **\r
-#ifdef __USE_PROTOS\r
-_nextresult(STreeParser *_parser, AST **t)\r
-#else\r
-_nextresult(_parser, t)\r
-AST **t;\r
-STreeParser *_parser;\r
-#endif\r
-{\r
- AST *p = *t;\r
-\r
- if ( p==NULL ) return t;\r
- while ( p->ast_right(_parser->write) != NULL )\r
- {\r
- p = p->ast_right(_parser->write);\r
- }\r
- return &(p->ast_right(_parser->write));\r
-}\r
-\r
-/*\r
- * Copy the read pointers to the write pointers for a node or entire subtree\r
- */\r
-void\r
-#ifdef __USE_PROTOS\r
-_copy_wildcard(STreeParser *_parser, AST *t, int root)\r
-#else\r
-_copy_wildcard(_parser, t, root)\r
-STreeParser *_parser;\r
-AST *t;\r
-int root;\r
-#endif\r
-{\r
- while ( t!=NULL )\r
- {\r
- if ( !root ) t->ast_right(_parser->write) = t->ast_right(_parser->read);\r
- t->ast_down(_parser->write) = t->ast_down(_parser->read);\r
- if ( t->ast_down(_parser->read)!=NULL )\r
- _copy_wildcard(_parser, t->ast_down(_parser->read), 0);\r
- if ( root ) return;\r
- else root=0;\r
- t = t->ast_right(_parser->read);\r
- }\r
-}\r
-#endif\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-_mkroot(SORAST **r, SORAST **s, SORAST **e, SORAST *t)\r
-#else\r
-_mkroot(r,s,e,t)\r
-SORAST **r, **s, **e, *t;\r
-#endif\r
-{\r
- *r = t;\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-_mkchild(SORAST **r, SORAST **s, SORAST **e, SORAST *t)\r
-#else\r
-_mkchild(r,s,e,t)\r
-SORAST **r, **s, **e, *t;\r
-#endif\r
-{\r
- /* if no sibling list, must attach to any existing root */\r
- if ( *s==NULL )\r
- {\r
- *s = *e = t;\r
- /* If r is NULL, then there was no root defined--must be sibling list */\r
- if ( *r==NULL ) *r = *s;\r
- else (*r)->ast_down = t;\r
- }\r
- else { (*e)->ast_right = t; *e = t; }\r
-}\r
-\r
-/* THESE FUNCS HAVE TO GO HERE BECAUSE THEY ARE SENSITIVE TO USER'S SORAST DEF */\r
-SORAST *\r
-#ifdef __USE_PROTOS\r
-ast_alloc(void)\r
-#else\r
-ast_alloc()\r
-#endif\r
-{\r
- SORAST *t = (SORAST *)calloc(1, sizeof(SORAST));\r
- if ( t==NULL ) sorcerer_panic("out of memory");\r
- return t;\r
-}\r
-\r
-SORAST *\r
-#ifdef __USE_PROTOS\r
-ast_dup_bushy(SORAST *t)\r
-#else\r
-ast_dup_bushy(t)\r
-SORAST *t;\r
-#endif\r
-{\r
- SORAST *u;\r
- \r
- if ( t == NULL ) return NULL;\r
- u = ast_alloc();\r
- *u = *t; /* copy contents */\r
- u->ast_down = ast_dup_bushy(t->ast_down); /* copy the rest of the tree */\r
- u->ast_right = ast_dup_bushy(t->ast_right);\r
- return u;\r
-}\r
-\r
-\r
-/* Assume t is a root node of a tree--duplicate that node and what's below */\r
-\r
-SORAST *\r
-#ifdef __USE_PROTOS\r
-ast_dup(SORAST *t)\r
-#else\r
-ast_dup(t)\r
-SORAST *t;\r
-#endif\r
-{\r
- SORAST *u;\r
- \r
- if ( t == NULL ) return NULL;\r
- u = ast_alloc();\r
- *u = *t; /* copy contents */\r
- u->ast_down = ast_dup_bushy(t->ast_down); /* copy the rest of the tree */\r
- u->ast_right = NULL;\r
- return u;\r
-}\r
-\r
-/* Assume t is a root node of a tree--duplicate that node and what's below */\r
-SORAST *\r
-#ifdef __USE_PROTOS\r
-ast_dup_node(SORAST *t)\r
-#else\r
-ast_dup_node(t)\r
-SORAST *t;\r
-#endif\r
-{\r
- SORAST *u;\r
- \r
- if ( t == NULL ) return NULL;\r
- u = ast_alloc();\r
- *u = *t; /* copy contents */\r
- u->down = NULL;\r
- u->right = NULL;\r
- return u;\r
-}\r