Skip to content

Commit

Permalink
Fixed usage of pog-config.cmake and added more info to README
Browse files Browse the repository at this point in the history
  • Loading branch information
metthal committed Jul 27, 2019
1 parent 851e4aa commit 0052b93
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,46 @@ Pog is C++17 library for generating LALR(1) parsers. It splits definitions of pa
1. Declaration of tokens (regular expressions describing how the input should be tokenized)
2. Grammar rules over tokens from tokenization phase

If you are familiar with tools like yacc + lex or bison + flex then this should be already known concept for you.
If you are familiar with tools like yacc + lex or bison + flex then this should be already known concept for you. This library is header-only itself but requires RE2 library which does not come with header-only version. The plan is to be completely header-only in the future.

## Requirements

* C++ compiler with C++17 support
* [re2](https://github.com/google/re2)
* [fmt](https://github.com/fmtlib/fmt)

Windows and macOS are not officially supported yet (might require some modifications of CMake) but will be guaranteed in the future.

## How To Build

You can run CMake to build examples to see how Pog works.

```
cmake -DCMAKE_BUILD_TYPE=Release -DPOG_EXAMPLES=ON ..
cmake --build . -- -j
```

If you want to install Pog and use it in another project.

```
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --target install -- -j
```

It should automatically install CMake and `pkg-config` files required for using `pog` in other projects. For CMake, put this in your `CMakeLists.txt`

```
find_package(pog REQUIRED)
...
target_link_libraries(<your_project> pog::pog)
```

## Why make another parser generator?

I had idea for project like this for a few years already, back when I used bison + flex for a school project. The advantage of bison + flex is that it generates LALR(1) parser. These parsers are very good for parsing usual programming languages constructs without any transformations of the grammar (such as removal of left-recursion, making sure that no 2 rules have same prefix). Their approach of splitting the process into tokenization and parsing makes it much easier to write the actual grammar without having it cluttered with things like whitespaces, comments and other things that can be ignored and don't have to be present in the grammar itself. The disadvantage of bison + flex is that you have to have these installed on your system because they are standalone tools which will generate you C/C++ code. Maintaining build system which uses them and works on Linux, Windows and macOS is not an easy task. For a long time, bison was also not able to work with modern C++ features such as move semantics. It should be supported as of now (3.4) but a lot of Linux distributions still don't have this version and some stable distros won't have for a very long time. There are also other options than bison + flex in C++ world such as Boost.Spirit or PEGTL which are all amazing but they all have some drawbacks (LL parsers, cluttered and hard to maintain grammars, inability to specify operator precedence, ...). This library aims to provide what was missing out there -- taking philosophy of bison + flex and putting it into pure C++ while still generating LALR(1) parser.

The implemented parser generator is based on algorithms from papers _Efficient computation of LALR(1) look-ahead sets_, _Development of an LALR(1) Parser Generator_, _Simple computation of LALR(1) lookahead sets_ and book _Compilers: Principles, Techniques, and Tools (2nd Edition)_.

## Roadmap

Things to do before 1.0.0
Expand Down
2 changes: 2 additions & 0 deletions share/pog-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ if(POG_DOWNLOAD_RE2)
)
target_link_libraries(re2::re2 INTERFACE Threads::Threads)
else()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_package(re2 REQUIRED)
find_package(fmt REQUIRED)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/pog-targets.cmake)
Expand Down

0 comments on commit 0052b93

Please sign in to comment.