A small parsing experiment
Find a file
Bruno BELANYI 77a7bdfddd evalexpr: parse: do not use operator kind directly
This allows for having different tokens mapping to the same mathematical
operator, with potentially different semantics. For example, we can add
`$` as another notation for factorial, but allowing it to be chained:
meaning we can evaluate `3$$` to `720`, and still keep `3!!` as a syntax
error.

To do so, we simply need to add the following line to our operator
table:

```c
POSTOP(UNOP_FACT, 5, ASSOC_LEFT, '$', 0)
```
2020-11-02 16:13:33 +01:00
src evalexpr: parse: do not use operator kind directly 2020-11-02 16:13:33 +01:00
tests evalexpr: tests: reduce repetition using X macros 2020-11-02 16:13:33 +01:00
.drone.yml ci: add Drone CI 2020-11-02 15:48:30 +01:00
.gitignore git: ignore testsuite binary 2020-11-02 15:48:30 +01:00
Makefile evalexpr: tests: add Criterion testsuite 2020-11-02 15:48:30 +01:00
README.md doc: add README 2020-11-02 15:48:30 +01:00

Evalexpr

This was a small experiment in writing a precedence climbing parser, using C. I also have my reference parsing implementation, using recursive descent, to compare the parsing results.

This is mostly based on the explanation found at this address: https://www.engr.mun.ca/~theo/Misc/exp_parsing.htm (use the Wayback Machine to read it).

How to build

Simply launch the following command

42sh$ make

If you want to build an evalexpr command using recursive descent instead, use:

42sh$ make USE_CLIMBING=0

Don't forget to use make clean when alternating between both.

How to use

Simply launch the binary, and write an expression on its standard input. The binary can parse exactly one expression per line, and reports parsing errors if they happen.

Example use:

42sh$ ./evalexpr
1 + 2 * 3 - 3!
1