Debian Codegraph @

FaCT++.Python/lib/Kernel/tLexeme.h

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 library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef TLEXEME_H
21 #define TLEXEME_H
22
23 #include "grammar.h"
24 #include "tNamedEntry.h"
25
26 /// Lexeme (smallest lexical element) in a syntax tree
27 class TLexeme
28 {
29 private: // members
30 /// Lexeme's Token
31 Token token;
32 /// pointer to information (for names)
33 union
34 {
35 TNamedEntry* pNE;
36 unsigned int data;
37 } value;
38
39 public: // interface
40 /// default c'tor for pointers
41 explicit TLexeme ( Token tok, TNamedEntry* p = nullptr ) : token(tok) { value.pNE = p; }
42 /// default c'tor for numbers
43 TLexeme ( Token tok, unsigned int val ) : token(tok) { value.data = val; }
44 /// Copy c'tor
45 TLexeme ( const TLexeme& ) = default;
46 /// Assignment
47 TLexeme& operator = ( const TLexeme& ) = default;
48
49 // access
50
51 /// get Token of given Lexeme
52 Token getToken ( void ) const { return token; }
53 /// get name pointer of given lexeme
54 TNamedEntry* getNE ( void ) const { return value.pNE; }
55 /// get name pointer of given lexeme
56 const char* getName ( void ) const { return value.pNE->getName(); }
57 /// get data value of given lexeme
58 unsigned int getData ( void ) const { return value.data; }
59
60 // comparison
61
62 /// full lexeme comparison (equality)
63 bool operator == ( const TLexeme& lex ) const { return ( token == lex.token && value.data == lex.value.data ); }
64 /// full lexeme comparison (inequality)
65 bool operator != ( const TLexeme& lex ) const { return !( *this == lex ); }
66 /// just token comparison (equality)
67 bool operator == ( Token tok ) const { return ( token == tok ); }
68 /// just token comparison (inequality)
69 bool operator != ( Token tok ) const { return ( token != tok ); }
70 }; // TLexeme
71
72 #endif