a68g-keywords.c
1 //! @file a68g-keywords.c
2 //! @author J. Marcel van der Veer
3
4 //! @section Copyright
5 //!
6 //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
7 //! Copyright 2001-2024 J. Marcel van der Veer [algol68g@xs4all.nl].
8
9 //! @section License
10 //!
11 //! This program is free software; you can redistribute it and/or modify it
12 //! under the terms of the GNU General Public License as published by the
13 //! Free Software Foundation; either version 3 of the License, or
14 //! (at your option) any later version.
15 //!
16 //! This program is distributed in the hope that it will be useful, but
17 //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 //! more details. You should have received a copy of the GNU General Public
20 //! License along with this program. If not, see [http://www.gnu.org/licenses/].
21
22 //! @section Synopsis
23 //!
24 //! Algol 68 keyword tables.
25
26 #include "a68g.h"
27 #include "a68g-parser.h"
28
29 //! @brief Add token to the token tree.
30
31 TOKEN_T *add_token (TOKEN_T ** p, char *t)
32 {
33 char *z = new_fixed_string (t);
34 while (*p != NO_TOKEN) {
35 int k = strcmp (z, TEXT (*p));
36 if (k < 0) {
37 p = &LESS (*p);
38 } else if (k > 0) {
39 p = &MORE (*p);
40 } else {
41 return *p;
42 }
43 }
44 *p = (TOKEN_T *) get_fixed_heap_space ((size_t) SIZE_ALIGNED (TOKEN_T));
45 TEXT (*p) = z;
46 LESS (*p) = MORE (*p) = NO_TOKEN;
47 return *p;
48 }
49
50 //! @brief Find keyword, from token name.
51
52 KEYWORD_T *find_keyword (KEYWORD_T * p, char *t)
53 {
54 while (p != NO_KEYWORD) {
55 int k = strcmp (t, TEXT (p));
56 if (k < 0) {
57 p = LESS (p);
58 } else if (k > 0) {
59 p = MORE (p);
60 } else {
61 return p;
62 }
63 }
64 return NO_KEYWORD;
65 }
66
67 //! @brief Find keyword, from attribute.
68
69 KEYWORD_T *find_keyword_from_attribute (KEYWORD_T * p, int a)
70 {
71 if (p == NO_KEYWORD) {
72 return NO_KEYWORD;
73 } else if (a == ATTRIBUTE (p)) {
74 return p;
75 } else {
76 KEYWORD_T *z;
77 if ((z = find_keyword_from_attribute (LESS (p), a)) != NO_KEYWORD) {
78 return z;
79 } else if ((z = find_keyword_from_attribute (MORE (p), a)) != NO_KEYWORD) {
80 return z;
81 } else {
82 return NO_KEYWORD;
83 }
84 }
85 }
86
87 //! @brief Add keyword to the tree.
88
89 void add_keyword (KEYWORD_T ** p, int a, char *t)
90 {
91 while (*p != NO_KEYWORD) {
92 int k = strcmp (t, TEXT (*p));
93 if (k < 0) {
94 p = &LESS (*p);
95 } else {
96 p = &MORE (*p);
97 }
98 }
99 *p = (KEYWORD_T *) get_fixed_heap_space ((size_t) SIZE_ALIGNED (KEYWORD_T));
100 ATTRIBUTE (*p) = a;
101 TEXT (*p) = t;
102 LESS (*p) = MORE (*p) = NO_KEYWORD;
103 }
104
105 //! @brief Make tables of keywords and non-terminals.
106
107 void set_up_tables (void)
108 {
109 // Entries are randomised to balance the tree.
110 if (OPTION_STRICT (&A68_JOB) == A68_FALSE) {
111 add_keyword (&A68 (top_keyword), ENVIRON_SYMBOL, "ENVIRON");
112 add_keyword (&A68 (top_keyword), DOWNTO_SYMBOL, "DOWNTO");
113 add_keyword (&A68 (top_keyword), UNTIL_SYMBOL, "UNTIL");
114 add_keyword (&A68 (top_keyword), CLASS_SYMBOL, "CLASS");
115 add_keyword (&A68 (top_keyword), NEW_SYMBOL, "NEW");
116 add_keyword (&A68 (top_keyword), DIAGONAL_SYMBOL, "DIAG");
117 add_keyword (&A68 (top_keyword), TRANSPOSE_SYMBOL, "TRNSP");
118 add_keyword (&A68 (top_keyword), ROW_SYMBOL, "ROW");
119 add_keyword (&A68 (top_keyword), COLUMN_SYMBOL, "COL");
120 add_keyword (&A68 (top_keyword), CODE_SYMBOL, "CODE");
121 add_keyword (&A68 (top_keyword), EDOC_SYMBOL, "EDOC");
122 add_keyword (&A68 (top_keyword), ANDF_SYMBOL, "THEF");
123 add_keyword (&A68 (top_keyword), ORF_SYMBOL, "ELSF");
124 add_keyword (&A68 (top_keyword), ANDF_SYMBOL, "ANDTH");
125 add_keyword (&A68 (top_keyword), ORF_SYMBOL, "OREL");
126 add_keyword (&A68 (top_keyword), ANDF_SYMBOL, "ANDF");
127 add_keyword (&A68 (top_keyword), ORF_SYMBOL, "ORF");
128 add_keyword (&A68 (top_keyword), ALIF_SYMBOL, "ALIF");
129 }
130 add_keyword (&A68 (top_keyword), POINT_SYMBOL, ".");
131 add_keyword (&A68 (top_keyword), COMPLEX_SYMBOL, "COMPLEX");
132 add_keyword (&A68 (top_keyword), ACCO_SYMBOL, "{");
133 add_keyword (&A68 (top_keyword), OCCA_SYMBOL, "}");
134 add_keyword (&A68 (top_keyword), SOUND_SYMBOL, "SOUND");
135 add_keyword (&A68 (top_keyword), COLON_SYMBOL, ":");
136 add_keyword (&A68 (top_keyword), THEN_BAR_SYMBOL, "|");
137 add_keyword (&A68 (top_keyword), SUB_SYMBOL, "[");
138 add_keyword (&A68 (top_keyword), BY_SYMBOL, "BY");
139 add_keyword (&A68 (top_keyword), OP_SYMBOL, "OP");
140 add_keyword (&A68 (top_keyword), COMMA_SYMBOL, ",");
141 add_keyword (&A68 (top_keyword), AT_SYMBOL, "AT");
142 add_keyword (&A68 (top_keyword), PRIO_SYMBOL, "PRIO");
143 add_keyword (&A68 (top_keyword), STYLE_I_COMMENT_SYMBOL, "CO");
144 add_keyword (&A68 (top_keyword), END_SYMBOL, "END");
145 add_keyword (&A68 (top_keyword), GO_SYMBOL, "GO");
146 add_keyword (&A68 (top_keyword), TO_SYMBOL, "TO");
147 add_keyword (&A68 (top_keyword), ELSE_BAR_SYMBOL, "|:");
148 add_keyword (&A68 (top_keyword), THEN_SYMBOL, "THEN");
149 add_keyword (&A68 (top_keyword), TRUE_SYMBOL, "TRUE");
150 add_keyword (&A68 (top_keyword), PROC_SYMBOL, "PROC");
151 add_keyword (&A68 (top_keyword), FOR_SYMBOL, "FOR");
152 add_keyword (&A68 (top_keyword), GOTO_SYMBOL, "GOTO");
153 add_keyword (&A68 (top_keyword), WHILE_SYMBOL, "WHILE");
154 add_keyword (&A68 (top_keyword), IS_SYMBOL, ":=:");
155 add_keyword (&A68 (top_keyword), ASSIGN_TO_SYMBOL, "=:");
156 add_keyword (&A68 (top_keyword), COMPL_SYMBOL, "COMPL");
157 add_keyword (&A68 (top_keyword), FROM_SYMBOL, "FROM");
158 add_keyword (&A68 (top_keyword), BOLD_PRAGMAT_SYMBOL, "PRAGMAT");
159 add_keyword (&A68 (top_keyword), BOLD_COMMENT_SYMBOL, "COMMENT");
160 add_keyword (&A68 (top_keyword), DO_SYMBOL, "DO");
161 add_keyword (&A68 (top_keyword), STYLE_II_COMMENT_SYMBOL, "#");
162 add_keyword (&A68 (top_keyword), CASE_SYMBOL, "CASE");
163 add_keyword (&A68 (top_keyword), LOC_SYMBOL, "LOC");
164 add_keyword (&A68 (top_keyword), CHAR_SYMBOL, "CHAR");
165 add_keyword (&A68 (top_keyword), ISNT_SYMBOL, ":/=:");
166 add_keyword (&A68 (top_keyword), REF_SYMBOL, "REF");
167 add_keyword (&A68 (top_keyword), NIL_SYMBOL, "NIL");
168 add_keyword (&A68 (top_keyword), ASSIGN_SYMBOL, ":=");
169 add_keyword (&A68 (top_keyword), FI_SYMBOL, "FI");
170 add_keyword (&A68 (top_keyword), FILE_SYMBOL, "FILE");
171 add_keyword (&A68 (top_keyword), PAR_SYMBOL, "PAR");
172 add_keyword (&A68 (top_keyword), ASSERT_SYMBOL, "ASSERT");
173 add_keyword (&A68 (top_keyword), OUSE_SYMBOL, "OUSE");
174 add_keyword (&A68 (top_keyword), IN_SYMBOL, "IN");
175 add_keyword (&A68 (top_keyword), LONG_SYMBOL, "LONG");
176 add_keyword (&A68 (top_keyword), SEMI_SYMBOL, ";");
177 add_keyword (&A68 (top_keyword), EMPTY_SYMBOL, "EMPTY");
178 add_keyword (&A68 (top_keyword), MODE_SYMBOL, "MODE");
179 add_keyword (&A68 (top_keyword), IF_SYMBOL, "IF");
180 add_keyword (&A68 (top_keyword), OD_SYMBOL, "OD");
181 add_keyword (&A68 (top_keyword), OF_SYMBOL, "OF");
182 add_keyword (&A68 (top_keyword), STRUCT_SYMBOL, "STRUCT");
183 add_keyword (&A68 (top_keyword), STYLE_I_PRAGMAT_SYMBOL, "PR");
184 add_keyword (&A68 (top_keyword), BUS_SYMBOL, "]");
185 add_keyword (&A68 (top_keyword), SKIP_SYMBOL, "SKIP");
186 add_keyword (&A68 (top_keyword), SHORT_SYMBOL, "SHORT");
187 add_keyword (&A68 (top_keyword), IS_SYMBOL, "IS");
188 add_keyword (&A68 (top_keyword), ESAC_SYMBOL, "ESAC");
189 add_keyword (&A68 (top_keyword), CHANNEL_SYMBOL, "CHANNEL");
190 add_keyword (&A68 (top_keyword), REAL_SYMBOL, "REAL");
191 add_keyword (&A68 (top_keyword), STRING_SYMBOL, "STRING");
192 add_keyword (&A68 (top_keyword), BOOL_SYMBOL, "BOOL");
193 add_keyword (&A68 (top_keyword), ISNT_SYMBOL, "ISNT");
194 add_keyword (&A68 (top_keyword), FALSE_SYMBOL, "FALSE");
195 add_keyword (&A68 (top_keyword), UNION_SYMBOL, "UNION");
196 add_keyword (&A68 (top_keyword), OUT_SYMBOL, "OUT");
197 add_keyword (&A68 (top_keyword), OPEN_SYMBOL, "(");
198 add_keyword (&A68 (top_keyword), BEGIN_SYMBOL, "BEGIN");
199 add_keyword (&A68 (top_keyword), FLEX_SYMBOL, "FLEX");
200 add_keyword (&A68 (top_keyword), VOID_SYMBOL, "VOID");
201 add_keyword (&A68 (top_keyword), BITS_SYMBOL, "BITS");
202 add_keyword (&A68 (top_keyword), ELSE_SYMBOL, "ELSE");
203 add_keyword (&A68 (top_keyword), EXIT_SYMBOL, "EXIT");
204 add_keyword (&A68 (top_keyword), HEAP_SYMBOL, "HEAP");
205 add_keyword (&A68 (top_keyword), INT_SYMBOL, "INT");
206 add_keyword (&A68 (top_keyword), BYTES_SYMBOL, "BYTES");
207 add_keyword (&A68 (top_keyword), PIPE_SYMBOL, "PIPE");
208 add_keyword (&A68 (top_keyword), FORMAT_SYMBOL, "FORMAT");
209 add_keyword (&A68 (top_keyword), SEMA_SYMBOL, "SEMA");
210 add_keyword (&A68 (top_keyword), CLOSE_SYMBOL, ")");
211 add_keyword (&A68 (top_keyword), AT_SYMBOL, "@");
212 add_keyword (&A68 (top_keyword), ELIF_SYMBOL, "ELIF");
213 add_keyword (&A68 (top_keyword), FORMAT_DELIMITER_SYMBOL, "$");
214 }
© 2002-2024 J.M. van der Veer (jmvdveer@xs4all.nl)
|