This is a rendition of Bjarne's basic mathematical calculator project into a maintainable format. The project spans two full chapters in the book, and is presented in a very methodical, bottom-up approach to reasoning about how to solve everything step-by-step. The primary focus of the project is to teach you how to parse formal
Language Grammars using your new programming skills.
It's presented ITT here in advance
before those chapters, so that you can 'look ahead' and get an idea where it's all going. If you're ever scratching your head trying to figure out one of the steps (to come), you can always look back here to see how it was solved in the end.
BTW, this is a working calculator. Try different entries for the
here string arguments at the end of the command line below.
>(protip: simply modify what's already given as an example)
You can just follow the link below to Coliru and tinker around with things there.
Caution
As a novice, it's not intended that you understand how all this works yet (though you will before long). For now, its simply posted here as a reference to assist with understanding the answers to some questions that will pop up for you as you work through these 2 chapters of the book. So glance at it if you care to, otherwise just refer back here afterwards as-needed. The textbook's material picks up a couple posts ahead at
§ 6.1 A problem - p175 (
>>21320), so you can just skip over to there instead if you'd like. Cheers.
---
>Calculator project command line + possible output:
ln -s /Archive2/b4/f1e7d567fd6bd2/main.cpp Calculator.h
ln -s /Archive2/68/52ff216ce3687f/main.cpp calc_util.h
ln -s /Archive2/56/2e219ca8d64e0b/main.cpp Calculator.cpp
ln -s /Archive2/68/b228c371f01ef5/main.cpp calc_util.cpp
g++ -std=c++20 -O2 -Wall -pedantic calc_util.cpp Calculator.cpp main.cpp && ./a.out <<< '1+2; 5%8; 2*(3/4-5); q'
> = 3
> = 5
> = -8.5
>
---
>Calculator project example code
https://rentry.org/PPP2_calculator_cli
https://coliru.stacked-crooked.com/a/213a22dd10a6f316
Edited last time by Chobitsu on 03/17/2023 (Fri) 20:03:23.