Re: Help: PCLEX, PCYACC and reserved words

Mark Thiehatten <mark@research.techforce.nl>
10 Dec 1997 00:34:01 -0500

          From comp.compilers

Related articles
Help: PCLEX, PCYACC and reserved words garryw@cyberus.com (Garry Whitworth) (1997-12-05)
Re: Help: PCLEX, PCYACC and reserved words fjh@murlibobo.cs.mu.OZ.AU (1997-12-07)
Re: Help: PCLEX, PCYACC and reserved words mark@research.techforce.nl (Mark Thiehatten) (1997-12-10)
Re: Help: PCLEX, PCYACC and reserved words clark@quarry.zk3.dec.com (Chris Clark USG) (1997-12-10)
| List of all articles for this month |
From: Mark Thiehatten <mark@research.techforce.nl>
Newsgroups: comp.compilers
Date: 10 Dec 1997 00:34:01 -0500
Organization: TechForce BV
References: 97-12-036
Keywords: lex, parse

Garry Whitworth wrote:
> 2nd Question: The language I am dealing with also allows the
> programmer to declare a variable using one of its reserved word


> [Yuck. Sometimes you can get away with an ugly grammar that says
>
> symbol | thiskeyword | thatkeyword | theotherkeyword
>
> all over the place, or maybe you can identify the contexts well enough in
> the parser to tell the lexer when it's expecting a keyword and when it
> isn't. -John]


This is indeed an extremely disgusting problem. A possible way to deal
with this is to write a piece of code that emulates yacc to see if the
keyword is acceptable at that point. The way to use this code is to
have it check every keyword for acceptablity (it should not cause a
parse error immediately) and if not, convert it to a regular
identifier. I could post the code for the bison engine, but I don't
know how well (if at all) it would apply to other yacc clones. The
trick is to copy the state stack, and perform reduces until the
keyword must be shifted or causes an error. If that happens, the
keyword can not be accepted at this point and has to be converted to
an identifier. Unfortunately, this code does require reading of the
parse engine, which has not been written with easy reading in mind.




M. Thiehatten


-----------------------------------------------------------------
Ir. M.J.M. Thiehatten TechForce BV
mark thiehatten (at) research techforce nl P.O. Box 3108
Tel. +31 (0)23 5622929 2130 KC Hoofddorp
Fax +31 (0)23 5627052 The Netherlands
--


Post a followup to this message

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