[antlr-interest] Pushing Characters onto the InputBuffer

Ric Klaren klaren at cs.utwente.nl
Mon Mar 1 09:46:05 PST 2004


Hi,

On Mon, Mar 01, 2004 at 08:13:56AM -0800, Jason wrote:
> I'm trying to convert a yacc grammar which makes heavy use of yacc's
> yyless/unput facilities.  Does ANTLR provide a means from within an action
> to push an arbitrary set of characters onto the input stream?

I trust you mean lex or flex?

No. And it's not advisable to do so unless you really really really really
know what you're doing. You'll very likely to break the use of syntactic
predicates (if you use them). Line/column counting might also be broken.
I'm not saying it might not be possible to do though but it would require
some serious debugging/testing, I would not be surprised if it might be
impossible in some cases. It really sounds like you want to use syntactic
predicates (e.g. guessing mode).

In the case you want to control this unputting of characters from the
parser I can again not recommend this unless you really really .. etc. ;)

> I've poked around the code a bit but it seems that the InputBuffer's queue
> is protected.  It would be easy enough for me to expose the queue and
> rebuild ANTLR but I'd rather not do this if I don't have to.  It's possible
> that in general the use of syntactic predicates eliminates the need for
> this kind of behavior but I'm trying to keep my ANTLR grammar as close to
> its yacc counterpart as possible.  So, is there some way to add characters
> to the stream or do I have to roll my own ANTLR?

Using predicates might give you a more elegant solution. But if you feel
adventurous ;)

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  Xander: "Buffy, we need to do something *now*"
  Angel: "We need a distraction."
  Buffy: "Right."
  Angel: "What are you going to do?"
  Buffy: "I'm going to kill them all. That oughtta distract 'em..."


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list