help-bison
[Top][All Lists]
Advanced

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

Re: Reserved Words


From: Hans Aberg
Subject: Re: Reserved Words
Date: Sat, 15 Feb 2003 00:25:21 +0100

At 20:24 +0000 2003/02/14, Mike Aubury wrote:
>I need to be able to write code which will parse :
>
>       define date date
>
>or even
>
>       define define date
>
>(and a lot more besides...)
>
>
>which defines a variable called 'date' or 'define' to be a date datatype...
>(I didn't write the language)

This is usually done by using context switches inside the lexer (scanner).
-- In Flex, these are called start conditions. When Flex sees the first
"define", it switches to a new context which disables that keyword.

More info at:
  Help-flex mailing list
  address@hidden
  http://mail.gnu.org/mailman/listinfo/help-flex

There are several different ways can tweak this further:

One way is to put all words in a lookup table, which might be iterated in
environments. When the lexer finds an identifier, it looks for the topmost
definition, and returns its type. This way you can produce typing, as in
C++.

The Bison generated parser does not see anything of this, nor needs it --
it suffices to act on the token numbers handed over by the lexer.

Sometimes one can tweak the parser grammar, but it is generally better to
put it into the lexer if you can.

  Hans Aberg






reply via email to

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