Debian Codegraph @

FaCT++/scanner.cpp

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 //-------------------------------------------------------------------------
21 //
22 // Scanner implementation for FaCT++ program
23 //
24 //-------------------------------------------------------------------------
25 #include <cctype> // isalnum
26
27 #include "fpp_assert.h"cxx . . $ `<file>/Kernel/fpp_assert.h`/
28
29 #include "scanner.h"cxx . . $ `<file>/FaCT++/scanner.h`/
30
31 // main methods
32 bool TsScannercxx . . $ TsScanner# :: isLegalIdCharcxx . . $ TsScanner#isLegalIdChar(aec1b1cad4a17585). ( char c ) const //id=[_a..z0-9[].]
33 {
34 switch (c)
35 {
36 case '(':
37 case ')':
38 case ';':
39 case '|':
40 return false;
41 default:
42 return !isspace(c) && !eofcxx . . $ CommonScanner#eof(b5fd09639b7a0261).(c);
43 }
44 }
45
46 // Word must be in a CAPITAL LETTERS
47 void TsScannercxx . . $ TsScanner# :: FillBuffercxx . . $ TsScanner#FillBuffer(44b6ea1973a07080). ( char c )
48 {
49 unsigned int i = 0;
50 LexBuffcxx . . $ CommonScanner#LexBuff. [0] = c;
51
52 while ( i < MaxIDLengthcxx . . $ MaxIDLength. && isLegalIdCharcxx . . $ TsScanner#isLegalIdChar(aec1b1cad4a17585). ( c = NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9).() ) )
53 LexBuffcxx . . $ CommonScanner#LexBuff.[++i] = c;
54
55 LexBuffcxx . . $ CommonScanner#LexBuff.[++i] = 0;
56
57 if ( i > MaxIDLengthcxx . . $ MaxIDLength. )
58 {
59 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( i == MaxIDLength + 1 );
60 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Identifier was restricted to " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). LexBuffcxx . . $ CommonScanner#LexBuff. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n";
61 do {
62 c = NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9).();
63 } while ( isLegalIdCharcxx . . $ TsScanner#isLegalIdChar(aec1b1cad4a17585).(c) );
64 }
65 // OK or read the end of ID
66
67 PutBackcxx . . $ CommonScanner#PutBack(abf0a7d9b482957c). ( c );
68 }
69
70 void TsScannercxx . . $ TsScanner# :: FillNameBuffercxx . . $ TsScanner#FillNameBuffer(44b6ea1973a07080). ( char c )
71 {
72 unsigned int i = 0;
73 const char stop = c;
74
75 while ( i <= MaxIDLengthcxx . . $ MaxIDLength. && ( c = NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9).() ) != stop )
76 LexBuffcxx . . $ CommonScanner#LexBuff.[i++] = c;
77
78 LexBuffcxx . . $ CommonScanner#LexBuff.[i] = 0;
79
80 if ( i > MaxIDLengthcxx . . $ MaxIDLength. )
81 {
82 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( i == MaxIDLength + 1 );
83 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Identifier was restricted to " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). LexBuffcxx . . $ CommonScanner#LexBuff. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
84 do {
85 c = NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9).();
86 } while ( c != stop );
87 }
88 }
89
90 LispTokencxx . . $ LispToken# TsScannercxx . . $ TsScanner# :: GetLexcxx . . $ TsScanner#GetLex(5dd2f7e041733f46). ( void )
91 {
92 char c;
93
94 while ( !eofcxx . . $ CommonScanner#eof(b5fd09639b7a0261).( c = NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9).() ) )
95 {
96 if ( c == ' ' || c == '\t' || c == 13 )
97 continue;
98
99 if ( c == '\n' )
100 {
101 CurLinecxx . . $ CommonScanner#CurLine.++;
102 continue;
103 }
104
105 if ( c == ';' )
106 { // Skip comments
107 do {
108 c = NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9).();
109 } while ( c != '\n' && !eofcxx . . $ CommonScanner#eof(b5fd09639b7a0261).(c) );
110 CurLinecxx . . $ CommonScanner#CurLine.++;
111 continue;
112 }
113
114 // one-symbol tokens
115 if ( c == '(' )
116 return LBRACKcxx . . $ LBRACK.;
117
118 if ( c == ')' )
119 return RBRACKcxx . . $ RBRACK.;
120
121 if ( c == ':' ) // some keyword
122 { // skip colon
123 FillBuffercxx . . $ TsScanner#FillBuffer(44b6ea1973a07080). ( NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9). () );
124 return IDcxx . . $ ID.;
125 }
126
127 if ( c == '|' || c == '"' )
128 {
129 FillNameBuffercxx . . $ TsScanner#FillNameBuffer(44b6ea1973a07080). ( c );
130 return IDcxx . . $ ID.;
131 }
132
133 if ( isdigit ( c ) ) // number
134 {
135 FillBuffercxx . . $ TsScanner#FillBuffer(44b6ea1973a07080). ( c );
136 return NUMcxx . . $ NUM.;
137 }
138 else // id
139 {
140 FillBuffercxx . . $ TsScanner#FillBuffer(44b6ea1973a07080). ( c );
141 return IDcxx . . $ ID.;
142 }
143 }
144 // read EOF - end of lex
145
146 return LEXEOFcxx . . $ LEXEOF.;
147 }
148
149 // recognize TOP, BOTTOM or general ID
150 LispTokencxx . . $ LispToken# TsScannercxx . . $ TsScanner# :: getNameKeywordcxx . . $ TsScanner#getNameKeyword(922db4e91ebad8cc). ( void ) const
151 {
152 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("*TOP*") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("TOP") )
153 return L_TOPcxx . . $ L_TOP.;
154
155 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("*BOTTOM*") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("BOTTOM") )
156 return L_BOTTOMcxx . . $ L_BOTTOM.;
157
158 // not a keyword just an ID
159 return IDcxx . . $ ID.;
160 }
161
162 // concept/role constructors; return BAD_LEX in case of error
163 LispTokencxx . . $ LispToken# TsScannercxx . . $ TsScanner# :: getExpressionKeywordcxx . . $ TsScanner#getExpressionKeyword(922db4e91ebad8cc). ( void ) const
164 {
165 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("and") )
166 return L_ANDcxx . . $ L_AND.;
167
168 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("or") )
169 return L_ORcxx . . $ L_OR.;
170
171 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("not") )
172 return L_NOTcxx . . $ L_NOT.;
173
174 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("inv") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("inverse") )
175 return L_INVcxx . . $ L_INV.;
176
177 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("compose") )
178 return L_RCOMPOSITIONcxx . . $ L_RCOMPOSITION.;
179
180 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("project_into") )
181 return L_PROJINTOcxx . . $ L_PROJINTO.;
182
183 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("project_from") )
184 return L_PROJFROMcxx . . $ L_PROJFROM.;
185
186 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("some") )
187 return L_EXISTScxx . . $ L_EXISTS.;
188
189 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("all") )
190 return L_FORALLcxx . . $ L_FORALL.;
191
192 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("min") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("at-least") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("atleast") )
193 return L_GEcxx . . $ L_GE.;
194
195 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("max") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("at-most") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("atmost") )
196 return L_LEcxx . . $ L_LE.;
197
198 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("one-of") )
199 return ONEOFcxx . . $ ONEOF.;
200
201 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("self-ref") )
202 return REFLEXIVEcxx . . $ REFLEXIVE.;
203
204 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("string") )
205 return STRINGcxx . . $ STRING.;
206
207 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("number") )
208 return NUMBERcxx . . $ NUMBER.;
209
210 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("real") )
211 return REALcxx . . $ REAL.;
212
213 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("bool") )
214 return BOOLcxx . . $ BOOL.;
215
216 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("gt") )
217 return DTGTcxx . . $ DTGT.;
218
219 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("lt") )
220 return DTLTcxx . . $ DTLT.;
221
222 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("ge") )
223 return DTGEcxx . . $ DTGE.;
224
225 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("le") )
226 return DTLEcxx . . $ DTLE.;
227
228 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("d-one-of") )
229 return DONEOFcxx . . $ DONEOF.;
230
231 // not a keyword -- error
232 return BAD_LEXcxx . . $ BAD_LEX.;
233 }
234
235 // recognize FaCT++ keywords; return BAD_LEX if not found
236 LispTokencxx . . $ LispToken# TsScannercxx . . $ TsScanner# :: getCommandKeywordcxx . . $ TsScanner#getCommandKeyword(922db4e91ebad8cc). ( void ) const
237 {
238 // definitions
239 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("defprimconcept") )
240 return PCONCEPTcxx . . $ PCONCEPT.;
241
242 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("defconcept") )
243 return CONCEPTcxx . . $ CONCEPT.;
244
245 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("defprimrole") )
246 return PROLEcxx . . $ PROLE.;
247
248 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("defdatarole") )
249 return DATAROLEcxx . . $ DATAROLE.;
250
251 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("defprimattribute") )
252 return PATTRcxx . . $ PATTR.;
253
254 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("defindividual") )
255 return DEFINDIVIDUALcxx . . $ DEFINDIVIDUAL.;
256
257 // general relations
258 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("implies") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("implies_c") )
259 return SUBSUMEScxx . . $ SUBSUMES.;
260
261 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("equal_c") )
262 return EQUAL_Ccxx . . $ EQUAL_C.;
263
264 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("disjoint") || isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("disjoint_c") )
265 return DISJOINTcxx . . $ DISJOINT.;
266
267 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("implies_r") )
268 return IMPLIES_Rcxx . . $ IMPLIES_R.;
269
270 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("equal_r") )
271 return EQUAL_Rcxx . . $ EQUAL_R.;
272
273 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("disjoint_r") )
274 return DISJOINT_Rcxx . . $ DISJOINT_R.;
275
276 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("inverse") )
277 return INVERSEcxx . . $ INVERSE.;
278
279 // role stuff
280 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("functional") )
281 return FUNCTIONALcxx . . $ FUNCTIONAL.;
282
283 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("transitive") )
284 return TRANSITIVEcxx . . $ TRANSITIVE.;
285
286 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("reflexive") )
287 return REFLEXIVEcxx . . $ REFLEXIVE.;
288
289 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("irreflexive") )
290 return IRREFLEXIVEcxx . . $ IRREFLEXIVE.;
291
292 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("symmetric") )
293 return SYMMETRICcxx . . $ SYMMETRIC.;
294
295 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("asymmetric") )
296 return ASYMMETRICcxx . . $ ASYMMETRIC.;
297
298 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("range") )
299 return ROLERANGEcxx . . $ ROLERANGE.;
300
301 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("domain") )
302 return ROLEDOMAINcxx . . $ ROLEDOMAIN.;
303
304 // individual stuff
305 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("instance") )
306 return INSTANCEcxx . . $ INSTANCE.;
307
308 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("related") )
309 return RELATEDcxx . . $ RELATED.;
310
311 if (isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636).("valueOf"))
312 return VALUEOFcxx . . $ VALUEOF.;
313
314 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("same") )
315 return SAMEcxx . . $ SAME.;
316
317 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("different") )
318 return DIFFERENTcxx . . $ DIFFERENT.;
319
320 if ( isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ("fairness") )
321 return FAIRNESScxx . . $ FAIRNESS.;
322
323 // not a keyword -- error
324 return BAD_LEXcxx . . $ BAD_LEX.;
325 }