feat(Evaluator): add strict comparaison operators
This commit is contained in:
parent
35ca9c31ea
commit
b72448c62d
4 changed files with 25 additions and 2 deletions
|
@ -41,6 +41,7 @@ ToDo List:
|
|||
- [ ] add basic number list support
|
||||
- [ ] add fully features strings support
|
||||
- [ ] add [classic problem solving](https://rosettacode.org) with code examples
|
||||
- [ ] add Web Assembly support and publish a demo website
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
set i to 0
|
||||
while !(i = 10) do
|
||||
while i < 10 do
|
||||
print_number(i)
|
||||
set i to i+1
|
||||
end
|
||||
|
|
|
@ -14,7 +14,9 @@ int is_operator(char candidate) {
|
|||
candidate == '=' ||
|
||||
candidate == '!' ||
|
||||
candidate == '&' ||
|
||||
candidate == '|'
|
||||
candidate == '|' ||
|
||||
candidate == '>' ||
|
||||
candidate == '<'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -83,6 +85,10 @@ int operate(
|
|||
res = m_float_pow(a, b);
|
||||
} else if (operator == '=') {
|
||||
res = (int) (a == b);
|
||||
} else if (operator == '>') {
|
||||
res = (int) (a > b);
|
||||
} else if (operator == '<') {
|
||||
res = (int) (a < b);
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
|
@ -105,6 +111,10 @@ int operate(
|
|||
res = integer_pow(aRepr, bRepr);
|
||||
} else if (operator == '=') {
|
||||
res = (int) (aRepr == bRepr);
|
||||
} else if (operator == '<') {
|
||||
res = (int) (aRepr < bRepr);
|
||||
} else if (operator == '>') {
|
||||
res = (int) (aRepr > bRepr);
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -121,4 +121,16 @@ void test_evaluation()
|
|||
evaluate(state, "1 & (1 | 0)", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(1 == resVal);
|
||||
|
||||
evaluate(state, "0 > 0", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(0 == resVal);
|
||||
|
||||
evaluate(state, "-45 < 1", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(1 == resVal);
|
||||
|
||||
evaluate(state, "5 > 0", &resVal, &resType);
|
||||
assert(resType == TYPE_INT);
|
||||
assert(1 == resVal);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue