Skip to content

Commit

Permalink
Added simple parser mode for easy expression evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
sillydan1 committed Mar 6, 2022
1 parent 959a677 commit df93956
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(expr VERSION 1.1.2)
project(expr VERSION 1.1.3)
include(cmake/CPM.cmake)
configure_file(src/config.h.in config.h)
set(CMAKE_CXX_STANDARD 20)
Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# expr
# EXPR
A variable environment manipulation expression parser written in C++20 with flex and bison.

## Features
The parser rules have two different modes:
1. Either evaluate a string of assignment expressions e.g. `a := 1; b := 2` or
2. Evaluate a single expression with result stored in `driver.result["expression_result"]`

## Examples
This project comes with an demo example command line interface called `expr_demo` so that you
can test if the project supports your expression syntax. This example cli can
Expand All @@ -25,10 +30,16 @@ try { // Errors are handled with exceptions
}
```

## Compile
You should be able to compile with cmake like so:
```
## Use CMake
This project is compiled through cmake, so you can simply configure the project and make it like so:
```shell
mkdir bin && cd bin
cmake ..
make
make
```
If you want to use the project in your own cmake project, simply include `expr` as a subdirectory and link
with the `libexpr` library. The project is also tagged with release versions to be compatible with [cpm](https://github.com/cpm-cmake/CPM.cmake),
so if your project uses that, simply include the project like so:
```cmake
CPMAddPackage("gh:sillydan1/expr@latest")
```
5 changes: 4 additions & 1 deletion src/parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@

%%
%start unit;
unit: assignments { };
unit:
assignments { }
| exp { drv.result["expression_result"] = $1; }
;

assignments:
%empty {}
Expand Down

0 comments on commit df93956

Please sign in to comment.