help-flex
[Top][All Lists]
Advanced

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

Re: Look ahead question (trailing context)


From: Hans Aberg
Subject: Re: Look ahead question (trailing context)
Date: Wed, 31 Mar 2004 20:58:42 +0200

At 16:12 +0100 2004/03/31, Henrik Sorensen wrote:
>Does anybody have an idea of how to look the token following a set of
>matching
>parentesis?
>
>In pl1 it is valid to use keywords as variable names, and this of course
>makes
>the grammar very ambiguous, and not really lalr(1). So I would like the
>scanner to help out with some of this.
>
>In pl1 arrays are referenced using parentesis around the subscripts.
>
>So if both the previously matched token and the token following
>the matched ')'  is known, it can be determined whether a matched keyword
>token, is really a variable name or a keyword.
>
>Eg:
>1) The display statement:
>       DISPLAY(1) ;
>2)  The array variable named display:
>       DISPLAY(1)=4;
>
>in the first sample flex should return the DISPLAY keyword token for the
>statement and in the second return VARNAME for variable.

This is very difficult to do in Flex, especially if the stuff within (...)
can be an expression. In principle, you can make a lookahead for the
matching ")", resolve it at the next token, and then put the stuff back in
the line. But that would require some work.

One way to do it in the future might be to make use of say Bison's GLR
parser, and let Flex return both the tokens DISPLAY and VARNAME. It would
then split until resolved at a later point in the parse.

This has been put up as a suggestion, but Flex can't do that for now.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]