Related articles |
---|
Handling keywords that are not reserved? amb@Apple.COM (1991-01-15) |
Handling keywords that are not reserved? meissner@osf.org (1991-01-17) |
Newsgroups: | comp.compilers |
From: | meissner@osf.org |
In-Reply-To: | amb@Apple.COM's message of 15 Jan 91 23:38:09 GMT |
Keywords: | parse, yacc, question |
Organization: | Compilers Central |
References: | <48132@apple.Apple.COM> |
Date: | Thu, 17 Jan 91 18:53:17 -0500 |
A. Michael Burbidge writes:
|I am writing a parser for MPW's Object Pascal. Some of the extension keywords
|to standard Pascal are not reserved. I am using yacc and having some trouble
|figuring out a clean way to handle non-reserved keywords.
And John writes:
| [There isn't any clean way to handle non-reserved keywords in yacc. You
| have to feed information from the parser back to the lexer to tell it when
| a token can be a keyword and when it can't. -John]
You can do it in other ways as well. I recall that some people used
the following to parse PL/1 (which has no reserved words at all).
You have a token for each keyword, and an everything else keyword.
Then you have an identifier reduction like:
<identifier>: other
| keyword1
| keyword2
| keyword3 ... ;
You put this at the end of the file, so that yacc's default rules (of
chosing the shift over a reduce rule in case of a conflict in a
shift/reduce conflict) will give you what you want. In order to
eliminate the shift/reduce conflicts, you then need to have
productions like:
<identifier_except_keyword1>: other
| keyword2
| keyword3 ... ;
<identifier_except_keyword2>: other
| keyword1
| keyword3 ... ;
You do have to make sure that in general the rules with the special
keywords come before the more general rules.
--
Michael Meissner email: meissner@osf.org phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.