Next: Grammar File, Previous: Concepts, Up: Top [Contents][Index]
Now we show and explain several sample programs written using Bison: a Reverse Polish Notation calculator, an algebraic (infix) notation calculator — later extended to track “locations” — and a multi-function calculator. All produce usable, though limited, interactive desk-top calculators.
These examples are simple, but Bison grammars for real programming languages are written the same way. You can copy these examples into a source file to try them.
Bison comes with several examples (including for the different target languages). If this package is properly installed, you shall find them in prefix/share/doc/bison/examples, where prefix is the root of the installation, probably something like /usr/local or /usr.
• RPN Calc | Reverse Polish Notation Calculator; a first example with no operator precedence. | |
• Infix Calc | Infix (algebraic) notation calculator. Operator precedence is introduced. | |
• Simple Error Recovery | Continuing after syntax errors. | |
• Location Tracking Calc | Demonstrating the use of @n and @$. | |
• Multi-function Calc | Calculator with memory and trig functions. It uses multiple data-types for semantic values. | |
• Exercises | Ideas for improving the multi-function calculator. |