1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
void Lexer::Lex()
{
string::const_iterator Start = this->Source.begin(),
End = this->Source.end ();
smatch Match;
match_flag_type Flags = match_default;
while(!this->Source.empty())
{
if(regex_search(Start, End, Match, regex("\"[^\"]*\""), Flags))
this->SymbolTable->PushBack("STRING", string(Match[0].first, Match[0].second), 0, -1);
else if(regex_search(Start, End, Match, regex("import|function|var|println|end"), Flags))
this->SymbolTable->PushBack("KEYWORD", string(Match[0].first, Match[0].second), 0, -1);
else if(regex_search(Start, End, Match, regex("[;\(\)\[\]\{\}&]"), Flags))
this->SymbolTable->PushBack("OPERATOR", string(Match[0].first, Match[0].second), 0, -1);
else if(regex_search(Start, End, Match, regex("[_a-zA-Z][_a-zA-Z0-9]*"), Flags))
this->SymbolTable->PushBack("IDENTIFIER", string(Match[0].first, Match[0].second), 0, -1);
this->SymbolTable->Next();
Start = Match[0].second;
Flags |= match_prev_avail;
Flags |= match_not_bob;
this->Source = string(Start, End);
}
}
|