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 */
|
|
|
|
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-04-29 10:22:07 +00:00
|
|
|
|
2013-05-14 21:24:38 +00:00
|
|
|
#include "parameters.h"
|
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>
|
2022-07-16 17:34:25 +00:00
|
|
|
#include <stdlib.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"
|
1988-03-22 17:54:01 +00:00
|
|
|
#include "main.h"
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "error.h"
|
1986-04-06 17:42:56 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
static int nsubnodes[] = {
|
|
|
|
0,
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
1,
|
|
|
|
2
|
|
|
|
};
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
struct node *getnode(int class)
|
1991-03-12 16:52:00 +00:00
|
|
|
{
|
2019-05-10 17:09:03 +00:00
|
|
|
register struct node *nd = new_node();
|
1991-03-12 16:52:00 +00:00
|
|
|
|
|
|
|
if (options['R']) nd->nd_flags |= ROPTION;
|
|
|
|
if (options['A']) nd->nd_flags |= AOPTION;
|
|
|
|
nd->nd_class = class;
|
|
|
|
return nd;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
struct node *dot2node(int class, struct node *left, struct node *right)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
2019-05-10 17:09:03 +00:00
|
|
|
register struct node *nd = getnode(class);
|
1986-04-06 17:42:56 +00:00
|
|
|
|
1991-03-18 16:30:49 +00:00
|
|
|
nd->nd_symb = dot.tk_symb;
|
|
|
|
nd->nd_lineno = dot.tk_lineno;
|
1991-03-12 16:52:00 +00:00
|
|
|
nd->nd_LEFT = left;
|
|
|
|
nd->nd_RIGHT = right;
|
1986-04-06 17:42:56 +00:00
|
|
|
return nd;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
struct node *dot2leaf(int class)
|
1986-06-04 09:01:48 +00:00
|
|
|
{
|
2019-05-10 17:09:03 +00:00
|
|
|
register struct node *nd = getnode(class);
|
1991-03-18 16:30:49 +00:00
|
|
|
|
|
|
|
nd->nd_token = dot;
|
1991-03-12 16:52:00 +00:00
|
|
|
switch(nsubnodes[class]) {
|
|
|
|
case 1:
|
|
|
|
nd->nd_NEXT = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
nd->nd_LEFT = 0;
|
|
|
|
nd->nd_RIGHT = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nd;
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
void FreeNode(register struct node *nd)
|
1987-12-02 10:41:38 +00:00
|
|
|
{
|
1991-03-13 13:49:56 +00:00
|
|
|
/* Put nodes that are no longer needed back onto the free
|
|
|
|
list
|
|
|
|
*/
|
|
|
|
if (!nd) return;
|
2019-03-01 17:39:25 +00:00
|
|
|
switch(nsubnodes[(unsigned int)nd->nd_class]) {
|
1991-03-12 16:52:00 +00:00
|
|
|
case 2:
|
|
|
|
FreeNode(nd->nd_LEFT);
|
|
|
|
FreeNode(nd->nd_RIGHT);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
FreeNode(nd->nd_NEXT);
|
|
|
|
break;
|
|
|
|
}
|
1986-04-06 17:42:56 +00:00
|
|
|
free_node(nd);
|
|
|
|
}
|
1986-04-07 17:40:38 +00:00
|
|
|
|
1991-03-18 16:30:49 +00:00
|
|
|
/*ARGSUSED*/
|
2019-05-10 17:09:03 +00:00
|
|
|
int NodeCrash(register struct node* expp, label exit_label, int end_reached)
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
1991-03-18 16:30:49 +00:00
|
|
|
crash("(NodeCrash) Illegal node");
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
1991-03-18 16:30:49 +00:00
|
|
|
/*ARGSUSED*/
|
2019-05-10 17:09:03 +00:00
|
|
|
int PNodeCrash(struct node **expp, int flags)
|
1991-03-12 16:52:00 +00:00
|
|
|
{
|
1991-03-18 16:30:49 +00:00
|
|
|
crash("(PNodeCrash) Illegal node");
|
1991-03-12 16:52:00 +00:00
|
|
|
}
|
|
|
|
|
1986-04-07 17:40:38 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
extern char *symbol2str();
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void indnt(int 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
void printnode(register struct node *nd, int lvl)
|
1986-04-07 17:40:38 +00:00
|
|
|
{
|
1986-06-26 09:39:36 +00:00
|
|
|
indnt(lvl);
|
1988-11-23 13:10:57 +00:00
|
|
|
print("Class: %d; Symbol: %s; Flags: %d\n", nd->nd_class, symbol2str(nd->nd_symb), nd->nd_flags);
|
1987-05-27 10:16:03 +00:00
|
|
|
if (nd->nd_type) {
|
|
|
|
indnt(lvl);
|
|
|
|
print("Type: ");
|
|
|
|
DumpType(nd->nd_type);
|
|
|
|
print("\n");
|
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
void PrNode(register struct node *nd, int lvl)
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
|
|
|
if (! nd) {
|
|
|
|
indnt(lvl); print("<nilnode>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printnode(nd, lvl);
|
1991-03-12 16:52:00 +00:00
|
|
|
switch(nsubnodes[nd->nd_class]) {
|
|
|
|
case 1:
|
|
|
|
PrNode(nd->nd_LEFT, lvl + 1);
|
|
|
|
PrNode(nd->nd_RIGHT, lvl + 1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
PrNode(nd->nd_NEXT, lvl + 1);
|
|
|
|
break;
|
|
|
|
}
|
1986-04-07 17:40:38 +00:00
|
|
|
}
|
1991-12-17 14:36:35 +00:00
|
|
|
#endif /* DEBUG */
|