Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fraser-levack/sledeval
Creating an extensive string mathematical expression function to be used in C
https://github.com/fraser-levack/sledeval
evaluator
Last synced: 26 days ago
JSON representation
Creating an extensive string mathematical expression function to be used in C
- Host: GitHub
- URL: https://github.com/fraser-levack/sledeval
- Owner: Fraser-Levack
- Created: 2024-07-08T12:14:58.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-10-07T13:23:18.000Z (4 months ago)
- Last Synced: 2024-11-10T01:35:54.560Z (3 months ago)
- Topics: evaluator
- Language: C
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## C Eval function for strings
This is a simple C function that evaluates a string as a mathematical expression. It is a simple implementation of the shunting yard algorithm. It is not a full implementation of the algorithm, but it is enough to evaluate simple expressions.
Could potentially be used to create entire interpreters for simple languages.
### Usage
```c
#include
#include "sledeval.h"int main() {
char *expression = "2 + 2 * 2";
int result = eval(expression);
if (result != 6) {
printf("Test failed: %s = %d (expected 6)\n", expression, result);
passed = 0;
} else {
printf("Test passed: %s = %d\n", expression, result);
}
return 0;
}
```Concept credit to Steve Summit Stack Overflow.