[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: use of lookaheads



Hi Pieter,

Lookaheads are not implemented. One of the reasons is that the algorithm proposed in the Dragon book (which I used to implement the LALR(1) calculations) is broken; another is that it is fairly easy to
simply recognize the full regular expression, and push back the extra
characters into the pushback reader, using a custom lexer (see my thesis for an example of custom lexer).


In other words, you could write:

in = 'in';
variable = var 'in';

then in the filter() method of you custome lexer, push back 'in', then change the TVariable token's text to token.setText(token.getText().substring(....))

Have fun!

Etienne

Pieter Verheyden wrote:
Hi,

I wanted to use a lookahead for variables in my language. As a variable
is always followed by the keyword 'in', I defined the variable token as
follow:

    in = 'in';
    variable = var / 'in';

where "in" is the token for the in-keyword, and "var" is defined in the
Helpers section as:

var = letter (letter | digit )*;

With both versions, i.e. SableCC2 and SableCC3, I get the following
error:

java.lang.RuntimeException: [146,17] Look ahead not yet supported.

What does this error mean? In other words, what am I possibly doing
wrong?


Thanks in advance, Pieter.






--
Etienne M. Gagnon, Ph.D.             http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/