1987-04-29 10:22:07 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
1986-05-01 19:06:53 +00:00
|
|
|
#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
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
#include "LLlex.h"
|
1986-04-06 17:42:56 +00:00
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "node.h"
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *
|
1986-04-06 17:42:56 +00:00
|
|
|
MkNode(class, left, right, token)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *left, *right;
|
|
|
|
t_token *token;
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
|
|
|
/* Create a node and initialize it with the given parameters
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd = new_node();
|
1986-04-06 17:42:56 +00:00
|
|
|
|
|
|
|
nd->nd_left = left;
|
|
|
|
nd->nd_right = right;
|
|
|
|
nd->nd_token = *token;
|
|
|
|
nd->nd_class = class;
|
|
|
|
return nd;
|
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *
|
1987-08-10 21:43:47 +00:00
|
|
|
dot2node(class, left, right)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *left, *right;
|
1987-08-10 21:43:47 +00:00
|
|
|
{
|
|
|
|
return MkNode(class, left, right, &dot);
|
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *
|
1986-06-04 09:01:48 +00:00
|
|
|
MkLeaf(class, token)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_token *token;
|
1986-06-04 09:01:48 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd = new_node();
|
1986-06-04 09:01:48 +00:00
|
|
|
|
|
|
|
nd->nd_token = *token;
|
|
|
|
nd->nd_class = class;
|
|
|
|
return nd;
|
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *
|
1987-08-10 21:43:47 +00:00
|
|
|
dot2leaf(class)
|
|
|
|
{
|
|
|
|
return MkLeaf(class, &dot);
|
|
|
|
}
|
|
|
|
|
1986-04-06 17:42:56 +00:00
|
|
|
FreeNode(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
NodeCrash(expp)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *expp;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
|
|
|
crash("Illegal node %d", expp->nd_class);
|
|
|
|
}
|
|
|
|
|
1986-04-07 17:40:38 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
extern char *symbol2str();
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
indnt(lvl)
|
1986-04-07 17:40:38 +00:00
|
|
|
{
|
1986-06-26 09:39:36 +00:00
|
|
|
while (lvl--) {
|
|
|
|
print(" ");
|
1986-04-07 17:40:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
printnode(nd, lvl)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-04-07 17:40:38 +00:00
|
|
|
{
|
1986-06-26 09:39:36 +00:00
|
|
|
indnt(lvl);
|
1987-05-27 10:16:03 +00:00
|
|
|
print("Class: %d; Symbol: %s\n", nd->nd_class, symbol2str(nd->nd_symb));
|
|
|
|
if (nd->nd_type) {
|
|
|
|
indnt(lvl);
|
|
|
|
print("Type: ");
|
|
|
|
DumpType(nd->nd_type);
|
|
|
|
print("\n");
|
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrNode(nd, lvl)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
|
|
|
if (! nd) {
|
|
|
|
indnt(lvl); print("<nilnode>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printnode(nd, lvl);
|
1987-06-23 17:12:25 +00:00
|
|
|
PrNode(nd->nd_left, lvl + 1);
|
1986-06-26 09:39:36 +00:00
|
|
|
PrNode(nd->nd_right, lvl + 1);
|
1986-04-07 17:40:38 +00:00
|
|
|
}
|
|
|
|
#endif DEBUG
|