added EQ and NEQ
This commit is contained in:
@@ -14,12 +14,16 @@ namespace lexer {
|
||||
|
||||
switch (c) {
|
||||
case '=':
|
||||
if (input.peek() == '=')
|
||||
return {token::type::EQ, std::string{c, (char) input.get()}};
|
||||
return {token::type::ASSIGN, c};
|
||||
case '+':
|
||||
return {token::type::PLUS, c};
|
||||
case '-':
|
||||
return {token::type::MINUS, c};
|
||||
case '!':
|
||||
if (input.peek() == '=')
|
||||
return {token::type::NEQ, std::string{c, (char) input.get()}};
|
||||
return {token::type::BANG, c};
|
||||
case '*':
|
||||
return {token::type::ASTERISK, c};
|
||||
|
@@ -30,6 +30,8 @@ namespace token {
|
||||
X(ELSE, "ELSE") \
|
||||
X(TRUE, "TRUE") \
|
||||
X(FALSE, "FALSE") \
|
||||
X(EQ, "==") \
|
||||
X(NEQ, "!=") \
|
||||
X(RETURN, "RETURN")
|
||||
|
||||
// Define the TokenType enum using the X-macro
|
||||
|
@@ -56,6 +56,9 @@ if (5 < 10) {\
|
||||
} else {\
|
||||
return false;\
|
||||
}\
|
||||
\
|
||||
10 == 10;\
|
||||
10 != 9;\
|
||||
");
|
||||
|
||||
lexer::lexer l{ss};
|
||||
@@ -137,6 +140,16 @@ if (5 < 10) {\
|
||||
{token::type::SEMICOLON, ";"},
|
||||
|
||||
{token::type::RBRACE, "}"},
|
||||
|
||||
{token::type::INT, "10"},
|
||||
{token::type::EQ, "=="},
|
||||
{token::type::INT, "10"},
|
||||
{token::type::SEMICOLON, ";"},
|
||||
|
||||
{token::type::INT, "10"},
|
||||
{token::type::NEQ, "!="},
|
||||
{token::type::INT, "9"},
|
||||
{token::type::SEMICOLON, ";"},
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user