| 1 |
# calc++ - A Flex+Bison calculator |
| 2 |
|
| 3 |
This directory contains calc++, a Bison grammar file in C++. If you never |
| 4 |
saw the traditional implementation in C, please first read |
| 5 |
examples/c/lexcalc, which can be seen as a C precursor of this example. |
| 6 |
|
| 7 |
Read the corresponding chapter in the documentation: "A Complete C++ |
| 8 |
Example". It is also available [on |
| 9 |
line](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html) |
| 10 |
(maybe with a different version of Bison). |
| 11 |
|
| 12 |
To use it, copy this directory into some work directory, and run `make` to |
| 13 |
compile the executable, and try it. It is a simple calculator which accepts |
| 14 |
several variable definitions, one per line, and then a single expression to |
| 15 |
evaluate. |
| 16 |
|
| 17 |
The program calc++ expects the file to parse as argument; pass `-` to read |
| 18 |
the standard input (and then hit <Ctrl-d>, control-d, to end your input). |
| 19 |
|
| 20 |
``` |
| 21 |
$ ./calc++ - |
| 22 |
one := 1 |
| 23 |
two := 2 |
| 24 |
three := 3 |
| 25 |
(one + two * three) * two * three |
| 26 |
<Ctrl-d> |
| 27 |
42 |
| 28 |
``` |
| 29 |
|
| 30 |
You may pass `-p` to activate the parser debug traces, and `-s` to activate |
| 31 |
the scanner's. |
| 32 |
|
| 33 |
<!--- |
| 34 |
Local Variables: |
| 35 |
fill-column: 76 |
| 36 |
ispell-dictionary: "american" |
| 37 |
End: |
| 38 |
|
| 39 |
Copyright (C) 2018-2021 Free Software Foundation, Inc. |
| 40 |
|
| 41 |
Permission is granted to copy, distribute and/or modify this document |
| 42 |
under the terms of the GNU Free Documentation License, Version 1.3 or |
| 43 |
any later version published by the Free Software Foundation; with no |
| 44 |
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover |
| 45 |
Texts. A copy of the license is included in the "GNU Free |
| 46 |
Documentation License" file as part of this distribution. |
| 47 |
|
| 48 |
LocalWords: calc parsers yy MERCHANTABILITY Ctrl ispell american |
| 49 |
---> |