[antlr-interest] Antlrworks cant two instances of parser

Thomas Brandon tbrandonau at gmail.com
Mon Jul 2 00:32:10 PDT 2007


On 7/2/07, chintan rao <chintanraoh at gmail.com> wrote:
> Hi,
> Thanks for all your time.
> On 7/2/07, Thomas Brandon <tbrandonau at gmail.com> wrote:
> > ANTLRWorks debug parsers listen on a socket to connect to the
> > ANTLRWorks debugger. As your main parser is already using this socket
> > the sub-parser cannot also use it. If your inner parser is different
> > to your outer parser then you could use a non-debug version of the
> > inner parser. Or if they are the same, you could, while debugging
> > create a second copy of your parser with a new name and generate this
> > without debugging enabled and then use that for your inner parser, or
> > just generate to a different package and use a fully qualified name
> > for it.
> Hmm.. This seems to a sort of solution. Tedious but okay .
> > Alternately there is a constructor that takes a port to debug on, so
> > if you used this constructor with a different port then they should
> > not clash. However then your inner parser will wait for socket
> > connections from ANTLRWorks to start parsing, maybe you could have two
> > copies of ANTLRWorks open (if it allows this) and connect the second
> > copy to the inner parser, though you would have to connect ANTLRWorks
> > after the constructor for you inner parser was called so if the inner
> > parser is constructed as needed then you would have to re-connect
> > ANTLRWorks everytime one was started. So unless you reuse a single
> > parser instance this is somewhat tricky.
> I did new nameParser(token,port no) and made another copy of antlrworks
> work on the port but it did not work :(. It was waiting for ever for
> the connection.
I would think this should work, if you can have two copies of
ANTLRWorks open. I didn't mention it but you have to do a Debug remote
after the construction of your new parser. And if your not using a
shared instance of your parser then do so again after each
instantiation. And, if you are using a shared copy I'm not sure if
ANTLRWorks will properly handle the resetting of the parser.
> > There is a constructor for DebugParser which accepts a debug listener
> > but ANTLRWorks does not add an override for this constructor to it's
> > debug parsers, if you added an override for this constructor then you
> > could have your inner parser not wait for ANTLRWorks by providing an
> > alternate debug listener. You can add this constructor to your
> > @members section but then you need to remove it when not compiling
> > with debugging.
> I added the required constructor and  called it with
> new nameParser( token,getDebugListener () ) . This also did not work :(
Yes, I don't think ANTLRWorks would like multiple parsers connected to
one debug listener. I was more suggesting you use nameParser(token,
new BlankDebugListener()) or you could use one of the other listeners
(see org.antlr.runtime.debug classes) to at least have tracing on the
inner parsers.
>
> > I requested that ANTLRWorks template be changed to also override this
> > constructor. In the meantime it would be a fairly trivial patch to the
> > ANTLRWorks templates to allow this.
>
> Also another point is that i could have variable no of recursive calls
> to the parser . So these
> solutions may not work well.A good feature in the ide will be to make
> both inner and outer parsers work on the same instance of the debugger
> ie let debugger make connections to any no of parsers. I don't know
> how hard or easy this is it but I do understand that this can be very
> difficult .
I imagine this would be rather difficult to support and not a big
priority given this isn't exactly a common usage.
> Another good feature would be to add a method setDebug(bool) to the DebugParser
> class.
Passing BlankDebugListener to the (added) constructor should give this
functionality.
> Currently i am working without the antlrworks IDE when i make
> recursive calls to the same parser.
>
Tom.


More information about the antlr-interest mailing list