Re: yacc parse tree

Josh Adams <josh_adams@bmc.com>
19 Dec 1998 11:20:54 -0500

          From comp.compilers

Related articles
yacc parse tree josh_adams@bmc.com (Josh Adams) (1998-12-10)
Re: yacc parse tree simon.cozens@pembroke.oxford.ac.uk (Simon Cozens) (1998-12-13)
Re: yacc parse tree mikesw@whiterose.net (1998-12-13)
Re: yacc parse tree bob@werken.com (1998-12-18)
Re: yacc parse tree belinfan@cs.utwente.nl (1998-12-18)
Re: yacc parse tree josh_adams@bmc.com (Josh Adams) (1998-12-19)
Re: yacc parse tree joachim.durchholz@munich.netsurf.de (Joachim Durchholz) (1998-12-19)
Re: yacc parse tree scinar@ug.bcc.bilkent.edu.tr (Sukru Cinar) (1998-12-21)
Re: yacc parse tree scinar@ug.bcc.bilkent.edu.tr (Sukru Cinar) (1998-12-22)
Re: yacc parse tree AMartin@ma.ultranet.com (Alan H. Martin) (1999-01-02)
Re: yacc parse tree scinar@ug.bcc.bilkent.edu.tr (Sukru Cinar) (1999-01-02)
Re: yacc parse tree buzzard@world.std.com (1999-01-02)
| List of all articles for this month |
From: Josh Adams <josh_adams@bmc.com>
Newsgroups: comp.compilers
Date: 19 Dec 1998 11:20:54 -0500
Organization: Compilers Central
References: 98-12-018
Keywords: parse

Thanks for the suggestions! John, I found an example of the tree
building technique you mentioned at:
www.cs.man.ac.uk/~pjj/cs2111/examples/tree


The technique I ended up using differs somewhat. The action for each
rule in the grammar is to put the symbol on the left side of the colon
into to a global array of symbols. When parsing is done I reverse the
array and recursively build the tree using my knowledge of how many
operands the various SQL operators have. (The leaves, which are the
columns and literals, have no operands and are the alogrithm's base
case.)


The where clause


WHERE NOT (foo BETWEEN (bar + 15) AND hah AND (jabba IS NULL OR zap <> 42));


results in the tree


not
    and
        between
            foo
            +
                bar
                15
            hah
        or
            is_null
                jabba
            <>
                zap
                42


The pleasant aspect of this approach is that the tree building routine
can assume that the list represents a syntactically correct where
clause.
--
Josh Adams - BMC Software
josh_adams@bmc.com
[You're producing an RPN string, then turning it into a tree. Perfectly
reasonable approach. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.