[SLP-Homepage]
[Source Modules]
[Manual]
[Run]
[Examples]
Token Types
This module defines an enumeration type tok_t
for the different kinds of tokens.
It is one of the few modules
which does not define a class.
There is one one function (tok_name)
defined in this module
which returns a string naming the token type.
Token Types:
- TOK_EOF:
-
The end of file was reached.
- TOK_FULLSTOP:
-
A fullstop ("
.
") followed by white space.
This indicates the end of a formula/rule.
- TOK_ATOM:
-
An atom like in Prolog, i.e.
a sequence of letters and digits,
starting with a lowercase letter.
Alternatively a quoted string,
e.g.
'abc'
.
- TOK_CMD:
-
A command: A dollar sign
$
,
followed by a sequence of letters and digits.
- TOK_INT:
-
An integer,
i.e. a sequence of digits,
optionally preceded by a minus sign.
- TOK_VAR:
-
A variable like in Prolog,
i.e. a sequence of letters and digits
starting with an uppercase letter.
- TOK_ANONVAR:
-
The anonymous variable ("
_
").
- TOK_COMMA:
-
A comma ("
,
").
This can be used to separate arguments in an atomic formula
and to denote conjunction (as in Prolog).
- TOK_LPAREN:
-
A left paranthesis ("
(
").
- TOK_RPAREN:
-
A right paranthesis ("
)
").
- TOK_MON_OP:
-
A monadic (prefix) operator,
i.e. the "classical negation" sign ("
~
")
or default negation ("not
).
- TOK_BIN_OP:
-
A binary operator,
i.e. one of the following:
- The conjunction (logical and) operator ("
&
").
- The disjunction (logical or) operator ("
|
").
The disjunction can also be written as ";
".
For compatibility reasons, currently also "v
"
is still understood.
- The implication (logical if) operator ("
<-
").
The implication can also be written as in Prolog (":-
").
- The implication (logical then) operator ("
->
").
- Theequivalence operator ("
<->
").
- TOK_QUERY:
-
A question mark ("
?
").
It is used to start a query.
- TOK_COLON:
-
A colon ("
:
").
It is used in queries if answer variables are explicitly given.
Error Tokens:
In addition,
there are a number of constants indicating
different kinds of lexical errors:
- TOK_ILLEGAL_CHAR:
-
An unknown character - neither alphanumeric nor one
of the few special characters which have a defined meaning in SLP.
- TOK_LESS:
-
A less than character ("
<
")
which is not followed by a minus ("-
").
Currently the only legal use of the less than character
is in the implies operator ("<-
").
- TOK_MINUS:
-
A minus character ("
-
")
which is neither followed by a (">
")
to make it an implication operator,
nor by digits.
Currently,
no arithmetic expressions are supported.
So this use of minus is illegal.
- TOK_MISSINGQ:
-
A quoted atom was begun,
but there is no closing quote before the line end was reached.
- TOK_EMPTYA:
-
An empty atom ("
''
") is not allowed.
- TOK_NOSPACE:
-
The fullstop must be followed by white space
(as in Prolog).
Currently, we treat a "
.
" which is not followed
by a space or a newline as an error,
and not as an atom.
- TOK_INT_OVERFLOW:
-
This means an integer constant was too large.
The minimum and maximum integer are defined in
lex.h
.
Currently,
the minum integer is -65536,
and the maximum integer is 65535
(i.e. 16-bit integers).
So, if the input contains a token like 10000000
,
its token type would be TOK_INT_OVERFLOW
.
- TOK_EMPTY_CMD:
-
Illegal empty command (a dollar sign that is not followed
by a letter or number.
- TOK_RESERVED_ATOM:
-
The input was an atom that is internally used,
but cannot occur in input programs.
At the moment the only such case is "
$answer
".
Normally,
the user would get a syntax error message because this is treated
as a command on input.
This might seem a bit strange,
since the user has seen $answer
used like an atom in the output.
This special token type produces a hopefully clearer message.
Functions of This Module:
- tok_name:
-
str_t tok_name(tok_t tok)
;
This function returns a string describing the kind of token
(e.g. "atom"
).
Implementation:
Stefan Brass
(sbrass@sis.pitt.edu),
April 04, 2002.
[HTML 3.2 Checked]