I am trying to parse a Boolean equation that is currently in the form of an NSString.
I want to parse it into a tree so that I can manipulate and simplify the expression into its simplest form.
Like Wolfram Alpha is able to do.
Simplifies the input:
(A and (A or B) or (B and A) or not(A)) and (B or not (A))
to
Not(a) or B
My problem is parsing the equation into a tree object where each tree node has 3 properties:
1.TreeNode *parent
2.NSMutableArray *children
3.NSString *data
thanks
Ok so thanks for the help this is the final Objective- C code i wrote to parse a Boolean expression into a tree:
it takes an expression such as
in the form:
It works with brackets parsing with precedence:
Where the treeNode object has properties and methods:
The methods do as implied by there names.
Hope this can help anyone else in future looking for a parser either specifically for Boolean algebra or maybe as a basis for a different parser.