examples: add an example of a push parser

Add an example to demonstrate the use of push parser.  I'm pleasantly
surprised: parse.error=detailed works like a charm with push parsers.

* examples/c/local.mk, examples/c/pushcalc/Makefile
* examples/c/pushcalc/README.md, examples/c/pushcalc/calc.test,
* examples/c/pushcalc/calc.y, examples/c/pushcalc/local.mk:
New.
This commit is contained in:
Akim Demaille
2020-01-24 08:33:20 +01:00
parent 26fba6fc94
commit 7bfff37f01
7 changed files with 268 additions and 0 deletions

View File

@@ -37,6 +37,17 @@ recursively. To demonstrate this feature, expressions in parentheses are
tokenized as strings, and then recursively parsed from the parser. So
`(((1)+(2))*((3)+(4)))` uses eight parsers, with a depth of four.
## pushcalc - calculator implemented with a push parser
All the previous examples are so called "pull parsers": the user invokes the
parser once, which repeatedly calls the scanner until the input is drained.
This example demonstrates the "push parsers": the user calls the scanner to
fetch the next token, passes it to the parser, and repeats the operation
until the input is drained.
This example is a straightforward conversion of the 'calc' example to the
push-parser model.
<!---