blob: 97ab281667f64aefabf560cc9f31f8b0c011c34b (
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;
}
|