blob: 9ac5fcb81a8f02d4a94261b5a69e444caf6c1c97 (
plain) (
tree)
|
|
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "ast.h"
#include "cibic.tab.h"
#define NEW_CNODE ((CNode *)malloc(sizeof(CNode)))
CNode *ast_root;
void cnode_reverse_chd(CNode *node) {
static CNode *chdn[MAX_CHDN];
CNode *p;
int n = 0;
for (p = node->chd; p; p = p->next)
cnode_reverse_chd(p);
for (p = node->chd; p; p = p->next)
chdn[n++] = p;
if (n)
{
node->chd = chdn[--n];
for (; n; n--)
chdn[n]->next = chdn[n - 1];
chdn[0]->next = NULL;
}
}
CNode *cnode_create_ast(CNode *wrapped) {
cnode_reverse_chd(wrapped);
return wrapped;
}
CNode *cnode_create_nop() {
CNode *nop = NEW_CNODE;
nop->type = NOP;
nop->next = nop->chd = NULL;
return nop;
}
CNode *cnode_create_general(int type, int subtype, int pnum, va_list ap) {
int i;
CNode *exp = NEW_CNODE;
exp->type = type;
exp->rec.subtyp
|