develop #15
@ -63,7 +63,7 @@ BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakInheritanceList: AfterColon
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 120
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: "^ IWYU pragma:"
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
@ -167,7 +167,7 @@ RawStringFormats:
|
||||
- PROTO
|
||||
CanonicalDelimiter: pb
|
||||
ReferenceAlignment: Left
|
||||
ReflowComments: false
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
SeparateDefinitionBlocks: Always
|
||||
ShortNamespaceLines: 0
|
||||
|
@ -31,7 +31,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Get the callee.
|
||||
*
|
||||
* @return std::string Returns the name of the function being called.
|
||||
* @return std::string Returns the name of the function being
|
||||
* called.
|
||||
*/
|
||||
std::string getCallee();
|
||||
|
||||
@ -45,7 +46,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Get the arguments being used by the function.
|
||||
*
|
||||
* @return std::vector<std::unique_ptr<ExpressionAST>> Returns an AST expression containing the args.
|
||||
* @return std::vector<std::unique_ptr<ExpressionAST>> Returns an
|
||||
* AST expression containing the args.
|
||||
*/
|
||||
std::vector<std::unique_ptr<ExpressionAST>> getArgs();
|
||||
|
||||
@ -63,7 +65,8 @@ namespace obelisk
|
||||
* @param[in] callee The function to call.
|
||||
* @param[in] args The args to pass into the function.
|
||||
*/
|
||||
CallExpressionAST(const std::string &callee, std::vector<std::unique_ptr<ExpressionAST>> args) :
|
||||
CallExpressionAST(const std::string &callee,
|
||||
std::vector<std::unique_ptr<ExpressionAST>> args) :
|
||||
callee_(callee),
|
||||
args_(std::move(args))
|
||||
{
|
||||
|
@ -11,7 +11,8 @@ namespace obelisk
|
||||
* @brief Log an AST expression error.
|
||||
*
|
||||
* @param[in] str The error message.
|
||||
* @return std::unique_ptr<ExpressionAST> Returns the AST expression that caused the error.
|
||||
* @return std::unique_ptr<ExpressionAST> Returns the AST expression that
|
||||
* caused the error.
|
||||
*/
|
||||
std::unique_ptr<ExpressionAST> LogError(const char *str);
|
||||
|
||||
|
@ -21,7 +21,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Generate LLVM IR code based on the AST expression.
|
||||
*
|
||||
* @return llvm::Value* Returns the LLVM code value from the expression.
|
||||
* @return llvm::Value* Returns the LLVM code value from the
|
||||
* expression.
|
||||
*/
|
||||
virtual llvm::Value *codegen() = 0;
|
||||
};
|
||||
|
@ -17,7 +17,8 @@ llvm::Function *obelisk::FunctionAST::codegen()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
llvm::BasicBlock *bB = llvm::BasicBlock::Create(*TheContext, "entry", theFunction);
|
||||
llvm::BasicBlock *bB
|
||||
= llvm::BasicBlock::Create(*TheContext, "entry", theFunction);
|
||||
Builder->SetInsertPoint(bB);
|
||||
|
||||
NamedValues.clear();
|
||||
|
@ -48,7 +48,8 @@ namespace obelisk
|
||||
* @param[in] prototype The prototype of the function.
|
||||
* @param[in] body The body of the function.
|
||||
*/
|
||||
FunctionAST(std::unique_ptr<PrototypeAST> prototype, std::unique_ptr<ExpressionAST> body) :
|
||||
FunctionAST(std::unique_ptr<PrototypeAST> prototype,
|
||||
std::unique_ptr<ExpressionAST> body) :
|
||||
prototype_(std::move(prototype)),
|
||||
body_(std::move(body))
|
||||
{
|
||||
|
@ -3,10 +3,17 @@
|
||||
|
||||
llvm::Function *obelisk::PrototypeAST::codegen()
|
||||
{
|
||||
std::vector<llvm::Type *> doubles(args_.size(), llvm::Type::getDoubleTy(*TheContext));
|
||||
llvm::FunctionType *FT = llvm::FunctionType::get(llvm::Type::getDoubleTy(*TheContext), doubles, false);
|
||||
std::vector<llvm::Type *> doubles(args_.size(),
|
||||
llvm::Type::getDoubleTy(*TheContext));
|
||||
llvm::FunctionType *FT
|
||||
= llvm::FunctionType::get(llvm::Type::getDoubleTy(*TheContext),
|
||||
doubles,
|
||||
false);
|
||||
|
||||
llvm::Function *F = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, name_, obelisk::TheModule.get());
|
||||
llvm::Function *F = llvm::Function::Create(FT,
|
||||
llvm::Function::ExternalLinkage,
|
||||
name_,
|
||||
obelisk::TheModule.get());
|
||||
|
||||
unsigned idx = 0;
|
||||
for (auto &arg : F->args())
|
||||
|
@ -54,7 +54,8 @@ namespace obelisk
|
||||
* @param[in] name The name of the prototype.
|
||||
* @param[in] args The arguments the prototype accepts.
|
||||
*/
|
||||
PrototypeAST(const std::string& name, std::vector<std::string> args) :
|
||||
PrototypeAST(const std::string& name,
|
||||
std::vector<std::string> args) :
|
||||
name_(name),
|
||||
args_(std::move(args))
|
||||
{
|
||||
|
@ -7,7 +7,8 @@ obelisk::Lexer::Lexer(const std::string& sourceFile)
|
||||
fileStream_.open(sourceFile, std::ifstream::in);
|
||||
if (!fileStream_)
|
||||
{
|
||||
throw obelisk::LexerException("could not open source file " + sourceFile);
|
||||
throw obelisk::LexerException(
|
||||
"could not open source file " + sourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
21
src/lexer.h
21
src/lexer.h
@ -56,19 +56,22 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Comment the rest of the line.
|
||||
*
|
||||
* @param[in] lastChar The char to check to see if it in the end of the line.
|
||||
* @param[in] lastChar The char to check to see if it in the end of
|
||||
* the line.
|
||||
*/
|
||||
void commentLine(int* lastChar);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief These token represent recognized language keywords and language functionality.
|
||||
* @brief These token represent recognized language keywords and
|
||||
* language functionality.
|
||||
*
|
||||
*/
|
||||
enum Token
|
||||
{
|
||||
/**
|
||||
* @brief End of file is returned when the source code is finished.
|
||||
* @brief End of file is returned when the source code is
|
||||
* finished.
|
||||
*
|
||||
*/
|
||||
kTokenEof = -1,
|
||||
@ -79,7 +82,8 @@ namespace obelisk
|
||||
*/
|
||||
kTokenFact = -2,
|
||||
/**
|
||||
* @brief A rule which is a relationship between a new fact a existing fact.
|
||||
* @brief A rule which is a relationship between a new fact a
|
||||
* existing fact.
|
||||
*
|
||||
*/
|
||||
kTokenRule = -3,
|
||||
@ -133,14 +137,16 @@ namespace obelisk
|
||||
* @brief Gets the next token in the source code.
|
||||
*
|
||||
* @throws LexerException when an invalid token is found.
|
||||
* @return int Returns a Token value or char if no known token was found.
|
||||
* @return int Returns a Token value or char if no known token was
|
||||
* found.
|
||||
*/
|
||||
int getToken();
|
||||
|
||||
/**
|
||||
* @brief Get the last identifier.
|
||||
*
|
||||
* @return const std::string& Returns a string that contains the last found identifier.
|
||||
* @return const std::string& Returns a string that contains the
|
||||
* last found identifier.
|
||||
*/
|
||||
const std::string& getIdentifier();
|
||||
|
||||
@ -188,7 +194,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Return the exception's error message.
|
||||
*
|
||||
* @return const char* Returns a string containing the error message.
|
||||
* @return const char* Returns a string containing the error
|
||||
* message.
|
||||
*/
|
||||
const char* what() const noexcept
|
||||
{
|
||||
|
@ -1,13 +1,15 @@
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief The obelisk namespace contains everything needed to compile obelisk code.
|
||||
* @brief The obelisk namespace contains everything needed to compile obelisk
|
||||
* code.
|
||||
*
|
||||
*/
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The obelisk library provides everything needed to consult the KnowledgeBase.
|
||||
* @brief The obelisk library provides everything needed to consult the
|
||||
* KnowledgeBase.
|
||||
*
|
||||
*/
|
||||
class Obelisk
|
||||
|
@ -44,7 +44,11 @@ obelisk::KnowledgeBase::~KnowledgeBase()
|
||||
void obelisk::KnowledgeBase::enableForeignKeys()
|
||||
{
|
||||
char* errmsg;
|
||||
int result = sqlite3_exec(dbConnection_, "PRAGMA foreign_keys = ON;", NULL, NULL, &errmsg);
|
||||
int result = sqlite3_exec(dbConnection_,
|
||||
"PRAGMA foreign_keys = ON;",
|
||||
NULL,
|
||||
NULL,
|
||||
&errmsg);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
if (errmsg)
|
||||
@ -86,7 +90,9 @@ void obelisk::KnowledgeBase::addEntities(std::vector<obelisk::Entity>& entities)
|
||||
catch (obelisk::DatabaseConstraintException& exception)
|
||||
{
|
||||
// ignore unique constraint error
|
||||
if (std::strcmp(exception.what(), "UNIQUE constraint failed: entity.name") != 0)
|
||||
if (std::strcmp(exception.what(),
|
||||
"UNIQUE constraint failed: entity.name")
|
||||
!= 0)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@ -105,7 +111,9 @@ void obelisk::KnowledgeBase::addVerbs(std::vector<obelisk::Verb>& verbs)
|
||||
catch (obelisk::DatabaseConstraintException& exception)
|
||||
{
|
||||
// ignore unique constraint error
|
||||
if (std::strcmp(exception.what(), "UNIQUE constraint failed: verb.name") != 0)
|
||||
if (std::strcmp(exception.what(),
|
||||
"UNIQUE constraint failed: verb.name")
|
||||
!= 0)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@ -124,7 +132,9 @@ void obelisk::KnowledgeBase::addActions(std::vector<obelisk::Action>& actions)
|
||||
catch (obelisk::DatabaseConstraintException& exception)
|
||||
{
|
||||
// ignore unique constraint error
|
||||
if (std::strcmp(exception.what(), "UNIQUE constraint failed: action.name") != 0)
|
||||
if (std::strcmp(exception.what(),
|
||||
"UNIQUE constraint failed: action.name")
|
||||
!= 0)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@ -153,7 +163,8 @@ void obelisk::KnowledgeBase::addFacts(std::vector<obelisk::Fact>& facts)
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::KnowledgeBase::addSuggestActions(std::vector<obelisk::SuggestAction>& suggestActions)
|
||||
void obelisk::KnowledgeBase::addSuggestActions(
|
||||
std::vector<obelisk::SuggestAction>& suggestActions)
|
||||
{
|
||||
for (auto& suggestAction : suggestActions)
|
||||
{
|
||||
@ -185,7 +196,9 @@ void obelisk::KnowledgeBase::addRules(std::vector<obelisk::Rule>& rules)
|
||||
catch (obelisk::DatabaseConstraintException& exception)
|
||||
{
|
||||
// ignore unique constraint error
|
||||
if (std::strcmp(exception.what(), "UNIQUE constraint failed: rule.fact, rule.reason") != 0)
|
||||
if (std::strcmp(exception.what(),
|
||||
"UNIQUE constraint failed: rule.fact, rule.reason")
|
||||
!= 0)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@ -213,7 +226,8 @@ void obelisk::KnowledgeBase::getFact(obelisk::Fact& fact)
|
||||
fact.selectById(dbConnection_);
|
||||
}
|
||||
|
||||
void obelisk::KnowledgeBase::getSuggestAction(obelisk::SuggestAction& suggestAction)
|
||||
void obelisk::KnowledgeBase::getSuggestAction(
|
||||
obelisk::SuggestAction& suggestAction)
|
||||
{
|
||||
suggestAction.selectById(dbConnection_);
|
||||
}
|
||||
@ -245,7 +259,9 @@ void obelisk::KnowledgeBase::updateIsTrue(obelisk::Fact& fact)
|
||||
fact.updateIsTrue(dbConnection_);
|
||||
}
|
||||
|
||||
void obelisk::KnowledgeBase::getFloat(float& result1, float& result2, double var)
|
||||
void obelisk::KnowledgeBase::getFloat(float& result1,
|
||||
float& result2,
|
||||
double var)
|
||||
{
|
||||
result1 = (float) var;
|
||||
result2 = (float) (var - (double) result1);
|
||||
|
@ -18,7 +18,8 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The KnowledgeBase class represents a collection of facts, rules, actions, and related language connectors.
|
||||
* @brief The KnowledgeBase class represents a collection of facts, rules,
|
||||
* actions, and related language connectors.
|
||||
*
|
||||
*/
|
||||
class KnowledgeBase
|
||||
@ -45,8 +46,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Enable foreign key functionality in the open database.
|
||||
*
|
||||
* This must always be done when the connection is opened or it will not enforce the foreign key
|
||||
* constraints.
|
||||
* This must always be done when the connection is opened or it will
|
||||
* not enforce the foreign key constraints.
|
||||
*/
|
||||
void enableForeignKeys();
|
||||
|
||||
@ -61,7 +62,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Construct a new KnowledgeBase object.
|
||||
*
|
||||
* @param[in] filename The name of the file to save the knowledge base as.
|
||||
* @param[in] filename The name of the file to save the knowledge
|
||||
* base as.
|
||||
* @param[in] flags The flags to open the KnowledgeBase with.
|
||||
*/
|
||||
KnowledgeBase(const char* filename, int flags);
|
||||
@ -69,10 +71,12 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Construct a new KnowledgeBase object.
|
||||
*
|
||||
* @param[in] filename The name of the file to save the knowledge base as.
|
||||
* @param[in] filename The name of the file to save the knowledge
|
||||
* base as.
|
||||
*/
|
||||
KnowledgeBase(const char* filename) :
|
||||
KnowledgeBase(filename, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
|
||||
KnowledgeBase(filename,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
|
||||
{
|
||||
}
|
||||
|
||||
@ -86,96 +90,104 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Add entities to the KnowledgeBase.
|
||||
*
|
||||
* @param[in,out] entities The entities to add. If the insert is successful it will have a row ID, if not
|
||||
* the ID will be 0.
|
||||
* @param[in,out] entities The entities to add. If the insert is
|
||||
* successful it will have a row ID, if not the ID will be 0.
|
||||
*/
|
||||
void addEntities(std::vector<obelisk::Entity>& entities);
|
||||
|
||||
/**
|
||||
* @brief Add verbs to the KnowledgeBase.
|
||||
*
|
||||
* @param[in,out] verbs The verbs to add. If the insert is successful it will have a row ID, if not the ID
|
||||
* will be 0.
|
||||
* @param[in,out] verbs The verbs to add. If the insert is
|
||||
* successful it will have a row ID, if not the ID will be 0.
|
||||
*/
|
||||
void addVerbs(std::vector<obelisk::Verb>& verbs);
|
||||
|
||||
/**
|
||||
* @brief Add actions to the KnowledgeBase.
|
||||
*
|
||||
* @param[in,out] actions The actions to add. If the insert is successful it will have a row ID, if nto the
|
||||
* ID will be 0.
|
||||
* @param[in,out] actions The actions to add. If the insert is
|
||||
* successful it will have a row ID, if nto the ID will be 0.
|
||||
*/
|
||||
void addActions(std::vector<obelisk::Action>& actions);
|
||||
|
||||
/**
|
||||
* @brief Add facts to the KnowledgeBase.
|
||||
*
|
||||
* @param[in,out] facts The facts to add. If the insert is successful it will have a row ID, if not the ID
|
||||
* will be 0.
|
||||
* @param[in,out] facts The facts to add. If the insert is
|
||||
* successful it will have a row ID, if not the ID will be 0.
|
||||
*/
|
||||
void addFacts(std::vector<obelisk::Fact>& facts);
|
||||
|
||||
/**
|
||||
* @brief Add suggested actions to the KnowledgeBase.
|
||||
*
|
||||
* @param[in,out] suggestActions The suggested actions to add. If the insert is successful it will have a
|
||||
* row ID, if not the ID will be 0.
|
||||
* @param[in,out] suggestActions The suggested actions to add. If
|
||||
* the insert is successful it will have a row ID, if not the ID
|
||||
* will be 0.
|
||||
*/
|
||||
void addSuggestActions(std::vector<obelisk::SuggestAction>& suggestActions);
|
||||
void addSuggestActions(
|
||||
std::vector<obelisk::SuggestAction>& suggestActions);
|
||||
|
||||
/**
|
||||
* @brief Add rules to the KnowledgeBase.
|
||||
*
|
||||
* @param[in,out] rules The rules to add. If the insert is successful it will have a row ID, if not the ID
|
||||
* will be 0.
|
||||
* @param[in,out] rules The rules to add. If the insert is
|
||||
* successful it will have a row ID, if not the ID will be 0.
|
||||
*/
|
||||
void addRules(std::vector<obelisk::Rule>& rules);
|
||||
|
||||
/**
|
||||
* @brief Get an Entity object based on the ID it contains.
|
||||
*
|
||||
* @param[in,out] entity The Entity object should contain just the ID and the rest will be filled in.
|
||||
* @param[in,out] entity The Entity object should contain just the
|
||||
* ID and the rest will be filled in.
|
||||
*/
|
||||
void getEntity(obelisk::Entity& entity);
|
||||
|
||||
/**
|
||||
* @brief Get a Verb object based on the ID it contains.
|
||||
*
|
||||
* @param[in,out] verb The Verb object should contain just the ID and the rest will be filled in.
|
||||
* @param[in,out] verb The Verb object should contain just the ID
|
||||
* and the rest will be filled in.
|
||||
*/
|
||||
void getVerb(obelisk::Verb& verb);
|
||||
|
||||
/**
|
||||
* @brief Get an Action based on the ID it contains.
|
||||
*
|
||||
* @param[in] action The Action object should contain just the ID and the rest will be filled in.
|
||||
* @param[in] action The Action object should contain just the ID
|
||||
* and the rest will be filled in.
|
||||
*/
|
||||
void getAction(obelisk::Action& action);
|
||||
|
||||
/**
|
||||
* @brief Get a Fact object based on the ID it contains.
|
||||
*
|
||||
* @param[in,out] fact The Fact object should contain just the ID and the rest will be filled in.
|
||||
* @param[in,out] fact The Fact object should contain just the ID
|
||||
* and the rest will be filled in.
|
||||
*/
|
||||
void getFact(obelisk::Fact& fact);
|
||||
|
||||
/**
|
||||
* @brief Get a SuggestAction based on the ID it contains.
|
||||
*
|
||||
* @param[in,out] suggestAction The SuggestAction object should contain just the ID and the rest will be
|
||||
* filled in.
|
||||
* @param[in,out] suggestAction The SuggestAction object should
|
||||
* contain just the ID and the rest will be filled in.
|
||||
*/
|
||||
void getSuggestAction(obelisk::SuggestAction& suggestAction);
|
||||
|
||||
/**
|
||||
* @brief Get a Rule based on the ID it contains.
|
||||
*
|
||||
* @param[in,out] rule The Rule object should contain just the ID and the rest will be filled in.
|
||||
* @param[in,out] rule The Rule object should contain just the ID
|
||||
* and the rest will be filled in.
|
||||
*/
|
||||
void getRule(obelisk::Rule& rule);
|
||||
|
||||
/**
|
||||
* @brief Check if a rule looks for this Fact, if so update its truth.
|
||||
* @brief Check if a rule looks for this Fact, if so update its
|
||||
* truth.
|
||||
*
|
||||
* @param[in,out] fact The Fact to check for existing rules.
|
||||
*/
|
||||
@ -191,8 +203,9 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Take a float and divide it into 2 floats.
|
||||
*
|
||||
* This is useful to store doubles in SQLite since SQLite doesn't have a double type. Instead just store the
|
||||
* 2 floats in the database. Then after selecting them combine them.
|
||||
* This is useful to store doubles in SQLite since SQLite doesn't
|
||||
* have a double type. Instead just store the 2 floats in the
|
||||
* database. Then after selecting them combine them.
|
||||
*
|
||||
* @param[out] result1 The first float generated from the double.
|
||||
* @param[out] result2 The second float generated from the double.
|
||||
@ -203,7 +216,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Combines 2 separated floats back into a double.
|
||||
*
|
||||
* This will recombine the separated floats from the getFloat method.
|
||||
* This will recombine the separated floats from the getFloat
|
||||
* method.
|
||||
*
|
||||
* @param[out] result The double generated from the combined floats.
|
||||
* @param[in] var1 The first float to combine.
|
||||
|
@ -21,7 +21,11 @@ void obelisk::Action::selectByName(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "SELECT id, name FROM action WHERE name=?", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"SELECT id, name FROM action WHERE name=?",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
@ -85,13 +89,18 @@ void obelisk::Action::insert(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "INSERT INTO action (name) VALUES (?)", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"INSERT INTO action (name) VALUES (?)",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
}
|
||||
|
||||
result = sqlite3_bind_text(ppStmt, 1, getName().c_str(), -1, SQLITE_TRANSIENT);
|
||||
result
|
||||
= sqlite3_bind_text(ppStmt, 1, getName().c_str(), -1, SQLITE_TRANSIENT);
|
||||
switch (result)
|
||||
{
|
||||
case SQLITE_OK :
|
||||
@ -118,7 +127,8 @@ void obelisk::Action::insert(sqlite3* dbConnection)
|
||||
sqlite3_set_last_insert_rowid(dbConnection, 0);
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
|
@ -8,7 +8,8 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The Action model represents an action to take when a fact is true or false.
|
||||
* @brief The Action model represents an action to take when a fact is true
|
||||
* or false.
|
||||
*
|
||||
*/
|
||||
class Action
|
||||
@ -107,14 +108,16 @@ namespace obelisk
|
||||
void setName(std::string name);
|
||||
|
||||
/**
|
||||
* @brief Select an Action from the datbase based on the object name.
|
||||
* @brief Select an Action from the datbase based on the object
|
||||
* name.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
void selectByName(sqlite3* dbConnection);
|
||||
|
||||
/**
|
||||
* @brief Insert an Action into the KnowledgeBase based on the object's fields.
|
||||
* @brief Insert an Action into the KnowledgeBase based on the
|
||||
* object's fields.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
|
@ -21,7 +21,11 @@ void obelisk::Entity::selectByName(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "SELECT id, name FROM entity WHERE name=?", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"SELECT id, name FROM entity WHERE name=?",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
@ -85,13 +89,18 @@ void obelisk::Entity::insert(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "INSERT INTO entity (name) VALUES (?)", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"INSERT INTO entity (name) VALUES (?)",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
}
|
||||
|
||||
result = sqlite3_bind_text(ppStmt, 1, getName().c_str(), -1, SQLITE_TRANSIENT);
|
||||
result
|
||||
= sqlite3_bind_text(ppStmt, 1, getName().c_str(), -1, SQLITE_TRANSIENT);
|
||||
switch (result)
|
||||
{
|
||||
case SQLITE_OK :
|
||||
@ -118,7 +127,8 @@ void obelisk::Entity::insert(sqlite3* dbConnection)
|
||||
sqlite3_set_last_insert_rowid(dbConnection, 0);
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
|
@ -8,7 +8,8 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The Entity model represents either a left or right side entity, typically used in facts and rules.
|
||||
* @brief The Entity model represents either a left or right side entity,
|
||||
* typically used in facts and rules.
|
||||
*
|
||||
*/
|
||||
class Entity
|
||||
@ -107,14 +108,16 @@ namespace obelisk
|
||||
void setName(std::string name);
|
||||
|
||||
/**
|
||||
* @brief Select an Entity from the KnowledgeBase based on the object's name.
|
||||
* @brief Select an Entity from the KnowledgeBase based on the
|
||||
* object's name.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
void selectByName(sqlite3* dbConnection);
|
||||
|
||||
/**
|
||||
* @brief Insert an Entity into the KnowledgeBase based on the object's fields.
|
||||
* @brief Insert an Entity into the KnowledgeBase based on the
|
||||
* object's fields.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
|
@ -35,14 +35,16 @@ namespace obelisk
|
||||
* @param[in] errorCode The error code that came from sqlite.
|
||||
*/
|
||||
DatabaseException(const int errorCode) :
|
||||
errorMessage_("database error " + std::to_string(errorCode) + " ocurred")
|
||||
errorMessage_(
|
||||
"database error " + std::to_string(errorCode) + " ocurred")
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new DatabaseException object.
|
||||
*
|
||||
* @param[in] errorMessage The error message to describe the exception.
|
||||
* @param[in] errorMessage The error message to describe the
|
||||
* exception.
|
||||
*/
|
||||
DatabaseException(const std::string& errorMessage) :
|
||||
errorMessage_(errorMessage)
|
||||
@ -71,7 +73,8 @@ namespace obelisk
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Exception thrown if the string or blob size exceeds sqlite's limits.
|
||||
* @brief Exception thrown if the string or blob size exceeds sqlite's
|
||||
* limits.
|
||||
*
|
||||
*/
|
||||
class DatabaseSizeException : public obelisk::DatabaseException
|
||||
@ -105,7 +108,8 @@ namespace obelisk
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Exception thrown if there is not enough memory to perform the operation.
|
||||
* @brief Exception thrown if there is not enough memory to perform the
|
||||
* operation.
|
||||
*
|
||||
*/
|
||||
class DatabaseMemoryException : public obelisk::DatabaseException
|
||||
@ -134,7 +138,8 @@ namespace obelisk
|
||||
*/
|
||||
DatabaseBusyException()
|
||||
{
|
||||
setErrorMessage("database was busy and operation was not performed");
|
||||
setErrorMessage(
|
||||
"database was busy and operation was not performed");
|
||||
}
|
||||
};
|
||||
|
||||
@ -175,7 +180,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Construct a new DatabaseConstraintException object.
|
||||
*
|
||||
* @param[in] errorMessage The error message to send when the constraint is violated.
|
||||
* @param[in] errorMessage The error message to send when the
|
||||
* constraint is violated.
|
||||
*/
|
||||
DatabaseConstraintException(const std::string& errorMessage)
|
||||
{
|
||||
|
@ -36,7 +36,8 @@ void obelisk::Fact::selectById(sqlite3* dbConnection)
|
||||
}
|
||||
else
|
||||
{
|
||||
query = "SELECT id, left_entity, right_entity, verb, is_true FROM fact WHERE (id=?)";
|
||||
query
|
||||
= "SELECT id, left_entity, right_entity, verb, is_true FROM fact WHERE (id=?)";
|
||||
}
|
||||
auto result = sqlite3_prepare_v2(dbConnection, query, -1, &ppStmt, nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
@ -259,7 +260,8 @@ void obelisk::Fact::insert(sqlite3* dbConnection)
|
||||
sqlite3_set_last_insert_rowid(dbConnection, 0);
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
@ -287,7 +289,11 @@ void obelisk::Fact::updateIsTrue(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "UPDATE fact SET is_true=? WHERE id=?", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"UPDATE fact SET is_true=? WHERE id=?",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
@ -338,7 +344,8 @@ void obelisk::Fact::updateIsTrue(sqlite3* dbConnection)
|
||||
// Row updated
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
|
@ -10,7 +10,8 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The Fact model represents truth in the releationship between two entities separated by a verb.
|
||||
* @brief The Fact model represents truth in the releationship between two
|
||||
* entities separated by a verb.
|
||||
*
|
||||
*/
|
||||
class Fact
|
||||
@ -35,7 +36,8 @@ namespace obelisk
|
||||
obelisk::Entity rightEntity_;
|
||||
|
||||
/**
|
||||
* @brief The Verb that represents the relationship in the expression.
|
||||
* @brief The Verb that represents the relationship in the
|
||||
* expression.
|
||||
*
|
||||
*/
|
||||
obelisk::Verb verb_;
|
||||
@ -77,12 +79,17 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Construct a new Fact object.
|
||||
*
|
||||
* @param[in] leftEntity The Entity on the left side of the expression.
|
||||
* @param[in] rightEntity The Entity on the right side of the expression.
|
||||
* @param[in] leftEntity The Entity on the left side of the
|
||||
* expression.
|
||||
* @param[in] rightEntity The Entity on the right side of the
|
||||
* expression.
|
||||
* @param[in] verb The Verb separating the entities.
|
||||
* @param[in] isTrue Whether or not the fact is true.
|
||||
*/
|
||||
Fact(obelisk::Entity leftEntity, obelisk::Entity rightEntity, obelisk::Verb verb, bool isTrue = false) :
|
||||
Fact(obelisk::Entity leftEntity,
|
||||
obelisk::Entity rightEntity,
|
||||
obelisk::Verb verb,
|
||||
bool isTrue = false) :
|
||||
id_(0),
|
||||
leftEntity_(leftEntity),
|
||||
rightEntity_(rightEntity),
|
||||
@ -95,8 +102,10 @@ namespace obelisk
|
||||
* @brief Construct a new Fact object.
|
||||
*
|
||||
* @param[in] id The ID of the Fact in the KnowledgeBase.
|
||||
* @param[in] leftEntity The Entity on the left side of the expression.
|
||||
* @param[in] rightEntity The Entity on the right side of the expression.
|
||||
* @param[in] leftEntity The Entity on the left side of the
|
||||
* expression.
|
||||
* @param[in] rightEntity The Entity on the right side of the
|
||||
* expression.
|
||||
* @param[in] verb The Verb separating the entities.
|
||||
* @param[in] isTrue Whether or not the fact is true.
|
||||
*/
|
||||
@ -192,7 +201,8 @@ namespace obelisk
|
||||
void setIsTrue(bool isTrue);
|
||||
|
||||
/**
|
||||
* @brief Select the Fact from the KnowledgeBase by IDs of the sub-objects.
|
||||
* @brief Select the Fact from the KnowledgeBase by IDs of the
|
||||
* sub-objects.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
@ -206,7 +216,8 @@ namespace obelisk
|
||||
void insert(sqlite3* dbConnection);
|
||||
|
||||
/**
|
||||
* @brief Update whether or not the fact is true in the KnowledgeBase.
|
||||
* @brief Update whether or not the fact is true in the
|
||||
* KnowledgeBase.
|
||||
*
|
||||
* @param[in] dbConnection The database connection.
|
||||
*/
|
||||
|
@ -111,8 +111,11 @@ void obelisk::Rule::insert(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result
|
||||
= sqlite3_prepare_v2(dbConnection, "INSERT INTO rule (fact, reason) VALUES (?, ?)", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"INSERT INTO rule (fact, reason) VALUES (?, ?)",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
@ -164,7 +167,8 @@ void obelisk::Rule::insert(sqlite3* dbConnection)
|
||||
sqlite3_set_last_insert_rowid(dbConnection, 0);
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
@ -183,7 +187,9 @@ void obelisk::Rule::insert(sqlite3* dbConnection)
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Rule::selectByReason(sqlite3* dbConnection, int reasonId, std::vector<obelisk::Rule>& rules)
|
||||
void obelisk::Rule::selectByReason(sqlite3* dbConnection,
|
||||
int reasonId,
|
||||
std::vector<obelisk::Rule>& rules)
|
||||
{
|
||||
if (dbConnection == nullptr)
|
||||
{
|
||||
@ -192,8 +198,11 @@ void obelisk::Rule::selectByReason(sqlite3* dbConnection, int reasonId, std::vec
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result
|
||||
= sqlite3_prepare_v2(dbConnection, "SELECT id, fact, reason FROM rule WHERE (reason=?)", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"SELECT id, fact, reason FROM rule WHERE (reason=?)",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
|
@ -134,7 +134,8 @@ namespace obelisk
|
||||
void setReason(obelisk::Fact reason);
|
||||
|
||||
/**
|
||||
* @brief Select the Rule from the KnowledgeBase by IDs of the sub-objects.
|
||||
* @brief Select the Rule from the KnowledgeBase by IDs of the
|
||||
* sub-objects.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
@ -146,7 +147,9 @@ namespace obelisk
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
* @param[out] rules The rules to fill in from the database.
|
||||
*/
|
||||
static void selectByReason(sqlite3* dbConnection, int reasonId, std::vector<obelisk::Rule>& rules);
|
||||
static void selectByReason(sqlite3* dbConnection,
|
||||
int reasonId,
|
||||
std::vector<obelisk::Rule>& rules);
|
||||
|
||||
/**
|
||||
* @brief Insert the Rule into the KnowledgeBase.
|
||||
|
@ -208,7 +208,8 @@ void obelisk::SuggestAction::insert(sqlite3* dbConnection)
|
||||
sqlite3_set_last_insert_rowid(dbConnection, 0);
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
|
@ -9,7 +9,8 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The SuggestAction model representas the actions to take depending on if the Fact is true or false.
|
||||
* @brief The SuggestAction model representas the actions to take depending
|
||||
* on if the Fact is true or false.
|
||||
*
|
||||
*/
|
||||
class SuggestAction
|
||||
@ -72,7 +73,9 @@ namespace obelisk
|
||||
* @param[in] trueAction The true Action.
|
||||
* @param[in] falseAction The false Action.
|
||||
*/
|
||||
SuggestAction(obelisk::Fact fact, obelisk::Action trueAction, obelisk::Action falseAction) :
|
||||
SuggestAction(obelisk::Fact fact,
|
||||
obelisk::Action trueAction,
|
||||
obelisk::Action falseAction) :
|
||||
id_(0),
|
||||
fact_(fact),
|
||||
trueAction_(trueAction),
|
||||
@ -88,7 +91,10 @@ namespace obelisk
|
||||
* @param[in] trueAction The true Action.
|
||||
* @param[in] falseAction The false Action.
|
||||
*/
|
||||
SuggestAction(int id, obelisk::Fact fact, obelisk::Action trueAction, obelisk::Action falseAction) :
|
||||
SuggestAction(int id,
|
||||
obelisk::Fact fact,
|
||||
obelisk::Action trueAction,
|
||||
obelisk::Action falseAction) :
|
||||
id_(id),
|
||||
fact_(fact),
|
||||
trueAction_(trueAction),
|
||||
@ -160,7 +166,8 @@ namespace obelisk
|
||||
void setFalseAction(obelisk::Action falseAction);
|
||||
|
||||
/**
|
||||
* @brief Select the SuggestAction from the KnowledgeBase by IDs of the sub-objects.
|
||||
* @brief Select the SuggestAction from the KnowledgeBase by IDs of
|
||||
* the sub-objects.
|
||||
*
|
||||
* @param[in] dbConnection The database connection to use.
|
||||
*/
|
||||
|
@ -23,7 +23,11 @@ void obelisk::Verb::selectByName(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "SELECT id, name FROM verb WHERE name=?", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"SELECT id, name FROM verb WHERE name=?",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
@ -85,13 +89,18 @@ void obelisk::Verb::insert(sqlite3* dbConnection)
|
||||
|
||||
sqlite3_stmt* ppStmt = nullptr;
|
||||
|
||||
auto result = sqlite3_prepare_v2(dbConnection, "INSERT INTO verb (name) VALUES (?)", -1, &ppStmt, nullptr);
|
||||
auto result = sqlite3_prepare_v2(dbConnection,
|
||||
"INSERT INTO verb (name) VALUES (?)",
|
||||
-1,
|
||||
&ppStmt,
|
||||
nullptr);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||
}
|
||||
|
||||
result = sqlite3_bind_text(ppStmt, 1, getName().c_str(), -1, SQLITE_TRANSIENT);
|
||||
result
|
||||
= sqlite3_bind_text(ppStmt, 1, getName().c_str(), -1, SQLITE_TRANSIENT);
|
||||
switch (result)
|
||||
{
|
||||
case SQLITE_OK :
|
||||
@ -118,7 +127,8 @@ void obelisk::Verb::insert(sqlite3* dbConnection)
|
||||
sqlite3_set_last_insert_rowid(dbConnection, 0);
|
||||
break;
|
||||
case SQLITE_CONSTRAINT :
|
||||
throw obelisk::DatabaseConstraintException(sqlite3_errmsg(dbConnection));
|
||||
throw obelisk::DatabaseConstraintException(
|
||||
sqlite3_errmsg(dbConnection));
|
||||
case SQLITE_BUSY :
|
||||
throw obelisk::DatabaseBusyException();
|
||||
break;
|
||||
|
@ -8,7 +8,8 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The Verb model represents a verb which is used to connnect entities.
|
||||
* @brief The Verb model represents a verb which is used to connnect
|
||||
* entities.
|
||||
*
|
||||
*/
|
||||
class Verb
|
||||
|
21
src/main.cpp
21
src/main.cpp
@ -10,13 +10,15 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
int obelisk::mainLoop(const std::vector<std::string>& sourceFiles, const std::string& kbFile)
|
||||
int obelisk::mainLoop(const std::vector<std::string>& sourceFiles,
|
||||
const std::string& kbFile)
|
||||
{
|
||||
std::unique_ptr<obelisk::KnowledgeBase> kb;
|
||||
|
||||
try
|
||||
{
|
||||
kb = std::unique_ptr<obelisk::KnowledgeBase> {new obelisk::KnowledgeBase(kbFile.c_str())};
|
||||
kb = std::unique_ptr<obelisk::KnowledgeBase> {
|
||||
new obelisk::KnowledgeBase(kbFile.c_str())};
|
||||
}
|
||||
catch (obelisk::KnowledgeBaseException& exception)
|
||||
{
|
||||
@ -28,7 +30,8 @@ int obelisk::mainLoop(const std::vector<std::string>& sourceFiles, const std::st
|
||||
std::shared_ptr<obelisk::Lexer> lexer;
|
||||
try
|
||||
{
|
||||
lexer = std::shared_ptr<obelisk::Lexer> {new obelisk::Lexer(sourceFiles[file++])};
|
||||
lexer = std::shared_ptr<obelisk::Lexer> {
|
||||
new obelisk::Lexer(sourceFiles[file++])};
|
||||
}
|
||||
catch (obelisk::LexerException& exception)
|
||||
{
|
||||
@ -53,14 +56,16 @@ int obelisk::mainLoop(const std::vector<std::string>& sourceFiles, const std::st
|
||||
switch (parser->getCurrentToken())
|
||||
{
|
||||
case obelisk::Lexer::kTokenEof :
|
||||
// end of source file found, create a new lexer and pass it to the parser to use
|
||||
// end of source file found, create a new lexer and pass it to
|
||||
// the parser to use
|
||||
if (file >= sourceFiles.size())
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
try
|
||||
{
|
||||
lexer = std::shared_ptr<obelisk::Lexer> {new obelisk::Lexer(sourceFiles[file++])};
|
||||
lexer = std::shared_ptr<obelisk::Lexer> {
|
||||
new obelisk::Lexer(sourceFiles[file++])};
|
||||
parser->setLexer(lexer);
|
||||
// prime the first token in the parser
|
||||
parser->getNextToken();
|
||||
@ -138,7 +143,11 @@ int main(int argc, char** argv)
|
||||
while (true)
|
||||
{
|
||||
int option_index = 0;
|
||||
switch (getopt_long(argc, argv, "k:hv", obelisk::long_options, &option_index))
|
||||
switch (getopt_long(argc,
|
||||
argv,
|
||||
"k:hv",
|
||||
obelisk::long_options,
|
||||
&option_index))
|
||||
{
|
||||
case 'k' :
|
||||
kbFile = std::string(optarg);
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <getopt.h>
|
||||
|
||||
/**
|
||||
* @brief The obelisk namespace contains everything needed to compile obelisk code.
|
||||
* @brief The obelisk namespace contains everything needed to compile obelisk
|
||||
* code.
|
||||
*
|
||||
*/
|
||||
namespace obelisk
|
||||
@ -42,5 +43,6 @@ Options:
|
||||
*
|
||||
* @return int Returns EXIT_SUCCESS or EXIT_FAILURE.
|
||||
*/
|
||||
int mainLoop(const std::vector<std::string> &sourceFiles, const std::string &kbFile);
|
||||
int mainLoop(const std::vector<std::string> &sourceFiles,
|
||||
const std::string &kbFile);
|
||||
} // namespace obelisk
|
||||
|
124
src/parser.cpp
124
src/parser.cpp
@ -42,13 +42,15 @@ void obelisk::Parser::setCurrentToken(int currentToken)
|
||||
currentToken_ = currentToken;
|
||||
}
|
||||
|
||||
std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::logError(const char* str)
|
||||
std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::logError(
|
||||
const char* str)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", str);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<obelisk::PrototypeAST> obelisk::Parser::logErrorPrototype(const char* str)
|
||||
std::unique_ptr<obelisk::PrototypeAST> obelisk::Parser::logErrorPrototype(
|
||||
const char* str)
|
||||
{
|
||||
logError(str);
|
||||
return nullptr;
|
||||
@ -82,12 +84,14 @@ std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parsePrimary()
|
||||
|
||||
std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parseNumberExpression()
|
||||
{
|
||||
auto result = std::make_unique<obelisk::NumberExpressionAST>(getLexer()->getNumberValue());
|
||||
auto result = std::make_unique<obelisk::NumberExpressionAST>(
|
||||
getLexer()->getNumberValue());
|
||||
getNextToken();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parseParenthesisExpression()
|
||||
std::unique_ptr<obelisk::ExpressionAST>
|
||||
obelisk::Parser::parseParenthesisExpression()
|
||||
{
|
||||
getNextToken();
|
||||
auto v = parseExpression();
|
||||
@ -104,7 +108,8 @@ std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parseParenthesisExpress
|
||||
return v;
|
||||
}
|
||||
|
||||
std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parseIdentifierExpression()
|
||||
std::unique_ptr<obelisk::ExpressionAST>
|
||||
obelisk::Parser::parseIdentifierExpression()
|
||||
{
|
||||
std::string idName = getLexer()->getIdentifier();
|
||||
getNextToken();
|
||||
@ -174,7 +179,8 @@ std::unique_ptr<obelisk::PrototypeAST> obelisk::Parser::parsePrototype()
|
||||
|
||||
getNextToken();
|
||||
|
||||
return std::make_unique<obelisk::PrototypeAST>(functionName, std::move(argNames));
|
||||
return std::make_unique<obelisk::PrototypeAST>(functionName,
|
||||
std::move(argNames));
|
||||
}
|
||||
|
||||
std::unique_ptr<obelisk::FunctionAST> obelisk::Parser::parseDefinition()
|
||||
@ -188,7 +194,8 @@ std::unique_ptr<obelisk::FunctionAST> obelisk::Parser::parseDefinition()
|
||||
|
||||
if (auto expression = parseExpression())
|
||||
{
|
||||
return std::make_unique<FunctionAST>(std::move(prototype), std::move(expression));
|
||||
return std::make_unique<FunctionAST>(std::move(prototype),
|
||||
std::move(expression));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@ -199,8 +206,10 @@ std::unique_ptr<obelisk::FunctionAST> obelisk::Parser::parseTopLevelExpression()
|
||||
if (auto expression = parseExpression())
|
||||
{
|
||||
// Make an anonymous prototype
|
||||
auto prototype = std::make_unique<obelisk::PrototypeAST>("__anon_expr", std::vector<std::string>());
|
||||
return std::make_unique<obelisk::FunctionAST>(std::move(prototype), std::move(expression));
|
||||
auto prototype = std::make_unique<obelisk::PrototypeAST>("__anon_expr",
|
||||
std::vector<std::string>());
|
||||
return std::make_unique<obelisk::FunctionAST>(std::move(prototype),
|
||||
std::move(expression));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -218,7 +227,8 @@ void obelisk::Parser::parseAction(obelisk::SuggestAction& suggestAction)
|
||||
getNextToken();
|
||||
if (getCurrentToken() != '(')
|
||||
{
|
||||
throw obelisk::ParserException("expected '(' but got '" + std::to_string(getCurrentToken()) + "'");
|
||||
throw obelisk::ParserException(
|
||||
"expected '(' but got '" + std::to_string(getCurrentToken()) + "'");
|
||||
}
|
||||
|
||||
syntax.push('(');
|
||||
@ -226,7 +236,8 @@ void obelisk::Parser::parseAction(obelisk::SuggestAction& suggestAction)
|
||||
getNextToken();
|
||||
if (getLexer()->getIdentifier() != "if")
|
||||
{
|
||||
throw obelisk::ParserException("expected 'if' but got '" + getLexer()->getIdentifier() + "'");
|
||||
throw obelisk::ParserException(
|
||||
"expected 'if' but got '" + getLexer()->getIdentifier() + "'");
|
||||
}
|
||||
|
||||
bool getEntity {true};
|
||||
@ -302,7 +313,8 @@ void obelisk::Parser::parseAction(obelisk::SuggestAction& suggestAction)
|
||||
{
|
||||
if (!isalpha(letter))
|
||||
{
|
||||
throw new obelisk::ParserException("non alphabetic symbol in verb");
|
||||
throw new obelisk::ParserException(
|
||||
"non alphabetic symbol in verb");
|
||||
}
|
||||
}
|
||||
getEntity = true;
|
||||
@ -357,7 +369,8 @@ void obelisk::Parser::parseAction(obelisk::SuggestAction& suggestAction)
|
||||
{
|
||||
if (getCurrentToken() == ')')
|
||||
{
|
||||
// closing parenthesis found, make sure we have everything needed
|
||||
// closing parenthesis found, make sure we have everything
|
||||
// needed
|
||||
if (syntax.top() != '(')
|
||||
{
|
||||
throw obelisk::ParserException("unexpected ')'");
|
||||
@ -421,8 +434,9 @@ void obelisk::Parser::parseAction(obelisk::SuggestAction& suggestAction)
|
||||
}
|
||||
}
|
||||
|
||||
suggestAction.setFact(
|
||||
obelisk::Fact(obelisk::Entity(leftEntity), obelisk::Entity(rightEntity), obelisk::Verb(verb)));
|
||||
suggestAction.setFact(obelisk::Fact(obelisk::Entity(leftEntity),
|
||||
obelisk::Entity(rightEntity),
|
||||
obelisk::Verb(verb)));
|
||||
suggestAction.setTrueAction(obelisk::Action(trueAction));
|
||||
suggestAction.setFalseAction(obelisk::Action(falseAction));
|
||||
}
|
||||
@ -434,7 +448,8 @@ void obelisk::Parser::parseRule(obelisk::Rule& rule)
|
||||
getNextToken();
|
||||
if (getCurrentToken() != '(')
|
||||
{
|
||||
throw obelisk::ParserException("expected '(' but got '" + std::to_string(getCurrentToken()) + "'");
|
||||
throw obelisk::ParserException(
|
||||
"expected '(' but got '" + std::to_string(getCurrentToken()) + "'");
|
||||
}
|
||||
|
||||
syntax.push('(');
|
||||
@ -509,7 +524,8 @@ void obelisk::Parser::parseRule(obelisk::Rule& rule)
|
||||
{
|
||||
if (getCurrentToken() == ')')
|
||||
{
|
||||
// closing parenthesis found, make sure we have everything needed
|
||||
// closing parenthesis found, make sure we have everything
|
||||
// needed
|
||||
if (syntax.top() != '(')
|
||||
{
|
||||
throw obelisk::ParserException("unexpected ')'");
|
||||
@ -536,12 +552,14 @@ void obelisk::Parser::parseRule(obelisk::Rule& rule)
|
||||
|
||||
if (leftReasonEntity == "")
|
||||
{
|
||||
throw obelisk::ParserException("missing left reason entity");
|
||||
throw obelisk::ParserException(
|
||||
"missing left reason entity");
|
||||
}
|
||||
|
||||
if (rightReasonEntity == "")
|
||||
{
|
||||
throw obelisk::ParserException("missing right reason entity");
|
||||
throw obelisk::ParserException(
|
||||
"missing right reason entity");
|
||||
}
|
||||
|
||||
if (reasonVerb == "")
|
||||
@ -579,7 +597,8 @@ void obelisk::Parser::parseRule(obelisk::Rule& rule)
|
||||
{
|
||||
if (!isalpha(letter))
|
||||
{
|
||||
throw new obelisk::ParserException("non alphabetic symbol in verb");
|
||||
throw new obelisk::ParserException(
|
||||
"non alphabetic symbol in verb");
|
||||
}
|
||||
}
|
||||
getEntity = true;
|
||||
@ -592,7 +611,8 @@ void obelisk::Parser::parseRule(obelisk::Rule& rule)
|
||||
{
|
||||
if (!isalpha(letter))
|
||||
{
|
||||
throw new obelisk::ParserException("non alphabetic symbol in verb");
|
||||
throw new obelisk::ParserException(
|
||||
"non alphabetic symbol in verb");
|
||||
}
|
||||
}
|
||||
getEntity = true;
|
||||
@ -602,7 +622,9 @@ void obelisk::Parser::parseRule(obelisk::Rule& rule)
|
||||
}
|
||||
}
|
||||
|
||||
rule.setFact(obelisk::Fact(obelisk::Entity(leftEntity), obelisk::Entity(rightEntity), obelisk::Verb(verb)));
|
||||
rule.setFact(obelisk::Fact(obelisk::Entity(leftEntity),
|
||||
obelisk::Entity(rightEntity),
|
||||
obelisk::Verb(verb)));
|
||||
rule.setReason(obelisk::Fact(obelisk::Entity(leftReasonEntity),
|
||||
obelisk::Entity(rightReasonEntity),
|
||||
obelisk::Verb(reasonVerb)));
|
||||
@ -615,7 +637,8 @@ void obelisk::Parser::parseFact(std::vector<obelisk::Fact>& facts)
|
||||
getNextToken();
|
||||
if (getCurrentToken() != '(')
|
||||
{
|
||||
throw obelisk::ParserException("expected '(' but got '" + std::to_string(getCurrentToken()) + "'");
|
||||
throw obelisk::ParserException(
|
||||
"expected '(' but got '" + std::to_string(getCurrentToken()) + "'");
|
||||
}
|
||||
|
||||
syntax.push('(');
|
||||
@ -671,7 +694,8 @@ void obelisk::Parser::parseFact(std::vector<obelisk::Fact>& facts)
|
||||
{
|
||||
if (getCurrentToken() == ')')
|
||||
{
|
||||
// closing parenthesis found, make sure we have everything needed
|
||||
// closing parenthesis found, make sure we have everything
|
||||
// needed
|
||||
if (syntax.top() != '(')
|
||||
{
|
||||
throw obelisk::ParserException("unexpected ')'");
|
||||
@ -688,12 +712,14 @@ void obelisk::Parser::parseFact(std::vector<obelisk::Fact>& facts)
|
||||
|
||||
if (leftEntities.size() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("missing left side entities");
|
||||
throw obelisk::ParserException(
|
||||
"missing left side entities");
|
||||
}
|
||||
|
||||
if (rightEntities.size() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("missing right side entities");
|
||||
throw obelisk::ParserException(
|
||||
"missing right side entities");
|
||||
}
|
||||
|
||||
getNextToken();
|
||||
@ -723,7 +749,8 @@ void obelisk::Parser::parseFact(std::vector<obelisk::Fact>& facts)
|
||||
{
|
||||
if (!isalpha(letter))
|
||||
{
|
||||
throw new obelisk::ParserException("non alphabetic symbol in verb");
|
||||
throw new obelisk::ParserException(
|
||||
"non alphabetic symbol in verb");
|
||||
}
|
||||
}
|
||||
getEntity = true;
|
||||
@ -736,8 +763,10 @@ void obelisk::Parser::parseFact(std::vector<obelisk::Fact>& facts)
|
||||
{
|
||||
for (auto& rightEntity : rightEntities)
|
||||
{
|
||||
facts.push_back(
|
||||
obelisk::Fact(obelisk::Entity(leftEntity), obelisk::Entity(rightEntity), obelisk::Verb(verb), true));
|
||||
facts.push_back(obelisk::Fact(obelisk::Entity(leftEntity),
|
||||
obelisk::Entity(rightEntity),
|
||||
obelisk::Verb(verb),
|
||||
true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -850,7 +879,8 @@ void obelisk::Parser::handleFact(std::unique_ptr<obelisk::KnowledgeBase>& kb)
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Parser::insertEntity(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Entity& entity)
|
||||
void obelisk::Parser::insertEntity(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Entity& entity)
|
||||
{
|
||||
std::vector<obelisk::Entity> entities {entity};
|
||||
kb->addEntities(entities);
|
||||
@ -862,12 +892,14 @@ void obelisk::Parser::insertEntity(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
kb->getEntity(entity);
|
||||
if (entity.getId() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("entity could not be inserted into the database");
|
||||
throw obelisk::ParserException(
|
||||
"entity could not be inserted into the database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Parser::insertVerb(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Verb& verb)
|
||||
void obelisk::Parser::insertVerb(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Verb& verb)
|
||||
{
|
||||
std::vector<obelisk::Verb> verbs {verb};
|
||||
kb->addVerbs(verbs);
|
||||
@ -879,12 +911,14 @@ void obelisk::Parser::insertVerb(std::unique_ptr<obelisk::KnowledgeBase>& kb, ob
|
||||
kb->getVerb(verb);
|
||||
if (verb.getId() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("verb could not be inserted into the database");
|
||||
throw obelisk::ParserException(
|
||||
"verb could not be inserted into the database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Parser::insertAction(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Action& action)
|
||||
void obelisk::Parser::insertAction(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Action& action)
|
||||
{
|
||||
std::vector<obelisk::Action> actions {action};
|
||||
kb->addActions(actions);
|
||||
@ -896,12 +930,15 @@ void obelisk::Parser::insertAction(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
kb->getAction(action);
|
||||
if (action.getId() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("action could not be inserted into the database");
|
||||
throw obelisk::ParserException(
|
||||
"action could not be inserted into the database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Parser::insertFact(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Fact& fact, bool updateIsTrue)
|
||||
void obelisk::Parser::insertFact(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Fact& fact,
|
||||
bool updateIsTrue)
|
||||
{
|
||||
std::vector<obelisk::Fact> facts {fact};
|
||||
kb->addFacts(facts);
|
||||
@ -913,7 +950,8 @@ void obelisk::Parser::insertFact(std::unique_ptr<obelisk::KnowledgeBase>& kb, ob
|
||||
kb->getFact(fact);
|
||||
if (fact.getId() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("fact could not be inserted into the database");
|
||||
throw obelisk::ParserException(
|
||||
"fact could not be inserted into the database");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -926,7 +964,8 @@ void obelisk::Parser::insertFact(std::unique_ptr<obelisk::KnowledgeBase>& kb, ob
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Parser::insertSuggestAction(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
void obelisk::Parser::insertSuggestAction(
|
||||
std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::SuggestAction& suggestAction)
|
||||
{
|
||||
std::vector<obelisk::SuggestAction> suggestActions {suggestAction};
|
||||
@ -939,12 +978,14 @@ void obelisk::Parser::insertSuggestAction(std::unique_ptr<obelisk::KnowledgeBase
|
||||
kb->getSuggestAction(suggestAction);
|
||||
if (suggestAction.getId() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("suggest_action could not be inserted into the database");
|
||||
throw obelisk::ParserException(
|
||||
"suggest_action could not be inserted into the database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obelisk::Parser::insertRule(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Rule& rule)
|
||||
void obelisk::Parser::insertRule(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Rule& rule)
|
||||
{
|
||||
std::vector<obelisk::Rule> rules {rule};
|
||||
kb->addRules(rules);
|
||||
@ -956,7 +997,8 @@ void obelisk::Parser::insertRule(std::unique_ptr<obelisk::KnowledgeBase>& kb, ob
|
||||
kb->getRule(rule);
|
||||
if (rule.getId() == 0)
|
||||
{
|
||||
throw obelisk::ParserException("rule could not be inserted into the database");
|
||||
throw obelisk::ParserException(
|
||||
"rule could not be inserted into the database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
95
src/parser.h
95
src/parser.h
@ -18,14 +18,16 @@
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The Parser is responsible for analyzing the language's key words and taking action based on its analysis.
|
||||
* @brief The Parser is responsible for analyzing the language's key words
|
||||
* and taking action based on its analysis.
|
||||
*
|
||||
*/
|
||||
class Parser
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief The Lexer object that the Parser is using to Parse a specific source file.
|
||||
* @brief The Lexer object that the Parser is using to Parse a
|
||||
* specific source file.
|
||||
*
|
||||
*/
|
||||
std::shared_ptr<obelisk::Lexer> lexer_;
|
||||
@ -47,7 +49,8 @@ namespace obelisk
|
||||
* @brief Log errors from the LLVM parsing.
|
||||
*
|
||||
* @param[in] str The error message.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the AST expression that caused the error.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the AST
|
||||
* expression that caused the error.
|
||||
*/
|
||||
std::unique_ptr<obelisk::ExpressionAST> logError(const char* str);
|
||||
|
||||
@ -55,70 +58,82 @@ namespace obelisk
|
||||
* @brief Log errors from the LLVM parsing involving the prototypes.
|
||||
*
|
||||
* @param[in] str The error message.
|
||||
* @return std::unique_ptr<obelisk::PrototypeAST> Returns the AST for the prototype.
|
||||
* @return std::unique_ptr<obelisk::PrototypeAST> Returns the AST
|
||||
* for the prototype.
|
||||
*/
|
||||
std::unique_ptr<obelisk::PrototypeAST> logErrorPrototype(const char* str);
|
||||
std::unique_ptr<obelisk::PrototypeAST> logErrorPrototype(
|
||||
const char* str);
|
||||
|
||||
/**
|
||||
* @brief The AST expression parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the parsed AST expression.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the
|
||||
* parsed AST expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::ExpressionAST> parseExpression();
|
||||
|
||||
/**
|
||||
* @brief The AST number expression parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the parsed AST expression.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the
|
||||
* parsed AST expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::ExpressionAST> parseNumberExpression();
|
||||
|
||||
/**
|
||||
* @brief The AST parenthesis expression parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the parsed AST expression.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the
|
||||
* parsed AST expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::ExpressionAST> parseParenthesisExpression();
|
||||
std::unique_ptr<obelisk::ExpressionAST>
|
||||
parseParenthesisExpression();
|
||||
|
||||
/**
|
||||
* @brief The AST identifier expression parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the parsed AST expression.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the
|
||||
* parsed AST expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::ExpressionAST> parseIdentifierExpression();
|
||||
|
||||
/**
|
||||
* @brief The AST primary expression parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the parsed AST expression.
|
||||
* @return std::unique_ptr<obelisk::ExpressionAST> Returns the
|
||||
* parsed AST expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::ExpressionAST> parsePrimary();
|
||||
|
||||
/**
|
||||
* @brief The AST prototype parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::PrototypeAST> Returns the parsed AST prototype expression.
|
||||
* @return std::unique_ptr<obelisk::PrototypeAST> Returns the parsed
|
||||
* AST prototype expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::PrototypeAST> parsePrototype();
|
||||
|
||||
/**
|
||||
* @brief The AST definition parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::FunctionAST> Returns the parsed AST definition expression.
|
||||
* @return std::unique_ptr<obelisk::FunctionAST> Returns the parsed
|
||||
* AST definition expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::FunctionAST> parseDefinition();
|
||||
|
||||
/**
|
||||
* @brief The AST top level expression parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::FunctionAST> Returns the parsed AST top level expression.
|
||||
* @return std::unique_ptr<obelisk::FunctionAST> Returns the parsed
|
||||
* AST top level expression.
|
||||
*/
|
||||
std::unique_ptr<obelisk::FunctionAST> parseTopLevelExpression();
|
||||
|
||||
/**
|
||||
* @brief The AST external definition parser.
|
||||
*
|
||||
* @return std::unique_ptr<obelisk::PrototypeAST> Returns the parsed AST external definition.
|
||||
* @return std::unique_ptr<obelisk::PrototypeAST> Returns the parsed
|
||||
* AST external definition.
|
||||
*/
|
||||
std::unique_ptr<obelisk::PrototypeAST> parseExtern();
|
||||
|
||||
@ -147,7 +162,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Construct a new Parser object.
|
||||
*
|
||||
* @param[in] lexer The lexer the parser uses to retrieve parts of the language.
|
||||
* @param[in] lexer The lexer the parser uses to retrieve parts of
|
||||
* the language.
|
||||
*/
|
||||
Parser(std::shared_ptr<obelisk::Lexer> lexer) :
|
||||
lexer_(lexer)
|
||||
@ -157,7 +173,8 @@ namespace obelisk
|
||||
/**
|
||||
* @brief Get the Lexer.
|
||||
*
|
||||
* @return std::shared_ptr<obelisk::Lexer> Returns the current Lexer in use by the Parser.
|
||||
* @return std::shared_ptr<obelisk::Lexer> Returns the current Lexer
|
||||
* in use by the Parser.
|
||||
*/
|
||||
std::shared_ptr<obelisk::Lexer> getLexer();
|
||||
|
||||
@ -183,7 +200,8 @@ namespace obelisk
|
||||
int getNextToken();
|
||||
|
||||
/**
|
||||
* @brief Parse the SuggestAction and then insert it into the KnowledgeBase.
|
||||
* @brief Parse the SuggestAction and then insert it into the
|
||||
* KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledgeBase to insert the SuggestAction into.
|
||||
*/
|
||||
@ -207,55 +225,66 @@ namespace obelisk
|
||||
* @brief Helper used to insert an Entity into the KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledgeBase to use.
|
||||
* @param[in,out] entity The Entity to insert. It will contain the ID of the Entity after inserting it.
|
||||
* @param[in,out] entity The Entity to insert. It will contain the
|
||||
* ID of the Entity after inserting it.
|
||||
*/
|
||||
void insertEntity(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Entity& entity);
|
||||
void insertEntity(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Entity& entity);
|
||||
|
||||
/**
|
||||
* @brief Helper used to insert a Verb into the KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledegeBase to use.
|
||||
* @param[in,out] verb The Verb to insert. It will contain the ID of the Verb after inserting it.
|
||||
* @param[in,out] verb The Verb to insert. It will contain the ID of
|
||||
* the Verb after inserting it.
|
||||
*/
|
||||
void insertVerb(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Verb& verb);
|
||||
void insertVerb(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Verb& verb);
|
||||
|
||||
/**
|
||||
* @brief Helper used to insert an Action into the KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledgeBase to use.
|
||||
* @param[in,out] action The Action to insert. It will contain the ID of the Action after inserting it.
|
||||
* @param[in,out] action The Action to insert. It will contain the
|
||||
* ID of the Action after inserting it.
|
||||
*/
|
||||
void insertAction(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Action& action);
|
||||
void insertAction(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Action& action);
|
||||
|
||||
/**
|
||||
* @brief Helper used to insert a Fact into the KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledgeBase to use.
|
||||
* @param[in,out] fact The Fact to insert. It will contain the ID of the Fact after inserting it.
|
||||
* @param[in] updateIsTrue If true, it will update the value of is_true in the KnowledgeBase if the Fact
|
||||
* already exists.
|
||||
* @param[in,out] fact The Fact to insert. It will contain the ID of
|
||||
* the Fact after inserting it.
|
||||
* @param[in] updateIsTrue If true, it will update the value of
|
||||
* is_true in the KnowledgeBase if the Fact already exists.
|
||||
*/
|
||||
void insertFact(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Fact& fact,
|
||||
bool updateIsTrue = false);
|
||||
|
||||
/**
|
||||
* @brief Helper used to insert a SuggestAction into the KnowledgeBase.
|
||||
* @brief Helper used to insert a SuggestAction into the
|
||||
* KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledgeBase to use.
|
||||
* @param[in,out] suggestAction The SuggestAction to insert. It will contain the ID of the SuggestAction
|
||||
* after inserting it.
|
||||
* @param[in,out] suggestAction The SuggestAction to insert. It will
|
||||
* contain the ID of the SuggestAction after inserting it.
|
||||
*/
|
||||
void insertSuggestAction(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
void insertSuggestAction(
|
||||
std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::SuggestAction& suggestAction);
|
||||
|
||||
/**
|
||||
* @brief Helper usedto insert a Rule into the KnowledgeBase.
|
||||
*
|
||||
* @param[in] kb The KnowledgeBase to use.
|
||||
* @param[in,out] rule The Rule to insert. It will contain the ID of the Rule after inserting it.
|
||||
* @param[in,out] rule The Rule to insert. It will contain the ID of
|
||||
* the Rule after inserting it.
|
||||
*/
|
||||
void insertRule(std::unique_ptr<obelisk::KnowledgeBase>& kb, obelisk::Rule& rule);
|
||||
void insertRule(std::unique_ptr<obelisk::KnowledgeBase>& kb,
|
||||
obelisk::Rule& rule);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user