1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
Now we show and explain three sample programs written using b(): a reverse
polish notation calculator, an algebraic (infix) notation calculator, and a
multi-function calculator. All three have been tested using the Gnu bf(C++)
compiler version 5.3.1. Each example results in a usable, though limited,
interactive desk-top calculator.
These examples are simple, but b() grammars for real programming languages are
written the same way. You can copy the examples from this document into source
files to create your own versions of these programs. In addition, the b()
source archive contains the various source files ready for use.
itemization(
it() Reverse Polish Notation Calculator (section ref(RPN)):
a first example of a calculator not requiring any operator precedence.
it() Infix Notation Calculator (section ref(CALC)):
infix (algebraic) notation calculator, introducing. operator
precedence.
it() Simple Error Recovery (section ref(ERROR)):
how to continue after syntactic errors.
it() Multi-Function Calculator (section ref(MFCALC)):
calculator having memory and trigonometrical functions. It uses
multiple data-types for semantic values.
it() Suggested Exercises (section ref(EXERCISES)): Ideas for improving
the multi-function calculator.
)
|