~ubuntu-branches/ubuntu/dapper/cdrdao/dapper

« back to all changes in this revision

Viewing changes to pccts/sorcerer/testcpp/test5.sor

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-12-10 22:52:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051210225211-rn7q0g36wlbc9a3r
Tags: 1:1.2.1-2ubuntu1
* Resynchronise with debian (orig. debian package)
* Merged debian/changelog to mention ubuntu uploads
* Re-Applied Michael Vogts patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test of support routines */
2
 
#header <<
3
 
#include <stdio.h>
4
 
#include <string.h>
5
 
#include "SCommonAST.h"
6
 
 
7
 
class wacko {
8
 
protected:
9
 
        char text[50];
10
 
public:
11
 
        char *getText()                 { return text; }
12
 
};
13
 
 
14
 
class SORAST : public SORCommonAST, public wacko {
15
 
public:
16
 
        SORAST() {setType(0);}
17
 
        SORAST(int tok, char *s);
18
 
        void lisp_action(FILE *f);
19
 
        PCCTS_AST *shallowCopy();
20
 
};
21
 
>>
22
 
 
23
 
#tokdefs "token3.h"
24
 
 
25
 
<<
26
 
/* This constr is implicitly called when you ref node constructor #[tok,s] */
27
 
SORAST::SORAST(int tok, char *s)
28
 
{
29
 
    setType(tok);
30
 
    strcpy(getText(), s);
31
 
}
32
 
 
33
 
void SORAST::
34
 
lisp_action(FILE *f)
35
 
{
36
 
        fprintf(f, " %s", getText());
37
 
}
38
 
 
39
 
PCCTS_AST *SORAST::
40
 
shallowCopy()
41
 
{
42
 
        SORAST *p = new SORAST();
43
 
        *p = *this;
44
 
        p->setDown(NULL);
45
 
        p->setRight(NULL);
46
 
        return p;
47
 
}
48
 
>>
49
 
 
50
 
<<
51
 
main()
52
 
{
53
 
    SORAST *a, *b, *c, *d, *e, *f, *g, *start;
54
 
    SORAST *result = NULL;
55
 
    Cool myparser;
56
 
        int n;
57
 
 
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" */
60
 
        a = #[Mult,"*"];
61
 
        a->addChild(#[Var,"a"]);
62
 
        a->addChild(#[Var,"b"]);
63
 
        b = #[Plus,"+"];
64
 
        b->addChild(#[Var,"c"]);
65
 
        b->addChild(a);
66
 
 
67
 
        printf("inital tree: "); b->lisp(stdout); printf("\n");
68
 
 
69
 
        b->down()->append(#[Var,"z"]);
70
 
        printf("after appending z to end of sibling list of '+': ");
71
 
        b->lisp(stdout);
72
 
        printf("\n");
73
 
 
74
 
        PCCTS_AST *t = b->down()->right()->bottom();
75
 
        t->insert_after(#[Var,"ack"]);
76
 
        printf("after inserting an 'ack' after 'a': ");
77
 
        b->lisp(stdout);
78
 
        printf("\n");
79
 
 
80
 
        PCCTS_AST::cut_between(t,t->tail());
81
 
        printf("after cutting between a and b: ");
82
 
        b->lisp(stdout);
83
 
        printf("\n");
84
 
 
85
 
        // find all Vars in b
86
 
        SORAST *var = #[Var, ""];
87
 
        PCCTS_AST *cursor = b;
88
 
        SORAST *p;
89
 
        while ( (p= (SORAST *)b->ast_find_all(var,&cursor)) )
90
 
        {
91
 
            printf("ast_find_all reports id %s\n", p->getText());
92
 
        }
93
 
 
94
 
        // add a new subtree
95
 
        b->addChild(PCCTS_AST::make(#[Plus,"+"],#[Var,"t"],NULL));
96
 
        printf("after adding subtree (+ t) as child of initial '+': ");
97
 
        b->lisp(stdout);
98
 
        printf("\n");
99
 
 
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");
102
 
 
103
 
        printf("number of children of top + tree is %d\n", b->down()->nsiblings());
104
 
 
105
 
        printf("ptr from 3rd child to end of siblings of top + tree is:");
106
 
        b->down()->sibling_index(3)->lisp(stdout);
107
 
        printf("\n");
108
 
 
109
 
        start = b;
110
 
    myparser.expr((SORASTBase **)&b, (SORASTBase **)&result);
111
 
        start->tfree();
112
 
}
113
 
>>
114
 
 
115
 
class Cool {
116
 
 
117
 
/* Match anything; we are testing support routines */
118
 
 
119
 
expr:   .
120
 
        ;
121
 
 
122
 
}