diff options
| -rw-r--r-- | examples/mathexamples.pcdt | 2 | ||||
| -rw-r--r-- | src/eval.c | 8 | ||||
| -rw-r--r-- | src/parse.c | 7 |
3 files changed, 13 insertions, 4 deletions
diff --git a/examples/mathexamples.pcdt b/examples/mathexamples.pcdt index 31d4f1d..b5b4430 100644 --- a/examples/mathexamples.pcdt +++ b/examples/mathexamples.pcdt @@ -1,2 +1,2 @@ @../stdlib/math.pcdt -print(multiply(12; 5;)) +print(multiply(12; -5;)) @@ -125,6 +125,7 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { firstInt = symtoi(v); } else if (type == FLOAT) { + firstFloat = symtof(v); } else if (type == STRING) { firstString = symtos(v); @@ -140,9 +141,12 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { return init_sym_int(0); } } - /* TODO: float */ else if (type == FLOAT) { - + float sf = symtof(v); + destroy_sym(v); + if (sf != firstFloat) { + return init_sym_int(0); + } } else if (type == STRING) { char* ss = symtos(v); diff --git a/src/parse.c b/src/parse.c index 79c1dc4..fcaab5d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -23,6 +23,11 @@ sym_t* init_sym_int(int value) { *vp = value; return init_sym(LITERAL, INT, vp); } +sym_t* init_sym_float(float value) { + int* vp = malloc(sizeof(float)); + *vp = value; + return init_sym(LITERAL, FLOAT, vp); +} sym_t* init_sym_str(char* value) { char* vp = malloc((strlen(value) + 1) * sizeof(char)); strcpy(vp, value); @@ -77,7 +82,7 @@ symset_t* parse_symbols(char** str) { symbolSet->count = 0; while (1) { /* clear whitespace */ - while (!isalnum(**str) && **str != '(' && **str != ')' && **str != '\0') { + while (!isalnum(**str) && **str != '-' && **str != '(' && **str != ')' && **str != '\0') { (*str)++; } if (**str == ')') { |
