- Home /
B83 Expression parser problem
Hi ! Newbie here =)
I am creating a calculator, using the Expression parser of @Bunny83 : http://wiki.unity3d.com/index.php/ExpressionParser
When i want to compute 3+4*5, and change f.e the value 4 to a negative number like -1, no problem arise. Though, if i change the value 5 for a negative number, i get the exception "Reached unexpected end within the parsing tree".
In the same way, if i have x*y*z and change x and y values to become negative it will be fine. It's only if the last member becomes negative that the exception is thrown.
The piece of code containing the multiply operation is the following, but i see nothing to incriminate..
else if (aExpression.Contains('*'))
{
string[] parts = aExpression.Split('*');
List<IValue> exp = new List<IValue>(parts.Length);
for (int i = 0; i < parts.Length; i++)
{
exp.Add(Parse(parts[i]));
}
if (exp.Count == 1)
return exp[0];
return new OperationProduct(exp.ToArray());
}
![alt text][1]
Notice in the image of my Console that i won't be able to pass the value 0 to set it to a lower value (i decrement my number by 1 with a keyboard key).. [1]: /storage/temp/114544-problemparser.png
Answer by Bunny83 · Apr 10, 2018 at 01:32 AM
So you didn't read the additional notes? ^^ Especially the last paragraph:
The parser uses a quite strict syntax. As mentioned earlier brackets must not be empty, so you can't use a custom method without a parameter. The "unary minus" has to be wrapped with brackets. The parser doesn't support things like:
5 * -4
. This should be5 * (-4)
The unary minus create countless problems. This parser doesn't parse the expression linearly from left to right but simply splits the expression at operators starting at the low priority operators
oh i see ! I did not pay attention to your additional notes, sorry about that. I was busy trying to figure this all out ^^. I think that what puzzled me is that the problem would only occur with the last member, so i had dropped the idea that it was a bracket problem.. i was more into thinking that it was maybe due to the way i was myself concatenating my string or something before to feed it to your expression parser.
Your code is extremely advanced to me. I have a hard time reading it :D. I literally stop at every line to try to figure it out ! Sorry about that ! I am still really new at program$$anonymous$$g.
Your answer
Follow this Question
Related Questions
Expression denotes C# 1 Answer
Remove TAB from parsed string 2 Answers
Performance impact of blend shapes 0 Answers
PC RSS Feed Get Xml Data Works , but not on android? 0 Answers
Simple XML reading? (only string/numerical data needed) 1 Answer