forked from KPGPMC/furlang
Add comparison operators
Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
@@ -88,6 +88,13 @@ enum class binop_expression_node_t {
|
|||||||
Mul,
|
Mul,
|
||||||
Div,
|
Div,
|
||||||
Mod,
|
Mod,
|
||||||
|
|
||||||
|
Equal,
|
||||||
|
NotEqual,
|
||||||
|
LessThan,
|
||||||
|
GreaterThan,
|
||||||
|
LessEqual,
|
||||||
|
GreaterEqual,
|
||||||
};
|
};
|
||||||
|
|
||||||
class binop_expression_node : public expression_node {
|
class binop_expression_node : public expression_node {
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ enum class token_t {
|
|||||||
StarEq,
|
StarEq,
|
||||||
SlashEq,
|
SlashEq,
|
||||||
PercentEq,
|
PercentEq,
|
||||||
|
|
||||||
|
DEq,
|
||||||
|
NotEq,
|
||||||
|
LessThan,
|
||||||
|
GreaterThan,
|
||||||
|
LessEq,
|
||||||
|
GreaterEq,
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline std::ostream& operator<<(std::ostream& os, token_t type) {
|
static inline std::ostream& operator<<(std::ostream& os, token_t type) {
|
||||||
@@ -73,6 +80,12 @@ static inline std::ostream& operator<<(std::ostream& os, token_t type) {
|
|||||||
case token_t::StarEq: return os << "*=";
|
case token_t::StarEq: return os << "*=";
|
||||||
case token_t::SlashEq: return os << "/=";
|
case token_t::SlashEq: return os << "/=";
|
||||||
case token_t::PercentEq: return os << "%=";
|
case token_t::PercentEq: return os << "%=";
|
||||||
|
case token_t::DEq: return os << "==";
|
||||||
|
case token_t::NotEq: return os << "!=";
|
||||||
|
case token_t::LessThan: return os << "<";
|
||||||
|
case token_t::GreaterThan: return os << ">";
|
||||||
|
case token_t::LessEq: return os << "<=";
|
||||||
|
case token_t::GreaterEq: return os << ">=";
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@@ -107,6 +120,12 @@ static inline std::string operator+(const std::string& str, token_t type) {
|
|||||||
case token_t::StarEq: return str + "*=";
|
case token_t::StarEq: return str + "*=";
|
||||||
case token_t::SlashEq: return str + "/=";
|
case token_t::SlashEq: return str + "/=";
|
||||||
case token_t::PercentEq: return str + "%=";
|
case token_t::PercentEq: return str + "%=";
|
||||||
|
case token_t::DEq: return str + "==";
|
||||||
|
case token_t::NotEq: return str + "!=";
|
||||||
|
case token_t::LessThan: return str + "<";
|
||||||
|
case token_t::GreaterThan: return str + ">";
|
||||||
|
case token_t::LessEq: return str + "<=";
|
||||||
|
case token_t::GreaterEq: return str + ">=";
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -82,6 +82,12 @@ std::ostream& operator<<(std::ostream& os, binop_expression_node_t type) {
|
|||||||
case binop_expression_node_t::Mul: return os << '*';
|
case binop_expression_node_t::Mul: return os << '*';
|
||||||
case binop_expression_node_t::Div: return os << '/';
|
case binop_expression_node_t::Div: return os << '/';
|
||||||
case binop_expression_node_t::Mod: return os << '%';
|
case binop_expression_node_t::Mod: return os << '%';
|
||||||
|
case binop_expression_node_t::Equal: return os << "==";
|
||||||
|
case binop_expression_node_t::NotEqual: return os << "!=";
|
||||||
|
case binop_expression_node_t::LessThan: return os << '<';
|
||||||
|
case binop_expression_node_t::GreaterThan: return os << '>';
|
||||||
|
case binop_expression_node_t::LessEqual: return os << "<=";
|
||||||
|
case binop_expression_node_t::GreaterEqual: return os << ">=";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +102,7 @@ bool binop_expression_node::equal(const node& rhsNode) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& var_assign_expression_node::print(std::ostream& os) const {
|
std::ostream& var_assign_expression_node::print(std::ostream& os) const {
|
||||||
return os << *m_lhs << " = " << *m_rhs;
|
return os << '(' << *m_lhs << ' ' << m_compound << "= " << *m_rhs << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool var_assign_expression_node::equal(const node& rhsNode) const {
|
bool var_assign_expression_node::equal(const node& rhsNode) const {
|
||||||
|
|||||||
@@ -127,6 +127,12 @@ token_handle<> lexer::next_token() {
|
|||||||
{ "*=", token_t::StarEq },
|
{ "*=", token_t::StarEq },
|
||||||
{ "/=", token_t::SlashEq },
|
{ "/=", token_t::SlashEq },
|
||||||
{ "%=", token_t::PercentEq },
|
{ "%=", token_t::PercentEq },
|
||||||
|
{ "==", token_t::DEq },
|
||||||
|
{ "!=", token_t::NotEq },
|
||||||
|
{ "<", token_t::LessThan },
|
||||||
|
{ ">", token_t::GreaterThan },
|
||||||
|
{ "<=", token_t::LessEq },
|
||||||
|
{ ">=", token_t::GreaterEq },
|
||||||
};
|
};
|
||||||
|
|
||||||
token_t type = token_t::None;
|
token_t type = token_t::None;
|
||||||
|
|||||||
@@ -271,6 +271,12 @@ ast::expression_node_h parser::parse_expression_rhs(ast::expression_node_h&& ini
|
|||||||
{ token_t::StarEq, rhsop_info::create(ast::binop_expression_node_t::Mul) },
|
{ token_t::StarEq, rhsop_info::create(ast::binop_expression_node_t::Mul) },
|
||||||
{ token_t::SlashEq, rhsop_info::create(ast::binop_expression_node_t::Div) },
|
{ token_t::SlashEq, rhsop_info::create(ast::binop_expression_node_t::Div) },
|
||||||
{ token_t::PercentEq, rhsop_info::create(ast::binop_expression_node_t::Mod) },
|
{ token_t::PercentEq, rhsop_info::create(ast::binop_expression_node_t::Mod) },
|
||||||
|
{ token_t::DEq, rhsop_info::create(ast::binop_expression_node_t::Equal, 10, associativity::Left) },
|
||||||
|
{ token_t::NotEq, rhsop_info::create(ast::binop_expression_node_t::NotEqual, 10, associativity::Left) },
|
||||||
|
{ token_t::LessThan, rhsop_info::create(ast::binop_expression_node_t::LessThan, 9, associativity::Left) },
|
||||||
|
{ token_t::GreaterThan, rhsop_info::create(ast::binop_expression_node_t::GreaterThan, 9, associativity::Left) },
|
||||||
|
{ token_t::LessEq, rhsop_info::create(ast::binop_expression_node_t::LessEqual, 9, associativity::Left) },
|
||||||
|
{ token_t::GreaterEq, rhsop_info::create(ast::binop_expression_node_t::GreaterEqual, 9, associativity::Left) },
|
||||||
};
|
};
|
||||||
|
|
||||||
ast::expression_node_h lhs = std::move(init);
|
ast::expression_node_h lhs = std::move(init);
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
furc::front::parser parser("<TEMP>", "func main() {\n return (x - -y) * z++;\n}");
|
furc::front::parser parser("<TEMP>", "func main() {\n return x = y;\n}");
|
||||||
std::cout << parser.parse() << '\n';
|
std::cout << parser.parse() << '\n';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user