Closed Hamdy1337 closed 1 year ago
An approach that was taken to solve the problem of Validating the PoS expression is to use Regex
. Regex
is a sequence of characters that specifies a match pattern in a given text. However, while using Regex
, two problems arose.
The first problem is that there is no way by using Regex
to represent nested parentheses and checking if they are balanced. Nevertheless, this can be solved by integrating another programming language like C++ along with Regex
and using a built-in class like stack to check if the parentheses are balanced. The other problem is representing unary products and excepting single summands. In the picture attached, highlighted text means that it passes the Regex
code. The first two lines are examples of functions that should pass the Regex
code and be signed as PoS expressions. The highlighted two lines in between should not be highlighted. The last non-highlighted lines are not PoS and, therefore, are not highlighted. The possible solution for the current problem is to OR
all of the correct conditions we are left with and except the faulty ones using Regex
.
The used Regex
code
/^\(* ?([A-z]'? ?\+( ?[A-z]'?)* ?)+\)*(( *|\*)\( ?([A-z]'? ?\+ ?([A-z]'?)* ?)+\))*$
/gm
Is your feature request related to a problem? Please describe.
Users' input might not be valid as a PoS. This will be implemented to validate the input of the user and ensure the expression is in PoS form, which is a boolean expression of
AND
operations (products) betweenOR
operations (sums). For example:(a + c)(d’ + e)(b + c')