Lexer daha anlaşılır hale getirildi
This commit is contained in:
parent
8adeabaff1
commit
0f33740a07
136
core/Lexer.cpp
136
core/Lexer.cpp
|
|
@ -20,12 +20,35 @@ public:
|
|||
int size = 0;
|
||||
int offset = 0;
|
||||
std::vector<int> offsetMap;
|
||||
void beginPosition()
|
||||
{
|
||||
void beginPosition();
|
||||
int getLastPosition();
|
||||
void acceptPosition();
|
||||
void setLastPosition(int);
|
||||
bool isEnd();
|
||||
void rejectPosition();
|
||||
int * positionRange();
|
||||
std::string getPositionRange();
|
||||
bool include(std::string,bool);
|
||||
int getOffset();
|
||||
int setOffset(int);
|
||||
char getchar(int);
|
||||
char getchar();
|
||||
void nextChar();
|
||||
void toChar(int);
|
||||
void setText(std::string);
|
||||
void skipWhiteSpace();
|
||||
bool isNumeric();
|
||||
INumber readNumeric();
|
||||
};
|
||||
|
||||
void Lexer::beginPosition()
|
||||
{
|
||||
this->offsetMap.push_back(this->getLastPosition());
|
||||
}
|
||||
int getLastPosition()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Lexer::getLastPosition()
|
||||
{
|
||||
if(this->offsetMap.size() == 0)
|
||||
{
|
||||
return this->offset;
|
||||
|
|
@ -34,14 +57,14 @@ public:
|
|||
{
|
||||
return this->offsetMap[this->offsetMap.size() - 1];
|
||||
}
|
||||
}
|
||||
void acceptPosition()
|
||||
{
|
||||
}
|
||||
void Lexer::acceptPosition()
|
||||
{
|
||||
int T = this->offsetMap[this->offsetMap.size() - 1];
|
||||
this->setLastPosition(T);
|
||||
}
|
||||
void setLastPosition(int n)
|
||||
{
|
||||
}
|
||||
void Lexer::setLastPosition(int n)
|
||||
{
|
||||
if(this->offsetMap.size() == 0)
|
||||
{
|
||||
this->offset = n;
|
||||
|
|
@ -50,18 +73,18 @@ public:
|
|||
{
|
||||
this->offsetMap[this->offsetMap.size() - 1] = n;
|
||||
}
|
||||
}
|
||||
bool isEnd()
|
||||
{
|
||||
}
|
||||
bool Lexer::isEnd()
|
||||
{
|
||||
bool result = this->size <= this->getOffset();
|
||||
return result;
|
||||
}
|
||||
void rejectPosition()
|
||||
{
|
||||
}
|
||||
void Lexer::rejectPosition()
|
||||
{
|
||||
this->offsetMap.pop_back();
|
||||
}
|
||||
int * positionRange()
|
||||
{
|
||||
}
|
||||
int * Lexer::positionRange()
|
||||
{
|
||||
int len = this->offsetMap.size();
|
||||
if(len == 0)
|
||||
{
|
||||
|
|
@ -79,9 +102,9 @@ public:
|
|||
this->offsetMap[len - 1]
|
||||
};
|
||||
}
|
||||
}
|
||||
std::string getPositionRange()
|
||||
{
|
||||
}
|
||||
std::string Lexer::getPositionRange()
|
||||
{
|
||||
int *A = this->positionRange();
|
||||
std::string mem;
|
||||
|
||||
|
|
@ -90,10 +113,10 @@ public:
|
|||
mem.push_back(this->input.at(i));
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
}
|
||||
|
||||
bool include(std::string word,bool accept = true)
|
||||
{
|
||||
bool Lexer::include(std::string word,bool accept = true)
|
||||
{
|
||||
this->beginPosition();
|
||||
for (int i = 0; i < word.size(); i++)
|
||||
{
|
||||
|
|
@ -123,18 +146,18 @@ public:
|
|||
this->rejectPosition();
|
||||
};
|
||||
return true;
|
||||
}
|
||||
int getOffset()
|
||||
{
|
||||
}
|
||||
int Lexer::getOffset()
|
||||
{
|
||||
return this->getLastPosition();
|
||||
}
|
||||
int setOffset(int n)
|
||||
{
|
||||
}
|
||||
int Lexer::setOffset(int n)
|
||||
{
|
||||
this->setLastPosition(n);
|
||||
return this->getLastPosition();
|
||||
}
|
||||
char getchar(int additionalOffset = 0)
|
||||
{
|
||||
}
|
||||
char Lexer::getchar(int additionalOffset)
|
||||
{
|
||||
int target = this->getOffset() + additionalOffset;
|
||||
if(this->size - 1 < target)
|
||||
{
|
||||
|
|
@ -143,29 +166,40 @@ public:
|
|||
}else{
|
||||
return this->input.at(target);
|
||||
}
|
||||
}
|
||||
void nextChar()
|
||||
}
|
||||
char Lexer::getchar()
|
||||
{
|
||||
int target = this->getOffset();
|
||||
if(this->size - 1 < target)
|
||||
{
|
||||
std::cerr << "Hata yanlış erişim\n";
|
||||
return '\0';
|
||||
}else{
|
||||
return this->input.at(target);
|
||||
}
|
||||
}
|
||||
void Lexer::nextChar()
|
||||
{
|
||||
if(this->isEnd() == true)
|
||||
{
|
||||
return;
|
||||
};
|
||||
this->setOffset(this->getOffset() + 1);
|
||||
}
|
||||
void toChar(int n)
|
||||
{
|
||||
}
|
||||
void Lexer::toChar(int n)
|
||||
{
|
||||
if(this->isEnd() == true)
|
||||
{
|
||||
return;
|
||||
};
|
||||
this->setOffset(this->getOffset() + n);
|
||||
}
|
||||
void setText(std::string input) {
|
||||
}
|
||||
void Lexer::setText(std::string input) {
|
||||
this->input = input;
|
||||
this->size = input.length();
|
||||
}
|
||||
void skipWhiteSpace()
|
||||
{
|
||||
}
|
||||
void Lexer::skipWhiteSpace()
|
||||
{
|
||||
while(this->isEnd() == false)
|
||||
{
|
||||
switch(this->getchar())
|
||||
|
|
@ -183,10 +217,10 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isNumeric()
|
||||
{
|
||||
bool Lexer::isNumeric()
|
||||
{
|
||||
char c = this->getchar();
|
||||
switch (c)
|
||||
{
|
||||
|
|
@ -206,9 +240,10 @@ public:
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INumber readNumeric(){
|
||||
INumber Lexer::readNumeric()
|
||||
{
|
||||
INumber numberToken;
|
||||
numberToken.start = this->getLastPosition();
|
||||
if(this->getchar() == '-')
|
||||
|
|
@ -386,6 +421,5 @@ public:
|
|||
}
|
||||
numberToken.end = this->getLastPosition();
|
||||
return numberToken;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
Loading…
Reference in New Issue