comparison tests/agcl/bugs/wraperror.syn @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 {
2 /*
3 * AnaGram, A System for Syntax Directed Programming
4 * Copyright 2006 David A. Holland. All Rights Reserved.
5 * See the file COPYING for license and usage terms.
6 *
7 * wraperror: test for wrappers and error token together
8 */
9
10 #include <stdio.h>
11
12
13 struct thingy {
14 const char *name;
15 int val;
16
17 void g(const char *n, int v) { name = n; val = v; }
18 void g(const thingy &t) { name = t.name; val = t.val; }
19
20 void m(const char *msg) {
21 printf("%s %s: %p, %d\n", msg, name, this, val);
22 }
23
24 thingy(const char *n, int v) { g(n,v); m("Constructed new"); }
25 thingy(const thingy &t) { g(t); m("Copied"); }
26 void operator = (const thingy &t) { g(t); m("Assigned"); }
27 ~thingy() { m("Destroyed"); }
28 };
29
30 struct foo : public thingy {
31 foo(int v) : thingy("foo", v) {}
32 foo(const foo &f) : thingy(f) {}
33 void operator = (const foo &f) { thingy::operator = (f); }
34 ~foo() {}
35 };
36
37 struct bar : public thingy {
38 bar(int v) : thingy("bar", v) {}
39 bar(const bar &f) : thingy(f) {}
40 void operator = (const bar &f) { thingy::operator = (f); }
41 ~bar() {}
42 };
43
44 void do_foo(foo &f) {
45 f.m("do_foo");
46 }
47
48 void do_bar(bar &b) {
49 b.m("do_bar");
50 }
51
52 }
53
54 [
55 parser file name = "#.cpp"
56 wrapper { foo }
57 ]
58
59 file $
60 -> declarations, eof
61
62 declarations
63 -> declaration...
64
65 declaration
66 -> foo decl:f, '\n' = do_foo(f);
67 -> bar decl:b, '\n' = do_bar(b);
68 -> '\n'
69 -> error
70
71 (foo) foo decl
72 -> 'f', 'o', 'o' = foo(1);
73
74 (bar) bar decl
75 -> 'b', 'a', 'r' = bar(2);
76
77 eof = 0
78
79 {
80
81 int main() {
82 wraperror();
83 return 0;
84 }
85
86 }