EXPLORATION 71

image

Project 4: Calculator

Now is the time to apply everything you have learned in this book, by writing a simple textual calculator. If you type 1 + 2, for example, the calculator prints 3. This project can be as complicated as you wish or dare to make it. I recommend starting small and adding capability slowly and incrementally.

  1. Start with a simple parser to read numbers and operators. If you are familiar with a parser generator, such as Bison or Antlr, go ahead and use it. If you are feeling adventurous, try learning about Spirit, which is part of the Boost project. Spirit makes use of C++ operator overloading to implement a BNF-like ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.