This section describes the concrete syntax of Qu-Prolog 10.6
There are four syntactic forms for atoms.
newline | Meaning: Continuation. |
^ | Meaning: Same as d. |
^character | Meaning: Control character. |
dd | Meaning: A two digit octal number. |
a | Meaning: Alarm (ASCII = 7). |
b | Meaning: Backspace (ASCII = 8). |
c | Meaning: Continuation. |
d | Meaning: Delete (ASCII = 127). |
e | Meaning: Escape (ASCII = 27). |
f | Meaning: Formfeed (ASCII = 12). |
n | Meaning: Newline (ASCII = 10). |
odd | Meaning: A two digits octal number. |
r | Meaning: Return (ASCII = 13) |
s | Meaning: Space (ASCII = 32). |
t | Meaning: Horizontal tab (ASCII = 9). |
v | Meaning: Vertical tab (ASCII = 11). |
xdd | Meaning: A two digit hexadecimal number. |
Here are a few examples of quoted atoms.
'hi!'
'they''re'
'\n'
The available range of integers is -(2^31-1) to 2^31-1 on a 32 bit machine and -(2^63-1) to 2^63-1 on a 64 bit machine. Integers can be represented in any of the following ways.
Meta variables are available in three syntactic forms.
Object variable names adhere to the following EBNF grammar:
obvar-name ---> ['!']['_'] obvar-prefix obvar-suffix
obvar-prefix ---> (lower-case-letter)+
obvar-suffix ---> (letter | digit | '_')*
Notes:
Examples (where x is predeclared as an object-variable-prefix):
x
x0
!_y (anonymous)
!y_0_1
The compound terms are represented in this notation. A compound term is composed of a functor and a sequence of one or more arguments, which are enclosed in a pair of parenthesis. The functor and each of the arguments can be any term. For example:
sibling(jack, jill)
sort(qsort)(InList, OutList)
Functor(X, Y, Z)
In the first example, sibling is the functor and the arity, the number of arguments, of the term is 2. sort(qsort) is the functor of the second example and the functor itself is a compound term with sort as the functor.
A compound term has at least one argument.
If the functor of a compound term is declared as an operator by op/[3,4], terms may be written in the style of an expression. The expression is parsed according to the precedence and associativity of the operators. For example, + and * are infix operators while \+ is a prefix operator.
Number + 2 * 3
\+ X
Lists are a special kind of compound term. Lists have "." as the functor and two arguments. A special list notation is provided where the elements of a list are enclosed by a pair of "[" "]" (square brackets). The elements are separated from each other by a comma. The tail of the list, which is a term, not a sequence of terms, can be separated from the rest of the list by a "|".
For example, the following represent the same list.
[apple, orange, banana]
[apple, orange|[banana]]
[apple|[orange|[banana]]]
The atom [] represents the empty list.
Any sequence of characters enclosed by """ is considered as a strings. Strings are semantically the same as lists of ASCII codes but are stored more efficiently. Consequently the empty string ("") is parsed as the empty list ([]) and strings can unify with lists.
Example:
| ?- X = "hello", X = [H|T].
X = "hello"
H = 104
T = [101, 108, 108, 111]
| ?- X = "".
X = []
A special syntactic form recognized by the Qu-Prolog parser is that of {}-lists. The syntax for a {}-list is a '{' followed by a collection of terms each terminated by a full stop and white spaces followed by '}'. The full stop and white space after that last term is optional. A {}-list is represented in Qu-Prolog as a compound term whose functor is {} and whose only argument is a "comma pair" representing the elements of the {}-list.
For example, the following are {}-lists together with their
internal representation.
{a. b. } {}((a , b))
{a. b. c} {}((a , (b , c)))
{a} {}(a)
One use of this notation is for grouping predicate definitions together, for example as class methods, and using term expansion rules to transform the resulting {}-lists into programs.
There are two syntactic forms for quantified terms.
The general form of a substitution term is
[t_1/x_1, ..., t_n/x_n]t_m
where t_i are terms and x_i are object variables.
The substitution [t_1/x_1, ..., t_n/x_n] is applied to the term t_m.
For example:
[f(a)/x, t/y]g(X)
[[b/z]x/y][t/z]h(A)
A program is composed of a number of predicate definitions. Each predicate definition is made up of a number of clauses. Each clause has a head and an optional body. The head is either an atom or a compound term whose functor is an atom, and the body may be an atom, a meta variable or a compound term. The head and the body are connected together by ":-".
Table of Contents | Getting Started | Syntax | Built-in Predicates | Standard Operators | Notation | Index |