/
control_structs.c
executable file
·52 lines (45 loc) · 1.35 KB
/
control_structs.c
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
/*
+----------------------------------------------+
| DPL Programming Language v1.1 |
+----------------------------------------------+
| The DPL langauge was developed for a school |
| project at ThunderRidge High School. |
| |
| Development of the language after its |
| completion is reserved to Brian Rosner. |
+----------------------------------------------+
| Author: Brian Rosner <br@brosner.com> |
+----------------------------------------------+
*/
#include <stdio.h>
#include "dpl.h"
#include "control_structs.h"
#include "stack.h"
#include "operators.h"
void csIfStart(dplVal *expr) {
/* push current state on to css stack */
stackPush(&_global(css), &_global(execute), sizeof(int));
/* should this if execute? */
if(_global(execute)) {
/* test the expression */
if(dplValExprTrue(expr) == TRUE) {
_global(execute) = TRUE;
}
else {
_global(execute) = FALSE;
}
}
else {
_global(execute) = FALSE;
}
}
void csIfEnd() {
int *execFlag;
/* restore last state and jump back */
stackPop(&_global(css), (void **) &execFlag);
_global(execute) = *execFlag;
}
void csElseStart() {
if(_global(execute) == TRUE) _global(execute) = FALSE;
else _global(execute) = TRUE;
}