I need a tree structure that supports both and and ing. For example, with a regular expression like ab|c(d|e) I want to turn this into a tree.
So, first we have two "or" branches ... it can either go down ab or c(d|e) . If you head the ab branch, you get two nodes: a and b (or a , and then b , whatever). Then, if you omit the branch c(d|e) , you get c and (d|e) , then (d|e) splits into d or e .
Creating a tree structure is easy, you just have something like
class Node { string element; Node[] children; }
But how do you know whether children should "be" or "scold"? I think each level of the tree should alternate between "anding" and "oring"

It makes sense? Can anyone suggest a framework for this?
Several people suggested saving the โstatementโ to node, which is good, but there is no way to take advantage of the fact that each level always alternates either, and, or, and ...
Edit: It's not entirely clear why people think this is a binary tree. Not this. I was hoping a tiny piece of code would tell you. The example just has only 2 branches.
Currently leaning toward this:
abstract class Node { } class DataNode : Node { string data; } abstract class OpNode : Node { Node[] children; } class OrNode : OpNode { } class AndNode : OpNode { }
c # data-structures
mpen
source share