binary tree and condition parser...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Bass

    #1

    binary tree and condition parser...

    Using VC#.Net, I want to take a statement, that loosely follows the rules of
    an SQL'a "WHERE" statement, and determine whether that statement is true or
    false.

    For example:

    ( ( Head = 'abc') AND ( Type = 'Text' ) ) OR ( Loc = '123' )

    I envisioned a binary tree, and using a stack object, I'd parse through the
    statement to populate the tree to something like this. (hope it looks right
    for you!)


    OR
    / \
    / \
    / \
    AND =
    / \ / \
    / \ Loc '123'
    / \
    = =
    / \ / \
    / \ Type 'Text'
    / \
    Head 'abc'


    The statements themselves are compared to an XML document I'm parsing...

    I got into the binary tree class to try and populate it it some way, but
    couldn't get an algorithm to work.

    Once the tree was populated in the above fashion, I planned to do a depth
    first search, factoring up each branch, (if Head == 'bcd' for example, then
    the tree would look like this after one node factor.

    OR
    / \
    / \
    / \
    AND =
    / \ / \
    / \ Loc '123'
    / \
    FALSE =
    / \
    Type 'Text'


    And so this process would occur until my root value had either a TRUE or a
    FALSE, which was the value of the statement, when compared to the XML
    document I'm evaluating.

    Something that's also confusing me a little is the C# syntax. Coming from
    C++ I knew the condition of each created and destroyed object via the
    pointers I used to access them, but that seems to be out the window, so
    would setting a node to the root, say, destroy the object it was currently
    assigned to? Because I wouldn't want this because the object would still
    exist in the tree structure.

    I'd appreciate any ideas, input, suggestions as to where to go from here.

    Thanks for your time.
    Daniel.


  • Bret Mulvey

    #2
    Re: binary tree and condition parser...

    It wouldn't destroy the object if the object is still in the tree and you
    can still "get to it." If you can't get to it because you don't have any
    references to it any more (coming at it from another direction in the tree)
    it would get garbage-collected.


    "Daniel Bass" <danielbass@NOS PAMpostmaster.c o.uk> wrote in message
    news:uQr0aMBhDH A.2164@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Using VC#.Net, I want to take a statement, that loosely follows the rules[/color]
    of[color=blue]
    > an SQL'a "WHERE" statement, and determine whether that statement is true[/color]
    or[color=blue]
    > false.
    >
    > For example:
    >
    > ( ( Head = 'abc') AND ( Type = 'Text' ) ) OR ( Loc = '123' )
    >
    > I envisioned a binary tree, and using a stack object, I'd parse through[/color]
    the[color=blue]
    > statement to populate the tree to something like this. (hope it looks[/color]
    right[color=blue]
    > for you!)
    >
    >
    > OR
    > / \
    > / \
    > / \
    > AND =
    > / \ / \
    > / \ Loc '123'
    > / \
    > = =
    > / \ / \
    > / \ Type 'Text'
    > / \
    > Head 'abc'
    >
    >
    > The statements themselves are compared to an XML document I'm parsing...
    >
    > I got into the binary tree class to try and populate it it some way, but
    > couldn't get an algorithm to work.
    >
    > Once the tree was populated in the above fashion, I planned to do a depth
    > first search, factoring up each branch, (if Head == 'bcd' for example,[/color]
    then[color=blue]
    > the tree would look like this after one node factor.
    >
    > OR
    > / \
    > / \
    > / \
    > AND =
    > / \ / \
    > / \ Loc '123'
    > / \
    > FALSE =
    > / \
    > Type 'Text'
    >
    >
    > And so this process would occur until my root value had either a TRUE or a
    > FALSE, which was the value of the statement, when compared to the XML
    > document I'm evaluating.
    >
    > Something that's also confusing me a little is the C# syntax. Coming from
    > C++ I knew the condition of each created and destroyed object via the
    > pointers I used to access them, but that seems to be out the window, so
    > would setting a node to the root, say, destroy the object it was currently
    > assigned to? Because I wouldn't want this because the object would still
    > exist in the tree structure.
    >
    > I'd appreciate any ideas, input, suggestions as to where to go from here.
    >
    > Thanks for your time.
    > Daniel.
    >
    >[/color]


    Comment

    Working...