help-flex
[Top][All Lists]
Advanced

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

Separate sign from number (was: Where're experts?)


From: Vincent Zweije
Subject: Separate sign from number (was: Where're experts?)
Date: Tue, 2 Dec 2003 12:10:20 +0100

Alejandro Catala Bolos <address@hidden> wrote:

> I have a problem when I define my lexic in FLEX. Where can I
> contact with
> experts using FLEX?

I don't think you need a flex expert for this.

> My problem is:
> - I need parse signed integer but when I use it in aritmetic
> expressions, flex
> always scans the signed integer when it must scan ADD token.
> (i.e: a+1 , must be:ID_TOK ADD_TOK INT_TOK but FLEX return
> ID_TOK INT_TOK)

The problem: flex always returns the longest prefix of the
input that yields a valid token.

There are several solutions:

[1] Do not put the sign in the number token, but make it a
    separate token. Decide in a higher-level grammar whether
    the sign is a unary or a binary operator.

    This is best in my opinion, because it gives fewest
    surprises to the user.

[2] Define whitespace, and require the user to put
    whitespace between the sign and the number.

    This is more cumbersome on the user, but easy for you.

[3] Use flex start conditions to distinguish when the sign
    should be part of the following number, or a token in
    itself.

    This is harder for you and less transparent, but it will
    give you a signed number token if that is really what
    you need.

There are probably other solutions.

Good luck.                                          Vincent.




reply via email to

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