examples: add a simple infix calculator in C

Currently we have no simple example: rpcalc in reverse Polish, mfcalc
has functions, and lexcalc is using lex.

* examples/c/calc/Makefile, examples/c/calc/calc.y,
* examples/c/calc/calc.test, examples/c/calc/local.mk: New.
This commit is contained in:
Akim Demaille
2019-02-10 14:32:16 +01:00
parent 30f61b0549
commit 40fc688765
10 changed files with 250 additions and 5 deletions

View File

@@ -1,9 +1,11 @@
This directory contains examples of Bison grammar files.
# Examples in C
This directory contains simple examples of Bison grammar files in C.
Most of them come from the documentation, which should be installed together
with Bison. The URLs are provided for convenience.
# rpcalc - Reverse Polish Notation Calculator
## rpcalc - Reverse Polish Notation Calculator
The first example is that of a simple double-precision Reverse Polish
Notation calculator (a calculator using postfix operators). This example
provides a good starting point, since operator precedence is not an issue.
@@ -11,12 +13,23 @@ provides a good starting point, since operator precedence is not an issue.
Extracted from the documentation: "Reverse Polish Notation Calculator"
https://www.gnu.org/software/bison/manual/html_node/RPN-Calc.html
# mfcalc - Multi-Function Calculator
A more complete C example: a multi-function calculator.
## calc - Simple Calculator
This example is slightly more complex than rpcalc: it features infix
operators (`1 + 2`, instead of `1 2 +` in rpcalc), but it does so using a
unambiguous grammar of the arithmetics instead of using precedence
directives (%left, etc.).
## mfcalc - Multi-Function Calculator
A more complete C example: a multi-function calculator. More complex than
the previous example. Using precedence directives to support infix
operators.
Extracted from the documentation: "Multi-Function Calculator: mfcalc".
https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html
## lexcalc - calculator with Flex and Bison
The calculator, redux. This time using a scanner generated by Flex.
<!---