-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.c
66 lines (56 loc) · 1.44 KB
/
value.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include "value.h"
/*
* value.c - A series of functions to manipulate the value struct
* - written by Kurt Anderson
- Last Updated 9/8/2016
*/
static value *newValue(int);
// Constants to differentiate value types
int INTEGER = 0;
int REAL = 1;
int STRING = 2;
// Creates a value of type INTEGER
value *newValueInt(int i){
value *v = newValue(INTEGER);
v->iVal = i;
return v;
}
// Creates a new Value of type REAL
value *newValueReal(double r) {
value *v = newValue(REAL);
v->rVal = r;
return v;
}
// Creates a new Value of type STRING
value *newValueString(char* str){
value *v = newValue(STRING);
v->sVal = str;
return v;
}
// Creates a new value of type VARIABLE and sets that variables iVal paraemeter to a given int
value *newValueVariableInt(char* var, int intVal){
value *v = newValue(INTEGER);
v->sVal = var;
v->iVal = intVal;
return v;
}
// Creates a new value of type VARIABLE and sets that variables rVal paraemeter to a given real number
value *newValueVariableReal(char* var, double realVal){
value *v = newValue(REAL);
v->sVal = var;
v->rVal = realVal;
return v;
}
/***** Private Interface *****/
// Creates a new value and mallocs the data required
static value *newValue(int type){
value *v;
v = malloc(sizeof(value));
v->type = type;
v->iVal = 0;
v->rVal = 0;
v->sVal = 0;
return v;
}