Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!uunet!allegra!alice!pereira
From: pereira@alta.research.att.com (Fernando Pereira)
Subject: Re: Handling syntax errors with DCGs
In-Reply-To: John Grundy's message of 5 May 1995 02:14:41 GMT
X-Nntp-Posting-Host: alta.research.att.com
Message-ID: <PEREIRA.95May5103816@alta.research.att.com>
Sender: usenet@research.att.com (netnews <9149-80593> 0112740)
Reply-To: pereira@research.att.com
Organization: AT&T Bell Laboratories
References: <3oc1mh$ui@ogre.cs.waikato.ac.nz>
Date: Fri, 5 May 1995 14:38:16 GMT
Lines: 26

In article <3oc1mh$ui@ogre.cs.waikato.ac.nz> John Grundy <jgrundy@cs.waikato.ac.nz> writes:
   I'm using DCGs in LPA MacProlog32 to parse a language held in a text
   window. I grab the tokens using etoks/2 and then give this as a list
   to phrase/3 to process using the DCG rules I've defined.

   I'd like to be able to detect syntax errors and move the window
   cursor to the (approximate!) position of the error, beep, etc.
The DCG parser obtained through the canonical translation of DCGs to
Prolog is a top-down backtrack parser. Such parsers are notoriously
bad at error reporting. By transforming your DCG into another one (or
a corresponding Prolog program) that simulates a bottom-up parser for
the original DCG, you can generate better error reports. The public
domain Prolog read/1 implementation due to Richard O'Keefe exemplifies
the technique for parsing Prolog itself. There may be semi-automatic
tools to do these transformations around, but I don't know of one,
although I vaguely remember something like that was mentioned in this
newsgroup a while ago.
--
Fernando Pereira
2B-441, AT&T Bell Laboratories
600 Mountain Ave, PO Box 636
Murray Hill, NJ 07974-0636
pereira@research.att.com
1-908-582-3980


