CMU Artificial Intelligence Repository
DCTG: Prolog definite clause translation grammar
Definite Clause Translation Grammars are described in chapter 9 of
Abramson and Dahl's book "Logic Grammars". They were devised by
Abramson to overcome the defects of Definite Clause Grammars, in which
syntax and semantics are often mixed in a non-modular fashion. They
avoid also the problem with the proliferation of unnamed arguments
that afflicts Definite Clause Grammars.
In a DCTG, the syntax and semantics are separated. Each rule contains
first a syntactic part, and then an optional semantics, written as one
or more clauses. An example is given below. See Ambramson and Dahl's
book for more details. The code in this package comes from Appendix
II of the book, with a few minor changes by Jocelyn Paine.
The following example shows how to parse binary numbers with binary
points (such as 1.1 or 1001.11) when expressed as lists ([1,'.',1] or
bit ::= 
bitval( 0, _ ).
bit ::= 
bitval( V,Scale ) ::- V is **(2,Scale).
bitstring ::= 
bitstring ::= bit^^B, bitstring^^B1
length( Length ) ::-
B1 ^^ length(Length1),
Length is Length1 + 1
value( Value, ScaleB ) ::-
B ^^ bitval( VB, ScaleB ),
S1 is ScaleB - 1,
B1 ^^ value( V1, S1 ),
Value is VB + V1.
number ::= bitstring ^^ B, fraction ^^ F
B ^^ length(Length),
S is Length-1,
B ^^ value( VB, S ),
F ^^ fractional_value( VF ),
V is VB + VF.
fraction ::= ['.'], bitstring ^^ B
fractional_value( V ) ::-
S is -1,
B ^^ value( V, S ).
fraction ::= 
test( L, V ) :-
write( 'LIST ' ), write( L ), nl,
number( Tree, L,  ),
Tree ^^ value( V ),
write( 'VALUE ' ), write( V ), nl, nl.
?- test( [1,'.',1], V ).
/* Should set V to 1.5. */
Ports: Edinburgh-compatible Prologs.
CD-ROM: Prime Time Freeware for AI, Issue 1-1
Author(s): Harvey Abramson and Veronica Dahl
Authors!Abramson, Authors!Dahl, Books!Prolog, DCG, DCTG,
Definite Clause Grammar, Definite Clause Translation Grammar,
Prolog!Code, Prolog!Syntax, Syntax
Harvey Abramson and Veronica Dahl, "Logic Grammars", Springer Verlag, 1989.
Last Web update on Mon Feb 13 10:34:00 1995