diff options
author | Safey A.Halim <safey.allah@gmail.com> | 2010-11-11 22:04:04 +0000 |
---|---|---|
committer | Safey A.Halim <safey.allah@gmail.com> | 2010-11-11 22:04:04 +0000 |
commit | 73c184a68fc96df8c4444b7541fd2a90144f62c4 (patch) | |
tree | c151bf490c0a1265dfaed48df17da08663f530e0 /src/monkey | |
parent | 26dbab092216d23db2c51061d1291015b4e01f94 (diff) | |
download | gnunet-73c184a68fc96df8c4444b7541fd2a90144f62c4.tar.gz gnunet-73c184a68fc96df8c4444b7541fd2a90144f62c4.zip |
A simple C program to test Seaspider.
Diffstat (limited to 'src/monkey')
-rw-r--r-- | src/monkey/seaspider/org/gnunet/seaspider/SeaspiderTest.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/monkey/seaspider/org/gnunet/seaspider/SeaspiderTest.c b/src/monkey/seaspider/org/gnunet/seaspider/SeaspiderTest.c new file mode 100644 index 000000000..1a44d2135 --- /dev/null +++ b/src/monkey/seaspider/org/gnunet/seaspider/SeaspiderTest.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /** | ||
2 | * @file seaspider/SeaspiderTest.c | ||
3 | * @brief C file to test Seaspider's parsing | ||
4 | */ | ||
5 | |||
6 | /* include */ | ||
7 | #include <stdio.h> | ||
8 | |||
9 | |||
10 | #define PRE_PROC_DIR 0 | ||
11 | |||
12 | struct MyStruct { | ||
13 | int member; | ||
14 | struct MyStruct *part; | ||
15 | }; | ||
16 | |||
17 | |||
18 | enum MyEnum{ | ||
19 | enumMember1, | ||
20 | enumMember2, | ||
21 | enumMember3 | ||
22 | }; | ||
23 | |||
24 | |||
25 | static int fun(int arg1, int arg2) | ||
26 | { | ||
27 | return arg1 + arg2; | ||
28 | } | ||
29 | |||
30 | |||
31 | int main(int args, const char * argv[]) | ||
32 | { | ||
33 | /* variables declarations */ | ||
34 | struct MyStruct whole; | ||
35 | struct MyStruct part; | ||
36 | enum MyEnum myEnum; | ||
37 | int i; | ||
38 | int x, y; | ||
39 | |||
40 | /* Allocations and assignments */ | ||
41 | whole.member = 1; | ||
42 | whole.part = ∂ | ||
43 | whole.part->member = 2; | ||
44 | myEnum = enumMember3; | ||
45 | x = 0, y = 1; | ||
46 | |||
47 | /* block */ | ||
48 | { | ||
49 | /* arithmetic and logic operations */ | ||
50 | float f = 20.0; | ||
51 | whole.part->member = (int)(whole.part->member + 5) - 6; // cast - multilevel assignment | ||
52 | } | ||
53 | |||
54 | /* for loop */ | ||
55 | for (i = 0; i < 2; i++) { | ||
56 | /* conditional expressions */ | ||
57 | if ( x > 0) { | ||
58 | while (y < 5) { | ||
59 | y++; | ||
60 | } | ||
61 | } else if (x > 0 || y == 4) { | ||
62 | do { | ||
63 | y--; | ||
64 | } while (y != 1); | ||
65 | } | ||
66 | else { | ||
67 | switch (myEnum) { | ||
68 | case enumMember1: | ||
69 | fun(enumMember1, enumMember2); | ||
70 | break; | ||
71 | case enumMember2: | ||
72 | fun(enumMember1, enumMember2 ? enumMember2 : enumMember1); // ternary operator | ||
73 | break; | ||
74 | default: | ||
75 | fun(enumMember1, PRE_PROC_DIR); // preprocessing directive | ||
76 | break; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | return 1; | ||
82 | } | ||