I'm asking this question mostly because I'm curious.
Mostly for fun, I'm trying to develop a basic interpreter & shell in C++. Now, I already developed a basic shell - I can CD
, dir
, and whatnot, and I'm asking this mostly in order to learn. :)
As a part of the interpreter, I want to save user-declared variables. I.e: param x = 'siosidf';
or param x = 5;
.
I also would like to be able to preform pure calculations, i.e 72*32
or 23 + 82 * 2
should output 2304
or 187
, recpectivley.
Note that I also want to be able to apply operators on variables, like so:
param x = 72;
x = x + 23;
print x;
Needs to output 95
.
My question has two parts:
First, how would you (doesn't have to be actual code, but if you do it, please do it in C++ :) ) implement the variable saving system? (Please also explain why, since I'm doing it in order to learn. :) )
Second, how would you tell apart different calculations/declarations/calls and preform them in all their different forms effectively? (Spaces, such as 72*83
vs. 72 * 83
.)