Add more logical operators
This commit is contained in:
parent
fb261e26f9
commit
c61b26e692
@ -11,7 +11,7 @@ using namespace std;
|
||||
/**
|
||||
* Tokens definition
|
||||
*/
|
||||
enum class TokenType { Type, Identifier, Int, Plus, Minus, DoublePlus, DoubleMinus, DoubleEqual, Lt, Gt, Leq, Geq, NotEqual, Not, Star, Slash, Percent, Equal, Semicolon, LParenthese, RParenthese, LCurlyBracket, RCurlyBracket, If, Else };
|
||||
enum class TokenType { Type, Identifier, Int, Plus, Minus, DoublePlus, DoubleMinus, DoubleEqual, Land, Lor, Lt, Gt, Leq, Geq, NotEqual, Not, Star, Slash, Percent, Equal, Semicolon, LParenthese, RParenthese, LCurlyBracket, RCurlyBracket, If, Else };
|
||||
enum class Type { Int };
|
||||
|
||||
using TokenData = variant<int, string, Type>;
|
||||
@ -52,6 +52,8 @@ Comp ->
|
||||
| Sum > Comp
|
||||
| Sum <= Comp
|
||||
| Sum >= Comp
|
||||
| Sum && Comp
|
||||
| Sum || Comp
|
||||
|
||||
Sum ->
|
||||
| Term
|
||||
|
@ -35,6 +35,12 @@ void _debug_print_token(Token token) {
|
||||
case TokenType::DoubleEqual:
|
||||
cout << "==";
|
||||
break;
|
||||
case TokenType::Land:
|
||||
cout << "&&";
|
||||
break;
|
||||
case TokenType::Lor:
|
||||
cout << "||";
|
||||
break;
|
||||
case TokenType::Lt:
|
||||
cout << "<";
|
||||
break;
|
||||
@ -152,6 +158,16 @@ vector<Token> tokenize(vector<string> input, int initial_line) {
|
||||
tokens.emplace_back(token);
|
||||
j += 2;
|
||||
}
|
||||
else if (str.starts_with("&&")) {
|
||||
Token token = { .type = TokenType::Land, .pos = pos };
|
||||
tokens.emplace_back(token);
|
||||
j += 2;
|
||||
}
|
||||
else if (str.starts_with("||")) {
|
||||
Token token = { .type = TokenType::Lor, .pos = pos };
|
||||
tokens.emplace_back(token);
|
||||
j += 2;
|
||||
}
|
||||
else if (str.starts_with("<")) {
|
||||
Token token = { .type = TokenType::Lt, .pos = pos };
|
||||
tokens.emplace_back(token);
|
||||
|
Loading…
Reference in New Issue
Block a user