| 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 class for FaCT++ |
| 23 | // |
| 24 | //------------------------------------------------------------------------- |
| 25 | #ifndef COMSCANNER_H |
| 26 | #define COMSCANNER_Hcxx . . $ `FaCT++/comscanner.h:26:9`! |
| 27 | |
| 28 | #include <cstdlib> |
| 29 | #include <cstring> |
| 30 | #include <iostream> |
| 31 | |
| 32 | /// max ID length for scanned objects |
| 33 | const unsigned int MaxIDLengthcxx . . $ MaxIDLength. = 10240; |
| 34 | |
| 35 | /// more-or-less general simple scanner implementation |
| 36 | class CommonScannercxx . . $ CommonScanner# |
| 37 | { |
| 38 | protected: // members |
| 39 | /// input stream |
| 40 | stdcxx . . $ std/::istreamcxx . . $ std/istream#* InFilecxx . . $ CommonScanner#InFile.; |
| 41 | /// buffer for names |
| 42 | char LexBuffcxx . . $ CommonScanner#LexBuff. [ MaxIDLengthcxx . . $ MaxIDLength. + 1 ]; |
| 43 | /// currently processed line of input (used in error diagnosis) |
| 44 | unsigned int CurLinecxx . . $ CommonScanner#CurLine.; |
| 45 | |
| 46 | protected: // methods |
| 47 | /// get next symbol from the stream |
| 48 | char NextCharcxx . . $ CommonScanner#NextChar(1b8b762cbef9c2c9). ( void ) const { return (char)InFilecxx . . $ CommonScanner#InFile.->getcxx . . $ std/basic_istream#get(3a3be259693afdc2).(); } |
| 49 | /// return given symbol back to stream |
| 50 | void PutBackcxx . . $ CommonScanner#PutBack(abf0a7d9b482957c). ( char c ) const { InFilecxx . . $ CommonScanner#InFile.->putbackcxx . . $ std/basic_istream#putback(52c6630ac51d3970).(c); } |
| 51 | /// check whether C is a EOF char |
| 52 | static bool eofcxx . . $ CommonScanner#eof(b5fd09639b7a0261). ( char c ) { return c == stdcxx . . $ std/::char_traitscxx . . $ std/char_traits#<char>::eofcxx . . $ std/char_traits#eof(b126dc7c1de90089).(); } |
| 53 | |
| 54 | public: // interface |
| 55 | /// c'tor |
| 56 | explicit CommonScannercxx . . $ CommonScanner#CommonScanner(6a35a7fc14119650). ( stdcxx . . $ std/::istreamcxx . . $ std/istream#* inp ) |
| 57 | : InFilecxx . . $ CommonScanner#InFile.(inp) |
| 58 | , CurLinecxx . . $ CommonScanner#CurLine.(1) |
| 59 | {} |
| 60 | /// d'tor |
| 61 | virtual ~cxx . . $ CommonScanner#`~CommonScanner`(49f6e7a06ebc5aa8).CommonScannercxx . . $ CommonScanner#() = default; |
| 62 | |
| 63 | /// get string collected in buffer |
| 64 | const char* GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf). ( void ) const { return LexBuffcxx . . $ CommonScanner#LexBuff.; } |
| 65 | /// get number by string from buffer |
| 66 | unsigned long GetNumbercxx . . $ CommonScanner#GetNumber(fe4d2d262d4164a8). ( void ) const { return (unsigned long) atol(LexBuffcxx . . $ CommonScanner#LexBuff.); } |
| 67 | /// get current input line |
| 68 | unsigned int Linecxx . . $ CommonScanner#Line(ddd8539a2fcdd4ce). ( void ) const { return CurLinecxx . . $ CommonScanner#CurLine.; } |
| 69 | /// check if Buffer contains given Word (in any register) |
| 70 | bool isKeywordcxx . . $ CommonScanner#isKeyword(7d4bdb1abc417636). ( const char* Word ) const |
| 71 | { return strlen(Word) == strlen(LexBuffcxx . . $ CommonScanner#LexBuff.) ? !strcmp ( Word, LexBuffcxx . . $ CommonScanner#LexBuff. ) : false; } |
| 72 | |
| 73 | /// reset scanner on the same file |
| 74 | void ReSetcxx . . $ CommonScanner#ReSet(49f6e7a06ebc5aa8). ( void ) |
| 75 | { |
| 76 | InFilecxx . . $ CommonScanner#InFile.->clearcxx . . $ std/basic_ios#clear(3e5fb2eb616d497d).(); |
| 77 | InFilecxx . . $ CommonScanner#InFile.->seekgcxx . . $ std/basic_istream#seekg(f79fad2892c4fe4). ( 0L, stdcxx . . $ std/::ioscxx . . $ std/ios#::begcxx . . $ std/ios_base#beg. ); |
| 78 | CurLinecxx . . $ CommonScanner#CurLine. = 1; |
| 79 | } |
| 80 | /// reset scanner to a given file |
| 81 | void reIncxx . . $ CommonScanner#reIn(6a35a7fc14119650). ( stdcxx . . $ std/::istreamcxx . . $ std/istream#* in ) { InFilecxx . . $ CommonScanner#InFile. = in; CurLinecxx . . $ CommonScanner#CurLine. = 1; } |
| 82 | |
| 83 | /// output an error message |
| 84 | void errorcxx . . $ CommonScanner#error(acfedb98bf840c77). ( const char* msg = nullptr ) const |
| 85 | { |
| 86 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nError at input line " <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). Linecxx . . $ CommonScanner#Line(ddd8539a2fcdd4ce).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " |
| 87 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (msg?msg:"illegal syntax") <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 88 | exit (1); |
| 89 | } |
| 90 | }; // CommonScanner |
| 91 | |
| 92 | #endif |