feature/knowledge_base #3

Merged
cromer merged 9 commits from feature/knowledge_base into develop 2022-11-09 16:52:23 -03:00
2 changed files with 25 additions and 10 deletions
Showing only changes of commit 6592f208d9 - Show all commits

View File

@ -8,7 +8,7 @@ int obelisk::Lexer::getToken()
while (isspace(lastChar))
{
lastChar = getchar();
lastChar = std::getc(stdin);
}
if (isalpha(lastChar))
@ -20,6 +20,21 @@ int obelisk::Lexer::getToken()
appendIdentifier(lastChar);
}
if (getIdentifier() == "fact")
{
return Token::kTokenFact;
}
if (getIdentifier() == "rule")
{
return Token::kTokenFact;
}
if (getIdentifier() == "action")
{
return Token::kTokenAction;
}
if (getIdentifier() == "def")
{
return Token::kTokenDef;
@ -90,12 +105,12 @@ void obelisk::Lexer::commentLine(int* lastChar)
while (*lastChar != EOF && *lastChar != '\n' && *lastChar != '\r');
}
std::string obelisk::Lexer::getIdentifier()
const std::string& obelisk::Lexer::getIdentifier()
{
return identifier_;
}
void obelisk::Lexer::setIdentifier(const std::string identifier)
void obelisk::Lexer::setIdentifier(const std::string& identifier)
{
identifier_ = identifier;
}

View File

@ -3,16 +3,16 @@
#include <string>
// TODO: add error handling
namespace obelisk
{
class Lexer
{
private:
std::string identifier_;
double numberValue_;
void setIdentifier(const std::string identifier);
void setIdentifier(const std::string& identifier);
void eraseIdentifier();
void appendIdentifier(int lastChar);
void setNumberValue(double numberValue);
@ -21,12 +21,12 @@ namespace obelisk
public:
enum Token
{
kTokenInvalid = -1,
kTokenEof = -2,
kTokenEof = -1,
// commands
kTokenFact = -3,
kTokenRule = -4,
kTokenFact = -2,
kTokenRule = -3,
kTokenAction = -4,
kTokenDef = -5,
kTokenExtern = -6,
@ -38,7 +38,7 @@ namespace obelisk
int getToken();
std::string getIdentifier();
const std::string& getIdentifier();
double getNumberValue();
};
} // namespace obelisk