<program> ::= <predicate> | <program><predicate>
<predicate> ::= <clause> | <predicate><clause>
<clause> ::= <base clause> | <nonbase clause>
Two clauses belong to the same predicate if they have the same
functor (name) and the same arity (number of arguments).
Thus, mother(jane)
and mother(jane, jim)
are
different predicates.
<base clause> ::= <structure> .
<nonbase clause> ::= <structure> :- <structures> .
<structures> ::= <structure> | <structure> , <structures>
A structure is a functor followed by zero or more arguments;
the arguments are enclosed in parentheses and separated by commas.
There must be no space between the functor and the opening
parenthesis! If there are no arguments, the parentheses are
omitted.
<structure> ::= <name> | <name> ( <arguments> )
<arguments> ::= <argument> | <argument> , <arguments>
Arguments may be any legal Prolog values or variables.A variable is written as a sequence of letters and digits, beginning with a capital letter. The underscore (_) is considered to be a capital letter.
An atom is any sequence of letters and digits, beginning with a
lowercase letter. Alternatively, an atom is any sequence of
characters, enclosed by single quotes ('); an internal single quote
must be doubled. Examples: cat
, r124c41
,
max_value
, maxValue
, 'max
value'
, 'Don''t go'
.
As syntactic sugar, Prolog allows certain infix operators: ','
(comma), ';' (semicolon), ':-' (turnstile), +, -, *, /, =, ==, and
many others. These are the same as the operator written as the
functor of a structure; for example, 2+2 is the same as
'+'(2,2)
.
Comments begin with the characters /*
and end with
*/
. Comments are not restricted to a single line, but may
not be nested.
Example: /* This is a comment. */
|
|