[antlr-interest] Implementing main method in ANTLR

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


I guess I don't understand what exactly it is you are asking.  What do you
mean a 'main method per file'?  What other functions in which files?

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

> Hello --
>
> I don't fully understand it yet, now my top-level rule is just a rule who
> defines a list of lines. But - if I start parsing at the main method - those
> other functions in the files aren't parsed and when I'm parsing them and I
> have a print statement there it will print right away.
>
> So I kind of need to parse everything and store it in my java-classes,
> without executing anything in the functions - is this possible, would this
> require much editting?
>
> Thanks,
>
> William van Doorn
>
> 2010/4/14 Cliff Hudson <cliff.s.hudson at gmail.com>
>
> 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