Updated README

This commit is contained in:
yhirose 2020-02-07 21:52:54 -05:00
parent 16a746bb87
commit 2c7d94761f
2 changed files with 22 additions and 23 deletions

View File

@ -24,7 +24,7 @@ The PEG syntax is well described on page 2 in the [document](http://www.brynosau
This library supports the linear-time parsing known as the [*Packrat*](http://pdos.csail.mit.edu/~baford/packrat/thesis/thesis.pdf) parsing.
*Parsing expressions by [Precedence climbing](https://eli.thegreenplace.net/2012/08/02/parsing-expressions-by-precedence-climbing)* algorithm is also supported.
*Parsing infix expression by [Precedence climbing](https://eli.thegreenplace.net/2012/08/02/parsing-expressions-by-precedence-climbing)* algorithm is also supported.
IMPORTANT NOTE for some Linux distributions such as Ubuntu and CentOS: Need `-pthread` option when linking. See [#23](https://github.com/yhirose/cpp-peglib/issues/23#issuecomment-261126127), [#46](https://github.com/yhirose/cpp-peglib/issues/46#issuecomment-417870473) and [#62](https://github.com/yhirose/cpp-peglib/issues/62#issuecomment-492032680).
@ -343,26 +343,25 @@ List(I, D) ← I (D I)*
T(x) ← < x > _
```
Parsing expressions by Precedence climbing altorithm
----------------------------------------------------
Parsing infix expression by Precedence climbing
-----------------------------------------------
```cpp
parser parser(R"(
EXPRESSION <- PRECEDENCE_PARSING(ATOM, OPERATOR)
EXPRESSION <- INFIX_EXPRESSION(ATOM, OPERATOR)
ATOM <- NUMBER / '(' EXPRESSION ')'
OPERATOR <- < [-+/*] >
NUMBER <- < '-'? [0-9]+ >
%whitespace <- [ \t]*
# Parsing expressions by Precedence climbing altorithm
PRECEDENCE_PARSING(A, O) <- A (O A)* {
INFIX_EXPRESSION(A, O) <- A (O A)* {
precedence
L + -
L * /
}
)");
parser["PRECEDENCE_PARSING"] = [](const SemanticValues& sv) -> long {
parser["INFIX_EXPRESSION"] = [](const SemanticValues& sv) -> long {
auto result = any_cast<long>(sv[0]);
if (sv.size() > 1) {
auto ope = any_cast<char>(sv[1]);

View File

@ -158,8 +158,8 @@ TEST_CASE("Precedence climbing with macro", "[precedence]")
{
// Create a PEG parser
parser parser(R"(
EXPRESSION <- PRECEDENCE_PARSING(ATOM, OPERATOR)
PRECEDENCE_PARSING(A, O) <- A (O A)* {
EXPRESSION <- INFIX_EXPRESSION(ATOM, OPERATOR)
INFIX_EXPRESSION(A, O) <- A (O A)* {
precedence
L + -
L * /
@ -174,7 +174,7 @@ TEST_CASE("Precedence climbing with macro", "[precedence]")
REQUIRE(ret == true);
// Setup actions
parser["PRECEDENCE_PARSING"] = [](const SemanticValues& sv) -> long {
parser["INFIX_EXPRESSION"] = [](const SemanticValues& sv) -> long {
auto result = any_cast<long>(sv[0]);
if (sv.size() > 1) {
auto ope = any_cast<char>(sv[1]);