help-flex
[Top][All Lists]
Advanced

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

Re: RFC: enum instead of #define for tokens


From: Hans Aberg
Subject: Re: RFC: enum instead of #define for tokens
Date: Fri, 5 Apr 2002 12:21:58 +0200

At 13:20 -0500 2002/04/04, Anthony DeRobertis wrote:
>Things like %token '=', %token ',', etc. are really usefull for
>programming languages.

One way to have such a feature and avoid character tokens altogether is to
mangle the names into C/C++ labels. If Flex/Bison use the same mangling
technique one can write out the names as though they were characters. (I
have used the technique in my own OOPL, which writes C++.)

This may work, for example, like names within say `...' are treated as
tokens and mangled into C/C++ labels. It is fairly easy to make a mangling
scheme admitting any string between `...'.

Thus, Bison might work so that one writes
  a: b `!=' b { ... }
  ...
If one wants `!=', in error messages, to be written as something else, add a
  %token `!=' "not equal"

If Flex adapts the same mangling scheme, then `...' within actions should
be mangled into C/C++ labels. Thus,
  "!=" { return `!=' }
might be legal. Or one may even has that as default.

But
  . { return yytext[0]; }
would not work. It is still possible to reserve this character range, so
that Bison can issue the proper error message.

This way, one may keep the '' character feature as is, or even have an
option, giving a chance to disabling it (which will reduce the Bison
yytranslate[] table).

  Hans Aberg





reply via email to

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