2022-10-25 17:08:36 -03:00
|
|
|
#include "knowledge_base.h"
|
2022-10-17 22:26:36 -03:00
|
|
|
#include "lexer.h"
|
|
|
|
#include "obelisk.h"
|
|
|
|
#include "parser.h"
|
|
|
|
|
2022-10-25 17:08:36 -03:00
|
|
|
#include <iomanip>
|
2022-10-17 22:26:36 -03:00
|
|
|
#include <iostream>
|
2022-10-25 17:08:36 -03:00
|
|
|
#include <limits>
|
2022-11-04 11:20:34 -03:00
|
|
|
#include <memory>
|
2022-10-17 22:26:36 -03:00
|
|
|
|
|
|
|
static void mainLoop()
|
|
|
|
{
|
2022-11-04 11:20:34 -03:00
|
|
|
auto parser = std::unique_ptr<obelisk::Parser> {new obelisk::Parser()};
|
2022-10-17 22:26:36 -03:00
|
|
|
|
|
|
|
// Prime the first token.
|
|
|
|
fprintf(stderr, "ready> ");
|
|
|
|
parser->getNextToken();
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ready> ");
|
|
|
|
switch (parser->getCurrentToken())
|
|
|
|
{
|
|
|
|
case obelisk::Lexer::kTokenEof :
|
|
|
|
return;
|
|
|
|
case ';' : // ignore top-level semicolons.
|
|
|
|
std::cout << "Identifier: "
|
|
|
|
<< parser->getLexer()->getIdentifier() << std::endl;
|
|
|
|
std::cout << "Num: " << parser->getLexer()->getNumberValue()
|
|
|
|
<< std::endl;
|
|
|
|
parser->getNextToken();
|
|
|
|
break;
|
2022-11-04 11:20:34 -03:00
|
|
|
case obelisk::Lexer::kTokenFact :
|
|
|
|
// parser->handleFactFunction();
|
|
|
|
break;
|
|
|
|
case obelisk::Lexer::kTokenRule :
|
|
|
|
// parser->handleRuleFunction();
|
|
|
|
break;
|
|
|
|
case obelisk::Lexer::kTokenAction :
|
|
|
|
// parser->handleActionFunction();
|
|
|
|
break;
|
2022-10-17 22:26:36 -03:00
|
|
|
default :
|
|
|
|
parser->getNextToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
std::cout << argv[i] << std::endl;
|
|
|
|
}
|
|
|
|
|
2022-11-04 11:20:34 -03:00
|
|
|
// This can be used to store a double as 2 floats in the database, then restore it back to a double.
|
|
|
|
// Inspired by Godot's double precision on the GPU to render large worlds.
|
|
|
|
/*try
|
2022-10-25 17:08:36 -03:00
|
|
|
{
|
2022-11-04 11:20:34 -03:00
|
|
|
float first;
|
|
|
|
float second;
|
|
|
|
double var = 0.123456789012345;
|
|
|
|
|
2022-10-25 17:08:36 -03:00
|
|
|
obelisk::KnowledgeBase* kb = new obelisk::KnowledgeBase("cromer.kb");
|
2022-11-04 11:20:34 -03:00
|
|
|
kb->getFloat(first, second, var);
|
|
|
|
std::cout << std::setprecision(std::numeric_limits<double>::digits10)
|
|
|
|
<< "Double: " << var << std::endl
|
|
|
|
<< "First: " << first << std::endl
|
|
|
|
<< "Second: " << second << std::endl;
|
|
|
|
var = 0.0;
|
|
|
|
kb->getDouble(var, first, second);
|
|
|
|
std::cout << std::setprecision(std::numeric_limits<double>::digits10)
|
|
|
|
<< "Double: " << var << std::endl
|
|
|
|
<< "First: " << first << std::endl
|
|
|
|
<< "Second: " << second << std::endl;
|
|
|
|
}
|
|
|
|
catch (obelisk::KnowledgeBaseException& exception)
|
|
|
|
{
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto kb = std::unique_ptr<obelisk::KnowledgeBase> {
|
|
|
|
new obelisk::KnowledgeBase("cromer.kb")};
|
2022-10-25 17:08:36 -03:00
|
|
|
|
|
|
|
/*std::vector<std::string> leftObjects;
|
|
|
|
std::vector<std::string> rightObjects;
|
|
|
|
leftObjects.push_back("chris");
|
|
|
|
leftObjects.push_back("martin");
|
|
|
|
|
|
|
|
rightObjects.push_back("happy");
|
|
|
|
rightObjects.push_back("smart");
|
|
|
|
|
|
|
|
kb->addFacts("is", leftObjects, rightObjects);*/
|
|
|
|
}
|
|
|
|
catch (obelisk::KnowledgeBaseException& exception)
|
|
|
|
{
|
|
|
|
std::cout << exception.what() << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2022-10-17 22:26:36 -03:00
|
|
|
mainLoop();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|