-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC- code.cmm
34 lines (30 loc) · 1.01 KB
/
C- code.cmm
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
// Code example from: http://marvin.cs.uidaho.edu/Teaching/CS445/c-Grammar.pdf
// Note: Very lightly modified for formatting.
char zev[10]: "corgis";
char yurt[20];
int x:42, y:666;
int ant(int bat, cat[]; bool dog, elk; int fox; char gnu) {
int goat, hog[100];
gnu = 'W';
goat = hog[2] = 3*cat; // hog is 3 times the size of array passed to cat
if dog and elk or bat > cat[3] then dog = not dog;
else fox++;
if bat <= fox then {
while dog do {
static int hog; // hog in new scope
hog = fox;
dog = fred(fox++, cat)>666;
if hog>bat then break;
else if fox!=0 then fox += 7;
}
}
for i = 0 to *zev-1 do outputc(zev[i]); outnl();
if zev > "dog" then outputs("bark");
yurt = zev;
yurt[3] = zev[?*zev];
return (fox+bat*cat[bat])/-fox;
}
// note that functions are defined using a statement
int max(int a, b) if a>b then return a; else return b;
// use the max operator
int max3(int a, b, c) return a :>: b :>: c;