File: comsub.k

package info (click to toggle)
kimwitu-doc 10a-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,192 kB
  • ctags: 341
  • sloc: makefile: 166; yacc: 125; ansic: 40; lex: 18; sh: 2
file content (34 lines) | stat: -rw-r--r-- 713 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* A very simple tree structure */
funnytree {uniq}:	Str(casestring)
| 			Cons(funnytree funnytree)
{			int ocs = 0;
			funnytree next ;
			{ $0->next = alltrees;
			  alltrees = $0; }
}
;

void occurs(funnytree $f) {
    Str:		{ f->ocs++; }
    Cons(f1, f2):	{ f->ocs++; occurs(f1); occurs(f2); }
}

%{ KC_TYPES_HEADER
funnytree alltrees;
%}

int main() {
    funnytree ft, it;

    alltrees = (funnytree)0;
    ft = Str(mkcasestring("foo"));
    ft = Cons(ft, ft);
    ft = Cons(ft, Str(mkcasestring("bar")));
    ft = Cons(ft, ft);
    it = alltrees;
    occurs(it);
    for(; it!= (funnytree)0; it= it->next) {
	if (it->ocs>1) {
	    printf("occurs %d times:\n", it->ocs);
	    print_funnytree(it);
}   }   }