-
Notifications
You must be signed in to change notification settings - Fork 0
/
parserTest.bnv
172 lines (126 loc) · 2.6 KB
/
parserTest.bnv
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "includeTest.bnv"
extern float subtract(float a, float b);
float subtractTest(float x){
return subtract(1.0, x);
}
extern float DotProductExt(Vector3 a, Vector3 b);
float DotProductExtTest(Vector3 a){
return DotProductExt(a, MakeVector3(1.0, 1.0, 1.0));
}
extern float sinf(float val);
float sinTest(float val){
return sinf(val);
}
int Factorial(int val){
if (val <= 1){
return 1;
}
return val * Factorial(val-1);
}
void PrintVector(Vector3 vec){
PRINTF(vec.x);
PRINTF(vec.y);
PRINTF(vec.z);
}
float DotProduct(Vector3 a, Vector3 b){
return a.x*b.x + a.y*b.y + a.z*b.z;
}
int IsPrime(int val){
int counter = 2;
int factorCount = 0;
while(counter < val){
if ((val / counter) * counter == val){
factorCount = factorCount + 1;
}
counter = counter + 1;
}
return factorCount == 0;
}
struct Triangle{
Vector3 v1;
Vector3 v2;
Vector3 v3;
int color;
};
Triangle MakeTriangle(Vector3 a, Vector3 b, Vector3 c, int col){
Triangle tri;
tri.v1 = a;
tri.v2 = b;
tri.v3 = c;
tri.color = col;
return tri;
}
void PrintTriangle(Triangle tri){
PrintVector(tri.v1);
PrintVector(tri.v2);
PrintVector(tri.v3);
PRINTI(tri.color);
}
Vector3 CrossProduct(Vector3 a, Vector3 b){
Vector3 cross;
cross.x = a.y*b.z-a.z*b.y;
cross.y = a.z*b.x-a.x*b.z;
cross.z = a.x*b.y-a.y*b.x;
return cross;
}
float VectorLengthSqr(Vector3 v){
return v.x*v.x + v.y*v.y + v.z*v.z;
}
int globalInteger;
void SetGlobalInteger(int newVal){
globalInteger = newVal;
}
Vector3 globalVec;
void SetGlobalVec(Vector3 vec){
globalVec = vec;
}
void SetGlobalVecX(float x){
globalVec.x = x;
}
extern void FlipCase(string str);
struct KeyValuePair{
string name;
float val;
};
void PrintKVPair(KeyValuePair kv){
PRINTS(kv.name);
PRINTS(": ");
PRINTF(kv.val);
}
KeyValuePair MakeKV(string name, float val){
KeyValuePair kvp;
kvp.name = name;
kvp.val = val;
return kvp;
}
string globalStr;
int main(){
Triangle myTri = MakeTriangle(
MakeVector3(1.2, 2.3, 3.4),
MakeVector3(11.2, 22.3, 33.4),
MakeVector3(17.7, 25.5, 34.4),
77);
// GAh....
globalStr = "\nThis is @%^&% a global string.\n";
int xp = 13;
PrintTriangle(myTri);
PRINTI(xp);
PRINTI(xp);
xp = 31;
PrintTriangle(myTri);
PRINTI(xp);
string testStr = "This is a test.";
PRINTS(testStr);
PRINTS("\nsdgdgds\n");
string testStr2 = "This is another test.";
PRINTS(testStr2);
FlipCase(testStr2);
PRINTS("\nNow flipping case:\n");
PRINTS(testStr2);
PRINTS(globalStr);
KeyValuePair kvp = MakeKV("KV_PAIR_ONE", 2.331);
PrintKVPair(kvp);
PrintKVPair(MakeKV("KV_PAIR_TWO", 1.733));
//PRINTF(DotProduct(vec, vec2));
return 0;
}