Re: no reserved words

William D Clinger <>
15 Mar 1998 00:19:53 -0500

          From comp.compilers

Related articles
no reserved words (1998-03-08)
Re: no reserved words (Chris F Clark) (1998-03-12)
Re: no reserved words (Jerry Leichter) (1998-03-13)
Re: no reserved words (William D Clinger) (1998-03-15)
Re: no reserved words (Stephen P Spackman) (1998-03-18)
Re: no reserved words (Sandeep Dutta) (1998-03-18)
| List of all articles for this month |

From: William D Clinger <>
Newsgroups: comp.compilers
Date: 15 Mar 1998 00:19:53 -0500
Organization: Northeastern University
References: 98-03-091
Keywords: yacc, parse, comment

When parsing a language with no reserved words, the following trick
might allow you to use Lex and Yacc or similar tools.

Use Lex to define a token (e.g. IF, THEN, CALL) for each syntactic
keyword of the language. Also define a token NONKEYWORD for
identifiers that are not also reserved words.

Use yacc to define a nonterminal identifier as follows:

        identifier : NONKEYWORD
                              | IF
                              | THEN
                              | CALL
                              | ...

Then use the nonterminal identifier wherever you want to allow any
identifier, and use the specific tokens IF, THEN, et cetera wherever a
specific syntactic keyword must go.

You might have to resolve a lot of shift-reduce and reduce-reduce
conflicts, but those conflicts are sort of intrinsic to the grammar of
your language; you'll have to resolve them somehow no matter what
tools you use.

[See subsequent message about ambiguity problems. -John]

Post a followup to this message

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