The calculator has recently been perfected, added support for variables, added more functions, implemented logical short-circuit operations, and fixed some minor bugs. I remember seeing an example in a book before, enter a function expression, you can draw the waveform of the function. When you first learn VB, you like to use a function to paint. Coupled with a little interest in electronic technology, many waveforms can be expressed using functions, it is natural to think of the program to simulate the display waveform. But because functions need to be written in the code, if you need new functions or make changes, you need to modify the program code and then compile and run. Now that you can do the calculation of the expression, you can also support the variable, so that the value of the variable can be calculated to get different values, and then combine these values into coordinate points, connected to the waveform. As a result, we also try to do a display function waveform of the small program to play, the effect is as follows:
Let's talk about the newly added variable support feature. The variable here does not need to be declared, as long as it is not a reserved keyword, the program takes it as a variable. Encountered in the previous version of the string will not recognize the error, it is now in the analysis of keywords to do a special processing, encountered a non-keyword string is added to a static variable dictionary. The key of the variable dictionary is the string representation of the variable, and value is a Tokenvalue object. After adding to the dictionary, if you encounter the same string again, the corresponding Tokenvalue object in the variable dictionary is returned. Here's an example: