[antlr-interest] How can I generate output with ANTLR?

Bryan Ewbank ewbank at gmail.com
Sat Sep 3 05:50:13 PDT 2005


Luciana asked:
> I would like to know how can I generate output. For example: if anyone 
> writes "a is equal to b", I would like to generate "a == b". 

It looks like you are very close;  you have "is equal to" generate
"==".  If everything is this direct, then you can simply have the
identifiers generate their names and you're done.

I think you should just keep doing what you are doing - perhaps start
with a simpler grammar that just recognizes "a equals b" (and nothing
else), the better to understand ANTLR in isolation from your problem.

Once you are able to process "a equals b", you can start to focus on
the problem (language recognition), rather than the tools you will be
using (ANTLR).

Remember that ANTLR just provides a framework for parsing a language,
for walking and manipulating parse trees, and for performing
user-specied actions when particular patterns (sequences, for parsing;
tree shapes, for tree parsers). are detected.  It is up to you to
figure out what actions are needed.

In your case, it sounds like it's "generate the equivalent java" - and
your grammar already has some of that in it.


More information about the antlr-interest mailing list