Apply distributive law on AST (or RPN) => disjunctive normal form
问题 I have expressions like the following: {1000} AND ({1001} OR {1002} OR {1003}) Allowed operators are OR and AND, expressions can be nested using parenthesis. I already managed to tokenize this string and to convert it to an abstract syntax tree (AST) using the Shunting Yard algorithm, implemented in PHP 5.3. The above expression results in the following: 1000 1001 1002 | 1003 | & & / \ 1000 | / \ | 1003 / \ 1001 1002 When traversing this tree I want to output the final combinations of numbers