Re: Grammar problems

"mahesha" <>
1 Feb 2001 17:42:17 -0500

          From comp.compilers

Related articles
Grammar problems (Michael Gerhardt) (2001-01-26)
Re: Grammar problems (Sebastian Moleski \(SurakWare\)) (2001-01-28)
Re: Grammar problems (mahesha) (2001-02-01)
| List of all articles for this month |

From: "mahesha" <>
Newsgroups: comp.compilers
Date: 1 Feb 2001 17:42:17 -0500
Organization: SSO-IT, Hewlett-Packard Co.
References: 01-01-158
Keywords: parse, PL/I
Posted-Date: 01 Feb 2001 17:42:17 EST

"Michael Gerhardt" <> wrote in message
> I started generating a parser in a standard grammar with the compiler
> generator coco. I do not not know if anybody is used to this tool, but
> my main problem is in the grammar itself. I need to describe in which
> it is allowed that Identifiers (variable names, etc.) CAN be called
> like keywords. I do not know who made this specification, but this is
> a severe problem for me. I wrote the complete grammar and after runnig
> through a sample of code the error occured: Compilation error: keyword
> expected...

I too had faced a similar problem when I had to write a parser for
PL/I (which does not have reserved words). Then I wrote my own parser
-a top down parser-. (I used top down approach since backtracking is
easier in topdown). If you still want to use the LR(1) grammar based
approach, you will have to enhance your lexer to understand the
current context (by getting information from parser) and return the
tokens appropriately. You will also have to do special handling during
error recovery to understand if the error is *really* an error, or is
because of a *wrongly interpreted* token returned by lexer.


Post a followup to this message

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