home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
aijournl
/
ai_feb87.arc
/
AIAPP.FEB
< prev
next >
Wrap
Text File
|
1987-01-29
|
8KB
|
195 lines
AI Apprentice
Figures and Listings
AI EXPERT magazine -- February 1987
|----------| |----------| |----------|
| cons | | cons | | cons |
|----------| |----------| |----------|
| --------->| --------> | ----->NIL
|----------| |----------| |----------|
| | | | | |
|----|-----| |----|-----| |----|-----|
| | |
V V V
|----------| |----------| |----------|
| functor | | constant | | variable |
|----------| |----------| |----------|
| likes | | vicky | | skiing |
|----------| |----------| |----------|
Figure 1.
Linked list representation of "likes(vicky,skiing)."
|----------| |----------| |----------|
| cons | | cons | | cons |
|----------| |----------| |----------|
| --------->| --------> | ----->NIL
|----------| |----------| |----------|
| | | | | |
|----|-----| |----|-----| |----|-----|
| | |
V V V
|----------| |----------| |----------| |---------| |---------|
| functor | | constant | | cons | | cons | | cons |
|----------| |----------| |----------| |---------| |---------|
| list | | a | | -------->| -------->| -------> NIL
|----------| |----------| |----------| |---------| |---------|
| | | | | |
|----|-----| |----|----| |----|----|
| | |
V V V
|----------| |---------| |---------|
| functor | | constant| | constant|
|----------| |---------| |---------|
| list | | b | | nil |
|----------| |---------| |---------|
Figure 2
The internal representation of list(a,list(b,nil)).
sentence ::- rule | query | command
rule ::- head '.' | head ':-' tail '.'
query ::- '?-' tail '.'
command ::- '@' file_name '.'
head ::- goal
tail ::- goal | goal ',' tail
goal ::- constant | variable | structure
constant ::- {quoted string} | {token beginning with 'a' .. 'z'}
variable ::- {identifier beginning with 'A' .. 'Z' or '_' }
structure ::- functor '(' component_list ')'
functor ::- {token beginning with 'a' .. 'z'}
component_list ::- term | term ',' component_list
term ::- goal | list
list ::- '[]' | '[' element_list ']'
element_list ::- term | term ',' element_list | term | term
file_name ::- {legitimate DOS file name, must be surrounded with
single quotes if it contains a '.',':' or '\'}
Figure 3
VTPROLOG Grammar.
PROCEDURE list(VAR l_ptr : node_ptr) ;
VAR
elem_list : node_ptr ;
PROCEDURE element_list(VAR e_list : node_ptr) ;
VAR
e_list2 : node_ptr ;
BEGIN
term(e_list) ;
IF token = ','
THEN
BEGIN
scan(source,token) ;
element_list(e_list) ;
END
ELSE IF token = '|'
THEN
BEGIN
e_list2 := NIL ;
scan(source,token) ;
term(e_list2) ;
e_list := append_list(e_list,head(e_list2)) ;
END ;
END ; (* element_list *)
BEGIN
scan(source,token) ;
IF token = ']'
THEN
BEGIN
l_ptr := append_list(l_ptr,cons(NIL,NIL)) ;
scan(source,token) ;
END
ELSE
BEGIN
elem_list := NIL ;
element_list(elem_list) ;
IF token = ']'
THEN
BEGIN
scan(source,token) ;
l_ptr := append_list(l_ptr,cons(elem_list,NIL)) ;
END
ELSE error('Missing '']''.') ;
END ;
END ; (* list *)
Figure 4
A routine to recognize lists.
|----------| |----------| |----------|
| cons | | cons | | cons |
|----------| |----------| |----------|
| --------->| --------> | ----->NIL
|----------| |----------| |----------|
| | | | | |
|----|-----| |----|-----| |----|-----|
| | |
V V V
|----------| |----------| |----------|
| constant | | constant | | constant |
|----------| |----------| |----------|
| a | | b | | c |
|----------| |----------| |----------|
Figure 5
The internal representation of [a,b,c].
|----------| |----------| |----------|
| cons | | cons | | variable |
|----------| |----------| |----------|
| --------->| --------> | Z |
|----------| |----------| |----------|
| | | |
|----|-----| |----|-----|
| |
V V
|----------| |----------|
| variable | | variable |
|----------| |----------|
| X | | Y |
|----------| |----------|
Figure 6
The internal structure of [X,Y|Z].
item | Item within the query
in the |
rule | constant variable functor list
| (C2) (V2) (F2) (L2)
|--------------------------------------------------------------------
constant | succeed if succeed fail fail
(C1) | C1 = C2 bind V2 to C1
|
variable | succeed succeed succeed succeed
(V1) | bind V1 to C2 bind V1 to V2 bind V1 to F2 bind V1 to L2
|
functor | fail succeed succeed if fail
(F1) | bind V2 to F1 expressions have
| same functor and
| arity and each
| of components
| can be unified
|
list | fail succeed fail succeed if
(L1) | bind V2 to L1 heads can be unified
| and tails can be
| unified
Table 1
Unification table for rules and queries.
| unified
Table 1
Unification table for rules and queri