[antlr-interest] Implementing main method in ANTLR

Cliff Hudson cliff.s.hudson at gmail.com
Wed Apr 14 11:39:52 PDT 2010


A simple main method would be one which determines where the input is going
to be coming from, then creates an input stream based on that location (for
instance, an ANTLRStringStream for something from a string, or
ANTLRFileStream for something from a file.)  Then you create your Lexer and
pass that input to the lexer.  You then create a token stream, such as
CommonTokenStream and pass it your lexer.  You then create your parser and
pass it your token stream.  You then invoke which ever rule you wish on your
parser - typically your top level rule whatever that may be.  If you are
using a tree parser, your parser call will return a tree.  You would then
instantiate your tree parser, and invoke one of its rules passing in your
tree.  Repeat this sequence for as many inputs as you desire.

On Wed, Apr 14, 2010 at 11:27 AM, William v Doorn
<williamvdoorn at gmail.com>wrote:

> Hello,
>
> I've been working with ANTLR for quite some time now - and now I want to
> implement a main method per file. However, I really have no idea how to do
> this. I'm generating AST trees and then walk over those. But, how would I
> implement a main method?
>
> If anyone has an idea/approach on how to go about it - please tell me,
> thanks.
>
> William v. Doorn
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list