Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.