Skip to content

Commit

Permalink
Modern logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed May 25, 2022
1 parent d39085b commit 3562e96
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion compiler/toker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void Toker::nextline()
continue;
}
int n = line[k + 1];
if((c == '<' && n == '>') || (c == '>' && n == '<'))
if((c == '<' && n == '>') || (c == '>' && n == '<') || (c == '!' && n == '='))
{
tokes.push_back(Toke(NE, from, k += 2));
continue;
Expand All @@ -253,6 +253,27 @@ void Toker::nextline()
tokes.push_back(Toke(GE, from, k += 2));
continue;
}
//Modern logical operators: &, |, !, !=, ^
if (c == '&') {
if (n != ' ') line = line.insert(k, 1, ' ');
tokes.push_back(Toke(AND, from, k += 2));
continue;
}
if (c == '|') {
if (n != ' ') line = line.insert(k, 1, ' ');
tokes.push_back(Toke(OR, from, k += 2));
continue;
}
if (c == '!') {
if (n != ' ') line = line.insert(k, 1, ' ');
tokes.push_back(Toke(NOT, from, k += 2));
continue;
}
if (c == '^') {
if (n != ' ') line = line.insert(k, 1, ' ');
tokes.push_back(Toke(XOR, from, k += 2));
continue;
}
tokes.push_back(Toke(c, from, ++k));
}
if(!tokes.size()) exit(0);
Expand Down

0 comments on commit 3562e96

Please # to comment.