[comp.lang.prolog] Query - DCGs and parse error handling

pgl@cup.portal.com (Peter G Ludemann) (10/18/90)

> I have recently started to use Prolog DCGs (Definite Clause Grammars)
> to implement a command parser, but have found it very hard to give
> effective error messages besides the uninformative 'Parse Error'.

For parsing computer languages, I've managed to produce reasonable
error messages by adding error productions.  There's a fair amount
of literature on how to do this -- a readily available text is
Wirth's "Programs = Data Structures + Algorithms" which contains
an LL(1) [top-down] parser and which uses a simple look-ahead to
see if things make sense.

If your system supports XGs or similar, you can do lookahead:
	lookahead(X), [X] --> [X] .
which checks for the token X but doesn't consume it.

- peter ludemann	ludemann@mlpvm1.iinus1.ibm.com