ack/lang/m2/comp/node.c

91 lines
1.5 KiB
C
Raw Normal View History

1986-04-06 17:42:56 +00:00
/* N O D E O F A N A B S T R A C T P A R S E T R E E */
1986-05-01 19:06:53 +00:00
#ifndef NORCSID
1986-04-06 17:42:56 +00:00
static char *RcsId = "$Header$";
1986-05-01 19:06:53 +00:00
#endif
#include "debug.h"
1986-04-06 17:42:56 +00:00
#include <em_label.h>
#include <em_arith.h>
#include <alloc.h>
1986-04-07 17:40:38 +00:00
#include <system.h>
1986-05-01 19:06:53 +00:00
1986-04-06 17:42:56 +00:00
#include "def.h"
#include "type.h"
#include "LLlex.h"
#include "node.h"
struct node *h_node; /* header of free list */
1986-05-30 18:48:00 +00:00
#ifdef DEBUG
int cnt_node; /* count number of allocated ones */
#endif
1986-04-06 17:42:56 +00:00
struct node *
MkNode(class, left, right, token)
struct node *left, *right;
struct token *token;
{
/* Create a node and initialize it with the given parameters
*/
register struct node *nd = new_node();
nd->nd_left = left;
nd->nd_right = right;
nd->nd_token = *token;
nd->nd_class = class;
1986-05-28 18:36:51 +00:00
nd->nd_type = error_type;
1986-04-07 17:40:38 +00:00
DO_DEBUG(4,(debug("Create node:"), PrNode(nd)));
1986-04-06 17:42:56 +00:00
return nd;
}
1986-06-04 09:01:48 +00:00
struct node *
MkLeaf(class, token)
struct token *token;
{
register struct node *nd = new_node();
nd->nd_left = nd->nd_right = 0;
nd->nd_token = *token;
nd->nd_type = error_type;
nd->nd_class = class;
return nd;
}
1986-04-06 17:42:56 +00:00
FreeNode(nd)
register struct node *nd;
{
/* Put nodes that are no longer needed back onto the free
list
*/
1986-04-12 02:21:24 +00:00
if (!nd) return;
1986-05-23 19:25:21 +00:00
FreeNode(nd->nd_left);
FreeNode(nd->nd_right);
1986-04-06 17:42:56 +00:00
free_node(nd);
}
1986-04-07 17:40:38 +00:00
#ifdef DEBUG
extern char *symbol2str();
static
printnode(nd)
register struct node *nd;
{
fprint(STDERR, "(");
if (nd) {
printnode(nd->nd_left);
fprint(STDERR, " %s ", symbol2str(nd->nd_symb));
printnode(nd->nd_right);
}
fprint(STDERR, ")");
}
PrNode(nd)
struct node *nd;
{
printnode(nd);
fprint(STDERR, "\n");
}
#endif DEBUG