[antlr-interest] Re: JavaTreeParser? What does it do?
lgcraymer
lgc at mail1.jpl.nasa.gov
Tue Apr 29 15:46:08 PDT 2003
Jon--
Look at the javatree.g grammar--that's the tree walker grammar that
defines "JavaTreeParser". If you have figured out how to get a series
of trees from the parser (parse a statement, produce a tree ...), then
it should not be too hard (I haven't tried) to feed your trees to it.
You will want to add actions to the grammar, but that is pretty
straightforward.
--Loring
--- In antlr-interest at yahoogroups.com, "jw9315" <jw9315 at b...> wrote:
> Hi,
> Thanks, that's cleared things up for me, but I've still got some
> questions if that's ok...
>
> I have used the example in the Java grammars directory to get the
AST
> window up on my screen. All I want to be able to do from here is
> parse this tree and get the statements and constants etc, so I can
> build an interpreter... So do I just declare a treeparser and then
> invoke the "getFirstChildMethods (or whatever method I need to)" on
> the instance? For example:
>
> JavaTreeParser tparse = new JavaTreeParser();
> tparse.compilationUnit(t); //(Where t is an AST tree)
> and then t.getFirstChild();
>
> The thing is, I don't wish to manipulate the tree at all, I just
want
> to read it? Does this mean that I shouldn't have to change the java
> grammars in the directory, its just a case of accessing the AST
> object in memory and extracting information from it.
> Thanks,
>
> Jon
>
> --- In antlr-interest at yahoogroups.com, "lgcraymer" <lgc at m...> wrote:
> > Tree parsers do the "getFirstChild()" and "getNextSibling()" for
> > you as well as matching a tree pattern--the whole idea is to
extend
> > the ANTLR parsing concept to trees. About the only case where you
> > might want to walk a tree without a tree parser is when
> the "Visitor"
> > pattern is appropriate.
> >
> > --Loring
> >
> >
> >
> > --- In antlr-interest at yahoogroups.com, "jw9315" <jw9315 at b...>
wrote:
> > >
> > > Hi,
> > > yeah, sorry I did see that linkm but I'm new to this and didn't
> > quite
> > > understand. What I'm trying to do is build an interpreter for a
> > > *small* subset of the Java language. I ran the example in the
> Java
> > > grammars folder to give me a nice AST tree for any program I
type
> in
> > > at the command line, and was planning on parsing and
interpreting
> > the
> > > program using the method calls such as .getChild().
> > >
> > > What I was confused about is the fact that I call such as "AST
> myAST
> > > = r.getFirstChild();", but what is the difference between this
> and
> > > the line "JavaTreeParser tparse = new JavaTreeParser();". I
can't
> > > understand what you can do differently with the two different
> > > commands! Sorry if this is a really stupid question but if
> there's a
> > > short answer that anyone's willing to give I would be glad to
> hear
> > it.
> > > Thanks,
> > > Jon
> > >
> > > --- In antlr-interest at yahoogroups.com, Terence Parr <parrt at j...>
> > > wrote:
> > > > Hi. Have you checked the faq entry that answers your
question?
> > > >
> > > > http://www.jguru.com/faq/view.jsp?EID=818959
> > > >
> > > > It's called: What is a tree parser and why would I want to use
> > one?
> > > >
> > > > <snicker>
> > > >
> > > > Terence
> > > >
> > > > On Monday, April 28, 2003, at 10:17 AM, jw9315 wrote:
> > > >
> > > > > Hi,
> > > > > I'm a brand new ANTLR user. I'm using the AST tree it
> produces
> > to
> > > > > create an interpreter for a small subset of the Java
> programming
> > > > > language. I was looking at the Main.java file in the grammar
> > > examples
> > > > > directory, and one of the last lines says:
> > > > > '
> > > > > JavaTreeParser tparse = new JavaTreeParser();
> > > > > try
> > > > > {
> > > > > tparse.compilationUnit(t);
> > > > > System.err.println("successful walk
> of result
> > > > > AST for "+f);
> > > > > }
> > > > > catch (RecognitionException e) {
> > > > > System.err.println(e.getMessage());
> > > > > e.printStackTrace();
> > > > > }
> > > > > ' Could anyone tell me what this block does in the program,
> what
> > > is
> > > > > a JavaTreeParser?
> > > > > Thanks,
> > > > > Jon
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Your use of Yahoo! Groups is subject to
> > > > > http://docs.yahoo.com/info/terms/
> > > > >
> > > > >
> > > > >
> > > > --
> > > > Co-founder, http://www.jguru.com
> > > > Creator, ANTLR Parser Generator: http://www.antlr.org
> > > > Co-founder, http://www.peerscope.com link sharing,
pure-n-simple
> > > > Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list