From ok@atlas.otago.ac.nz Wed Oct 10 00:27:25 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f99MRNt16043
	for <prolog@swi.psy.uva.nl>; Wed, 10 Oct 2001 00:27:24 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id LAA11357;
	Wed, 10 Oct 2001 11:27:13 +1300 (NZDT)
Date: Wed, 10 Oct 2001 11:27:13 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200110092227.LAA11357@atlas.otago.ac.nz>
To: ai@solvo.ru, prolog@swi.psy.uva.nl
Subject: Re:  [SWIPL] DCG rules and error reporting

Keeping track of line numbers in DCGs?

(1) Split the parsing task into a tokenising task and a parsing task proper.
(2) In the tokenising task, either
    (a) attach source coordinates to every token.
        Instead of id(foo), use id(foo)*pos(L1,C1,L2,C2)
        where L1,C1 is where the token starts and L2,C2 is where it ends.
or  (b) attach source coordinates to selected token types,
or  (c) insert line change tokens.
(3) In the parsing task, either
    (x) construct source coordinates for non-terminals from the terminals
        (usually the first and last, or you might pick infix operators or
        something as representative) they are made of
or  (y) ignore source coordinates during parsing, just letting the
        error reporting machinery look for them.

In a parser of mine, I chose (2a,3x).  It was less work than I feared.

