| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef PARSER_H |
| 21 |
#define PARSER_H |
| 22 |
|
| 23 |
#include "scanner.h" |
| 24 |
#define GenericToken LispToken |
| 25 |
#include "comparser.h" |
| 26 |
#include "Kernel.h" |
| 27 |
|
| 28 |
|
| 29 |
class DLLispParser: public CommonParser<TsScanner> |
| 30 |
{ |
| 31 |
protected: |
| 32 |
|
| 33 |
typedef ReasoningKernel::TExpr TExpr; |
| 34 |
|
| 35 |
typedef ReasoningKernel::TConceptExpr TConceptExpr; |
| 36 |
|
| 37 |
typedef ReasoningKernel::TIndividualExpr TIndividualExpr; |
| 38 |
|
| 39 |
typedef ReasoningKernel::TRoleExpr TRoleExpr; |
| 40 |
|
| 41 |
typedef ReasoningKernel::TORoleComplexExpr TORoleComplexExpr; |
| 42 |
|
| 43 |
typedef ReasoningKernel::TORoleExpr TORoleExpr; |
| 44 |
|
| 45 |
typedef ReasoningKernel::TDRoleExpr TDRoleExpr; |
| 46 |
|
| 47 |
typedef ReasoningKernel::TDataExpr TDataExpr; |
| 48 |
|
| 49 |
typedef ReasoningKernel::TDataTypeExpr TDataTypeExpr; |
| 50 |
|
| 51 |
typedef ReasoningKernel::TDataValueExpr TDataValueExpr; |
| 52 |
|
| 53 |
protected: |
| 54 |
|
| 55 |
ReasoningKernel* Kernel; |
| 56 |
|
| 57 |
TExpressionManager* EManager; |
| 58 |
|
| 59 |
std::set<std::string> DataRoles; |
| 60 |
|
| 61 |
protected: |
| 62 |
|
| 63 |
void errorByException ( const EFPPCantRegName& ex ) const { parseError(ex.what()); } |
| 64 |
|
| 65 |
|
| 66 |
TConceptExpr* getConcept ( void ) |
| 67 |
{ |
| 68 |
TConceptExpr* ret = EManager->Concept(scan.GetName()); |
| 69 |
NextLex(); |
| 70 |
return ret; |
| 71 |
} |
| 72 |
|
| 73 |
TIndividualExpr* getSingleton ( void ) |
| 74 |
{ |
| 75 |
TIndividualExpr* ret = EManager->Individual(scan.GetName()); |
| 76 |
NextLex(); |
| 77 |
return ret; |
| 78 |
} |
| 79 |
|
| 80 |
TRoleExpr* getRole ( void ) |
| 81 |
{ |
| 82 |
TRoleExpr* ret; |
| 83 |
if ( DataRoles.find(scan.GetName()) != DataRoles.end() ) |
| 84 |
ret = EManager->DataRole(scan.GetName()); |
| 85 |
else |
| 86 |
ret = EManager->ObjectRole(scan.GetName()); |
| 87 |
NextLex(); |
| 88 |
return ret; |
| 89 |
} |
| 90 |
|
| 91 |
TDRoleExpr* getDataRole ( void ) |
| 92 |
{ |
| 93 |
DataRoles.insert(scan.GetName()); |
| 94 |
TDRoleExpr* ret = EManager->DataRole(scan.GetName()); |
| 95 |
NextLex(); |
| 96 |
return ret; |
| 97 |
} |
| 98 |
|
| 99 |
TORoleExpr* getObjectRole ( void ) |
| 100 |
{ |
| 101 |
TORoleExpr* ret = EManager->ObjectRole(scan.GetName()); |
| 102 |
NextLex(); |
| 103 |
return ret; |
| 104 |
} |
| 105 |
|
| 106 |
TDataValueExpr* getDTValue ( TDataTypeExpr* type ) |
| 107 |
{ |
| 108 |
TDataValueExpr* ret = EManager->DataValue ( scan.GetName(), type ); |
| 109 |
NextLex(); |
| 110 |
return ret; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
bool isDataRole ( const TRoleExpr* R ) const { return dynamic_cast<const TDRoleExpr*>(R) != nullptr; } |
| 115 |
|
| 116 |
void tellRoleAxiom ( LispToken tag, TORoleExpr* R, TORoleExpr* S ); |
| 117 |
|
| 118 |
void tellRoleAxiom ( LispToken tag, TDRoleExpr* R, TDRoleExpr* S ); |
| 119 |
|
| 120 |
TRoleExpr* getRoleExpression ( void ); |
| 121 |
|
| 122 |
TORoleExpr* getORoleExpression ( void ); |
| 123 |
|
| 124 |
TDRoleExpr* getDRoleExpression ( void ); |
| 125 |
|
| 126 |
TRoleExpr* getComplexRoleExpression ( void ); |
| 127 |
|
| 128 |
void parseCommand ( void ); |
| 129 |
|
| 130 |
void parseRoleArguments ( TORoleExpr* role ); |
| 131 |
|
| 132 |
void parseConceptList ( bool singletonsOnly ); |
| 133 |
|
| 134 |
TConceptExpr* getConceptExpression ( void ); |
| 135 |
|
| 136 |
TConceptExpr* getComplexConceptExpression ( void ); |
| 137 |
|
| 138 |
TDataExpr* getDataExpression ( void ); |
| 139 |
|
| 140 |
public: |
| 141 |
|
| 142 |
DLLispParser ( std::istream* in, ReasoningKernel* kernel ) |
| 143 |
: CommonParser<TsScanner>(in) |
| 144 |
, Kernel (kernel) |
| 145 |
, EManager(kernel->getExpressionManager()) |
| 146 |
{ |
| 147 |
|
| 148 |
DataRoles.insert("*UDROLE*"); |
| 149 |
DataRoles.insert("*EDROLE*"); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
void Parse ( void ); |
| 154 |
}; |
| 155 |
|
| 156 |
#endif |