I have been searching around but did not find any good solution yet, so what I am trying to do is I have below input Strings
(a&b|c)&d
a&(b|c)
(a&b)|(c&d)
so basically I want to validate if the input String is a valid logical expression, and below inputs should return false;
a(b&c)
a(&b|c)
(a&b
So wonder is there a standard way to do this?
I tried this code
https://www.interviewkickstart.com/problems/valid-parentheses
but this do not cover all cases
(a(&b&c))
will fail
2
Answers
So I actually write some code like this
which can do validtion, so my ideal here is I treat both digit and left parenthese as Evaluatable which should be eventually evaluated to true or false, and this
Evaluatable
can only be added at beginning or after an operator, for operator, it can only be added after aValue
, and for each is_valid recursive, we need know if it expectEndparentheses or notTry this one