![]() |
.. (לתיקייה המכילה) | |
What is a legal variable name in an expression ? | |
Any thing that is not recognized as an integer, operator, or parenthesis inside an expression. variable can't start or end with spaces, but it can contain spaces. ignore leading or eding spaces in variable names. |
How and what exception to throw ? | |
use Smalltalk method error: as following: smalltalk error: 'your error messege'. you can send any error messege you want. |
what happens if there are 2 delimiters one after another, | |
in both cases you should return an empty string as the next token. |
Is the expression (x) valid, and what is it's value ? | |
it is a valid expression and its value is the value of the variable x. notice that in this case ( like in cases of redundant paranthesis like ((3+4)), you will get ) and you will have only one value in the stack. |
should the MathExpRecognizer identify numbers and variables with delimeters different | |
yes, for example if the delimeter is = the the expresison (=2=0=0=+=30=0=) shoul be treated as (200+300) and it's value should be 500. |
The algorithm proposed can't handle cases where only a variable/number | |
1. You can assume there is just one case where variables/numbers can appear like this, which is for expressions that contain only number/variable such as (3) or (x) 2. Even without these restrictions, the algorithm can be simply modified to handle these cases by pushing the "(" into teh stack instead of ignoring it, and when getting ")" pop from the stack till the first "(" encountered. But you don't have to change the algorithm. |
In the exercise, it is written that for the string: | |
It is a mistake. 'fghij' should be the last token. |