[antlr-interest] Re: some (maybe stupid) questions on aquiring expected tokens.

ioffe_nick ioffe_nick at yahoo.com
Wed Oct 20 03:12:27 PDT 2004



--- In antlr-interest at yahoogroups.com, "ioffe_nick" <ioffe_nick at y...> 
wrote:
> 
> 
> Hi!
> I've some language with good LL(1) grammar.
> 1. I need to develop an interactive interface for "stupid" user.
>    It means the interface has to incorporate hiding options (tokens)
>    which are impossible to enter after some sequence of tokens.
> 2. Also the interface has to incorporate options to "remove last 
word"
>    i.e. going back and reenter some input.
> 
> As for problem 1 - I don't quite understand how should I use FIRST 
and
> FOLLOW in my case since because of 2 reasons:
> 1. I have to provide lookahead token before production is made, so I
>    have no alternatives for the LA (am I correct)
> 2. assume we have r1 -> X r2 Y and some more rules using the r2.
>    after going to r1 and making r2 production my exected is FIRST(Y)
>    which is subset of FOLLOW(r2).
>    How can I know it before getting back to r1 from r2?
> 

Regarding problem 1 I think I've solved the problem using $FIRST and
stack:

s -> {push(FIRST(b), expect = FIRST(a)}
     a {pop(), push(FIRST(c), expect = FIRST(b)}
     b {pop(), push(EOF), expect = FIRST(c)}
     c

a -> {expect = FIRST(a)}
     X {expect = FIRST(c) or top()}
    (c)*

and so on.

It seems to work good for k=1, but for k=2 it doesn't work, since
FIRST set is set of 1-length sequences of tokens.

As I understand from the group antlr 3.0 is going to be table based
and thus will provide some way to calculate the expect set.

When will it be released?

As for problem 2 - I'm still looking for advice.

> Problem 2:
> I understand that backtracking here is bad idea because of actions 
which
> have to be either undone or abandoned.
> Is reparsing the whole sequence the only option?
> Maybe <wordback> should be special unhandled token which will cause
> an expception? But how then can I get back to the correct state?
> 
> Thank you in advance,
> 
> Nick

Sincerely,

Nick





 
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