[antlr-interest] Re: Parser question

micheal_jor open.zone at virgin.net
Wed Nov 12 16:05:40 PST 2003


--- In antlr-interest at yahoogroups.com, "kevthefree" <kevthefree at y...>
wrote:
> Hi all,
> 
> I am completely new to ANTLR, I am trying to write a parser with lexer
> in ANTLR to parse a basic C function.
> 
> What do I need to do to check whether a parse has been succeed? (I
> pipe a test text file which contains a c function and it seems to
> return to the prompt without any exception, is that a success parse?)
> I don't know much about ANTLR.
> 
> Any help would be appreciated

Kevin,

Your message suggests that you know enough about ANTLR to have built a
candidate grammar for your project. So, you could:
a) ensure that the grammar builds a tree
   http://www.antlr.org/doc/options.html#_bb12
b) use the getAST() method of the parser to get the tree after parsing
c) use one of the toStringList()/toStringTree() methods to print the tree.
d) compare the tree to what you expected your grammar to generate for
the given input

See the comments in the test.g of the ASTSupport example for more info
on ANTLR trees, visualization and tree notation.

This article might help too: 
   http://www.cs.usfca.edu/~parrt/course/652/lectures/antlr.html

You can find more tutorials here:
   http://www.antlr.org/doc/getting-started.html

Cheers,

Micheal
ANTLR/C#

PS   For more advanced visualization, have a look at the ASTFrame
class (only available for C# and Java output). The java grammar sample
uses this class to display the AST.



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list