This module contains character classification functions,
very similar to the macros from "ctype.h
".
Differences are as follows:
ctype.h
".
Since I want that the input language understood by my program
is portable,
I had to program it myself.
ch_t
of character classes,
and a function classify
which returns
the class of a character.
This makes the main switch in the lexical scanner
more elegant and efficient.
Furthermore,
all characters are classified in this module,
the scanner works only with character classes.
So this is the central place where special characters can be changed
or synonyms defined.
Currently, this module is realized as a class ch_c with some class functions. It is not possible to create instances of this class.
Note that the class method init must be called before any of the other functions.
The enumeration type ch_t defines the possible character classes:
'\0'
).
Crtl+D
and Crtl+Z
.
Currently,
both characters are defined no matter what the operating system is.
If that should lead to problems,
it can easily be changed in ch_c::init
.
-
").
0123456789
").
.
").
,
).
:
").
;
").
(
").
)
").
~
".
&
").
|
").
<
").
>
").
=
").
?
").
$
").
It is used as first character of commands.
!@#^*+\{}[]"`/
"
are classified in this way.
There sometime has been a bug in my program
where it would have been useful if I had made such characters explicit
(like it is done now).
void init(void)
;
static ch_t classify(char c)
;static bool_t is_alnum(char_c)
;BOOL_TRUE
iff the input character is a letter (including national ones),
a digit,
or the underscore character ("_
").
Otherwise,
BOOL_FALSE
is returned.
static bool_t is_space(char c)
;BOOL_TRUE
iff the input character is a "white space" character,
i.e. a space, a tabulator, or a carriage return.
Note that a linefeed is not treated as white space here.
static bool_t is_comment(char c)
;BOOL_TRUE
if the input character indicates a begin of a comment.
Currently, this is the character "%
".
static bool_t is_newline(char c)
;BOOL_TRUE
iff the input character is the linefeed character.
static bool_t is_quote(char c)
;BOOL_TRUE
if the input character is a quotation character ("'
")
used in quoted atoms.
static bool_t is_undersc(char c)
;BOOL_TRUE
iff the input character is the underscore character ("_
").
The underscore character is special because of the anonymous variable.
static int ord(char c)
;ord
-values of two characters
should give the correct order.
Uppercase and lowercase characters return the same value
(whereas, if the ASCII sequence would be used,
all uppercase characters come before all lowercase characters).
Also, national characters with accents (like "äöü")
return the same values as the corresponding normal characters
(i.e. "aou").
static int xord(char c)
;ord
returns the position of the first character
and xord
returns the position of the second character.
For normal characters,
xord
returns 0.