[antlr-interest] Re: woohoo! ParseTrees for free, Debugging for me!
Terence Parr
parrt at cs.usfca.edu
Sat Nov 29 23:08:38 PST 2003
On Saturday, November 29, 2003, at 10:16 PM, lgcraymer wrote:
> Ter--
>
> If I interpret this right, you're actually visualizing parse trees
> without generating them.
Nope, i build parse trees and then rewalk them to get step i of
derivation. You can ask for any intermediate step or all of 'em :)
> Modifying ANTLR to build parse trees is even easier--add the root
> node creation code in genRule (XXXCodeGenerator) and modify refRule
> in DefineGrammarSymbols.java, then adding an option recognizer to
> ParserGrammar.java. About 10-15 lines total, unless I've missed
> something.
Sounds great! I just wanted something quickly that didn't require
modifications to ANTLR. Figured I'd break something ;) and we will
have a bug release first before features. :)
Ter
>
>
> --Loring
>
>
> --- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...>
> wrote:
>> Howdy,
>>
>> I just made ANTLR generate parse trees w/o modifying the tool
> itself.
>> I just overrode match(), traceIn(), traceOut() in the parser and
> turned
>> on -traceParser. :) Not only will it build a parse tree for you
> to
>> look at, it knows how to dump the derivation tree! This is super
> great
>> thing for debugging big grammars. The question is always "how is
> xxx
>> being matched? I know it's not right!" This derivation tool will
>> pretty much tell you. For example, here is the output when I
> run "int
>> i;" into a tinyc example with parse tree construction overrides:
>>
>> $ java Test < decl.c
>> parse tree: ( <program> ( <declaration> ( <variable> ( <type>
> int ) (
>> <declarator> i ) ; ) ) EOF )
>> derivation:
>> <program>
>> => <declaration> EOF
>> => <variable> EOF
>> => <type> <declarator> ; EOF
>> => int <declarator> ; EOF
>> => int i ; EOF
>>
>> pretty cool, n'est-ce pas? You can see precisely how your input
> is
>> matched by the grammar.
>>
>> Note: this is what a parse tree is for...not translation. For
> that you
>> use an AST or token stream rewriting (got something comin on that
> too).
>> :)
>>
>> I'm going to go to the gym and if I have the energy I'll write up
> the
>> mechanism later and post to ANTLR.org.
>>
>> Anybody wanna port to C#? ;) I know somebody that could use it
> about
>> now ;) Should I roll this into 2.7.3? Perhaps not as we want to
>> quickly get out a bug fix release w/o having to wait for C++ and
> C#
>> implementations...
>>
>> Ter
>> --
>> Professor Comp. Sci., University of San Francisco
>> Creator, ANTLR Parser Generator, http://www.antlr.org
>> Co-founder, http://www.jguru.com
>> Co-founder, http://www.knowspam.net enjoy email again!
>> Co-founder, http://www.peerscope.com pure link sharing
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list