|keywords and identifiers.. firstname.lastname@example.org (1999-09-11)|
|Re: keywords and identifiers.. email@example.com (1999-09-16)|
|Re: keywords and identifiers.. firstname.lastname@example.org (Chris F Clark) (1999-09-16)|
|Re: keywords and identifiers.. email@example.com (Armel) (1999-09-16)|
|Re: keywords and identifiers.. firstname.lastname@example.org (Jerry Leichter) (1999-09-20)|
|Re: keywords and identifiers.. email@example.com (1999-09-24)|
|Re: keywords and identifiers.. firstname.lastname@example.org (Leif Leonhardy) (1999-09-27)|
|Date:||11 Sep 1999 09:08:21 -0400|
Had a small question concerning keywords/identifiers and possibly
languages in general. Are there languages which allow a keyword to be
accepted as an identifier. I have familiarity with Pascal/C/C++/Java
and those don't. Like consider the following example in C
A function named void,
An example of a keyword of the language being used as an identifier.
int void ()
And, if a compiler were to be written for such a language, how would
the parser/laxical analyzer interact. My idea here is for the parser
to specify to the lexical analyzer what token (or set of tokens) it
expects and the lexical analyzer checks to see if the current token
lies in that set, else it signals an error.
I'd appreciate some of the compiler guru's viewpoints/ideas on this.
If it helps, the language I am using to write the parser is C++, because
I am going to modify an existing parser.
Thanks a lot in advance,
[Yes, lots of languages don't reserve their keywords, with Fortran and
PL/I being among the better known examples. One approach is to concoct
an extended syntax with rules like this that permit keywords to act as
symbol: SYMBOL | IF | THEN | ELSE | ...
but that usually ends up being hopelessly ambiguous. The other approach
is to keep enough lexical state to know when a keyword is possible and
when not, and for the lexer to hand back the appropriate kind of token.
I've done that in a Fortran parser. It wasn't very hard, although some
of the state management kludges were really ugly. -John]
Return to the
Search the comp.compilers archives again.