Update 3 - The interpreter can now recognize strings and sign numbers.
So in the previous update, we made the program in such a way that it would return an error when we input some thing like 22.3.5. But what about inputting the string "122.33.89.64". Turns out the program would consider this an error, too. But we don't want that. We want the program to be able to recognize the characters in between double quotes as strings, so as to not apply rules of numbers on these strings. Also previously, inputting something like -24.5 would result in the output:
[-,24.5]
I've now implemented a signNumber function which takes in the array and automatically signs the number. So the above input would become:
[-24.5]
The signNumber function operates on a similar logic as the makeNumber function, only this time it uses '+' and '-' instead of dot, and with some slight changes.
So right now, when a line is inputted, it first goes to the makeString function, which groups words inside double and single quotes, then trims extra white spaces outside them. Then it is passed to makeNumber function, which converts seperate decimal parts of a number into a single token, and then finally to signNumber function, which identifies + and - tokens and signs the number to its right. Here are a few inputs and outputs:
Inputs:
"Hello world"; "How are you?"; 'H O W ARE Y O U ?????'; '22.34.12.67.23+67'; ""; 23 - -89 + -67 + ----34.8; "23 - -89 + -67 + ----34.8";
Output:
[", Hello, , world, ", ;, , ", How, , are, , you, ", ;, , ', H, , O, , W, , ARE, , Y, , O, , U, , ?, ?, ?, ?, ?, ', ;, , ', 22, ., 34, ., 12, ., 67, ., 23, +, 67, ', ;, , ", ", ;, , 24, , -, , -, 89, , +, , -, 67, , +, , -, -, -, -, 34, ., 8, ;, , ", 24, , -, , -, 89, , +, , -, 67, , +, , -, -, -, -, 34, ., 8, ", ;, ] ["Hello world"] ["How are you"] ['H O W ARE Y O U ?????'] ['22.34.12.67.23+67'] [""] [24, 89, -67, 34.8] ["24 - -89 + -67 + ----34.8"]