Boost logo

Boost Users :

From: elviin (elviin_at_[hidden])
Date: 2006-01-26 03:34:22


Hello there.

I'd like to use non-ast tree. I'm also using the tree_to_xml function
to generate xml code.
Plus my own grammar. The problem is with the token_node_d directive. I
assumed that this directive merge the parsed code to an one node. At
this time my parser works for me very fine except the tree because
there are missing value objects in xml structure. So it seems that the
whole tree is empty:/

I can reproduce that state with the example file parse_tree_calc1.cpp:

The correct output from the tree_to_xml function is following when parsing "1":

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE parsetree SYSTEM "parsetree.dtd">
<!-- 1 -->
<parsetree version="1.0">
    <parsenode rule="expression">
        <parsenode rule="term">
            <parsenode rule="factor">
                <parsenode rule="integer">
                    <parsenode rule="integer">
                        <value>1</value> <<<<======== it's OK here
                    </parsenode>
                </parsenode>
            </parsenode>
        </parsenode>
    </parsenode>
</parsetree>
parsing succeeded

... and the corresponfing code/rules:

    integer = lexeme_d[ token_node_d[ (!ch_p('-') >> +digit_p) ] ];
    factor = integer
                | '(' >> expression >> ')'
                | ('-' >> factor);
    term = factor >>
                    *( ('*' >> factor)
                      | ('/' >> factor)
                    );
    expression = term >>
                    *( ('+' >> term)
                      | ('-' >> term)
                    );

But if I move the token_node_d directive to another position, so that
is similar to the problem with my grammar:

    integer = lexeme_d[ (!ch_p('-') >> +digit_p) ];
    factor = token_node_d[integer]
                | '(' >> expression >> ')'
                | ('-' >> factor);
    term = factor >>
                    *( ('*' >> factor)
                      | ('/' >> factor)
                    );
    expression = term >>
                    *( ('+' >> term)
                      | ('-' >> term)
                    );

... then the XML structure looks like this. The "value" object are missing:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE parsetree SYSTEM "parsetree.dtd">
<!-- 1 -->
<parsetree version="1.0">
    <parsenode rule="expression">
        <parsenode rule="term">
            <parsenode rule="factor">
                <parsenode rule="integer">
                                                    <<<<======== it is
not OK here
                </parsenode>
            </parsenode>
        </parsenode>
    </parsenode>
</parsetree>
parsing succeeded

Can anyone explain me why it is not possible to use the directive
token_node_d like this token_node_d[integer]? I just want to group all
the parsed text (integer) in one node. May I have to change the policy
or to create proper typedefs.

The problem is with hierarchy, that I want to group the parsed text
only in the higher levels of parsing process.

Thank you.

Elviin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net