keywords and identifiers..

ash_nw@my-deja.com
11 Sep 1999 09:08:21 -0400

          From comp.compilers

Related articles
keywords and identifiers.. ash_nw@my-deja.com (1999-09-11)
Re: keywords and identifiers.. wmm@fastdial.net (1999-09-16)
Re: keywords and identifiers.. world!cfc@uunet.uu.net (Chris F Clark) (1999-09-16)
Re: keywords and identifiers.. webid@asi.fr (Armel) (1999-09-16)
Re: keywords and identifiers.. jerrold.leichter@smarts.com (Jerry Leichter) (1999-09-20)
Re: keywords and identifiers.. genew@shuswap.net (1999-09-24)
Re: keywords and identifiers.. delta-t@t-online.de (Leif Leonhardy) (1999-09-27)
| List of all articles for this month |
From: ash_nw@my-deja.com
Newsgroups: comp.compilers
Date: 11 Sep 1999 09:08:21 -0400
Organization: Compilers Central
Keywords: syntax, question

Hi everyone,


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,


Ash
[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
symbols.


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]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.