1
/* Test of support routines */
5
#include "SCommonAST.h"
11
char *getText() { return text; }
14
class SORAST : public SORCommonAST, public wacko {
16
SORAST() {setType(0);}
17
SORAST(int tok, char *s);
18
void lisp_action(FILE *f);
19
PCCTS_AST *shallowCopy();
26
/* This constr is implicitly called when you ref node constructor #[tok,s] */
27
SORAST::SORAST(int tok, char *s)
36
fprintf(f, " %s", getText());
42
SORAST *p = new SORAST();
53
SORAST *a, *b, *c, *d, *e, *f, *g, *start;
54
SORAST *result = NULL;
58
/* M a k e I n p u t T r e e T o P a r s e */
59
/* var 'b' expr is ( + c ( * a b ) ) == "c + a * b" */
61
a->addChild(#[Var,"a"]);
62
a->addChild(#[Var,"b"]);
64
b->addChild(#[Var,"c"]);
67
printf("inital tree: "); b->lisp(stdout); printf("\n");
69
b->down()->append(#[Var,"z"]);
70
printf("after appending z to end of sibling list of '+': ");
74
PCCTS_AST *t = b->down()->right()->bottom();
75
t->insert_after(#[Var,"ack"]);
76
printf("after inserting an 'ack' after 'a': ");
80
PCCTS_AST::cut_between(t,t->tail());
81
printf("after cutting between a and b: ");
86
SORAST *var = #[Var, ""];
87
PCCTS_AST *cursor = b;
89
while ( (p= (SORAST *)b->ast_find_all(var,&cursor)) )
91
printf("ast_find_all reports id %s\n", p->getText());
95
b->addChild(PCCTS_AST::make(#[Plus,"+"],#[Var,"t"],NULL));
96
printf("after adding subtree (+ t) as child of initial '+': ");
100
if ( !b->match(b) ) printf("something is not right with match()\n");
101
if ( b->match(b->down()) ) printf("something is not right with match()\n");
103
printf("number of children of top + tree is %d\n", b->down()->nsiblings());
105
printf("ptr from 3rd child to end of siblings of top + tree is:");
106
b->down()->sibling_index(3)->lisp(stdout);
110
myparser.expr((SORASTBase **)&b, (SORASTBase **)&result);
117
/* Match anything; we are testing support routines */