1 /********************************************************************/
2 /* */
3 /* s7 Seed7 interpreter */
4 /* Copyright (C) 1990 - 2000 Thomas Mertes */
5 /* */
6 /* This program is free software; you can redistribute it and/or */
7 /* modify it under the terms of the GNU General Public License as */
8 /* published by the Free Software Foundation; either version 2 of */
9 /* the License, or (at your option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public */
17 /* License along with this program; if not, write to the */
18 /* Free Software Foundation, Inc., 51 Franklin Street, */
19 /* Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* */
21 /* Module: General */
22 /* File: seed7/src/chclsutl.c */
23 /* Changes: 1990, 1991, 1992, 1993, 1994 Thomas Mertes */
24 /* Content: Compute the type of a character very quickly. */
25 /* */
26 /* The procedure init_chclass initializes several arrays to obtain */
27 /* the type of a character very quickly. The is.. procedures from */
28 /* the c-library give not exact the results we need here. Our */
29 /* procedures are also defined for EOF and need no bit operation */
30 /* with a mask. Our arrays contain direct boolean values, so only */
31 /* one array access is necessary and this brings speed. No joke: */
32 /* The character class is used in the scanner which consumes */
33 /* approx 40 to 50 % of analyze time. The arrays are accessed via */
34 /* macros defined in chclsutl.h. This macros use the EOF value */
35 /* because it can be (0) or (-1) (see K&R 1). */
36 /* Don't fear the runtime penalty: The compiler can do the */
37 /* calculation with EOF at compile time. */
38 /* */
39 /********************************************************************/
40
41 #define LOG_FUNCTIONS 0
42 #define VERBOSE_EXCEPTIONS 0
43
44 #include "version.h"
45
46 #include "stdio.h"
47
48 #include "common.h"
49
50 #undef EXTERN
51 #define EXTERN
52 #include "chclsutl.h"
53
54
55
init_chclass(void)56 void init_chclass (void)
57
58 {
59 int character;
60
61 /* init_chclass */
62 logFunction(printf("init_chclass\n"););
63 for (character = 0; character <= 255; character++) {
64 char_class(character) = ILLEGALCHAR;
65 name_character(character) = FALSE;
66 op_character(character) = FALSE;
67 no_escape_char(character) = FALSE;
68 std_comment_char(character) = TRUE;
69 } /* for */
70
71 for (character = '!'; character <= '/'; character++) {
72 char_class(character) = SPECIALCHAR;
73 } /* for */
74 for (character = '0'; character <= '9'; character++) {
75 char_class(character) = DIGITCHAR;
76 } /* for */
77 for (character = ':'; character <= '@'; character++) {
78 char_class(character) = SPECIALCHAR;
79 } /* for */
80 for (character = 'A'; character <= 'Z'; character++) {
81 char_class(character) = LETTERCHAR;
82 } /* for */
83 for (character = '['; character <= '`'; character++) {
84 char_class(character) = SPECIALCHAR;
85 } /* for */
86 for (character = 'a'; character <= 'z'; character++) {
87 char_class(character) = LETTERCHAR;
88 } /* for */
89 for (character = '{'; character <= '~'; character++) {
90 char_class(character) = SPECIALCHAR;
91 } /* for */
92
93 char_class(' ') = SPACECHAR;
94 char_class('_') = UNDERLINECHAR;
95 char_class('#') = SHARPCHAR;
96 char_class('\'') = APOSTROPHECHAR;
97 char_class('\"') = QUOTATIONCHAR;
98 char_class('(') = LEFTPARENCHAR;
99 char_class(')') = PARENCHAR;
100 char_class('[') = PARENCHAR;
101 char_class(']') = PARENCHAR;
102 char_class('{') = PARENCHAR;
103 char_class('}') = PARENCHAR;
104 char_class('\t') = SPACECHAR;
105 char_class('\n') = NEWLINECHAR;
106 char_class('\r') = SPACECHAR;
107 char_class(EOF) = EOFCHAR;
108
109 for (character = ' '; character <= '~'; character++) {
110 if (char_class(character) == DIGITCHAR ||
111 char_class(character) == LETTERCHAR) {
112 name_character(character) = TRUE;
113 } /* if */
114 if (char_class(character) == SPECIALCHAR) {
115 op_character(character) = TRUE;
116 } /* if */
117 no_escape_char(character) = TRUE;
118 } /* for */
119
120 name_character('_') = TRUE;
121 name_character(EOF) = FALSE;
122
123 op_character(EOF) = FALSE;
124
125 no_escape_char('\\') = FALSE;
126 no_escape_char('\"') = FALSE;
127 no_escape_char(EOF) = FALSE;
128
129 std_comment_char('(') = FALSE;
130 std_comment_char('*') = FALSE;
131 std_comment_char('\n') = FALSE;
132 std_comment_char(EOF) = FALSE;
133
134 for (character = '0'; character <= '9'; character++) {
135 digit_value[character] = (uintType) character - (uintType) '0';
136 } /* for */
137 for (character = 'A'; character <= 'Z'; character++) {
138 digit_value[character] = (uintType) 10 +
139 (uintType) character - (uintType) 'A';
140 } /* for */
141 for (character = 'a'; character <= 'z'; character++) {
142 digit_value[character] = (uintType) 10 +
143 (uintType) character - (uintType) 'a';
144 } /* for */
145 logFunction(printf("init_chclass -->\n"););
146 } /* init_chclass */
147