Problems in CalcX Development
Development of my own calculator / simple programming language I called calcx was going very well up until this point... And now, I feel like I am simply stuck.
I have implemented working systems for handling units and calculations, etc.
The problem I am facing however, is that when I run a command, I parse it all into different tokens and already convert them to their respective numbers with units. This, however, results in me loosing the information which I need for conversion.
If I say I want to convert to Milli seconds, I do not mean to convert to 0.001 seconds...
I genuinely cannot think of a good solution for this problem. I have tried some possibilities, but they are all very clumsy and very much not elegant. As an example, I tried to parse every token after the “to” or “in” token as a single string-token which I could then later use. But this feels very wrong... Since the meaning is supposed to happen during the parsing. And I do not create more meaning by leaving an entire phrase like volt second / (kilo gram) as a string instead of parsing it into actually meaningful numbers...
I believe, I need to spend a few days thinking the problem through until I should start coding new things. Until then, I will try to reorganize the project further (as during writing one of the possibilities, I felt like the code base was a whole mess).
Let's see how this will go!
Update: Oh wow... Everything I wrote before, I just put into a stale branch (it will not get developed further)... But I was able to refactor the entire program to be much better. While doing so, I've also found some edge cases and errors, which took some time as well to fix. But now, I feel pretty good about the state of the calculator again. The code base is quite tidy and I feel like it would be rather straightforward to implement few functions. First, however, I want to improve the output of conversions by adding appropriate units at the end of the output quantity. I am, however, not sure how exactly I should implement it:
- Option 1:
- Adding appropriate SI Units at the End
- (–> Easier, because the original string for the query does not need to be transferred through multiple software layers)
- Option 2:
- Adding the units the user decided on
- (–> Seemingly easier, because you could just append everything after the “to” keyword as the output unit, but actually very hard to implement, because the string is tokenized into tokens that have nothing to do with the original string anymore)
I'm guessing for extensibility, I should go with the first option, but later, I might add a function to turn SI unit tokens back into the original unit strings and use them as the output...
Okay, wow. Never mind. I do not know why I would have thought that could work...
When I would have done exactly what I have just said, the program does the following:
5 kilo gram to gram = 5000 kilogram^1...
Well, I guess I'll just leave the units out for now...