diff --git a/furc/include/furc/ast/expression.hpp b/furc/include/furc/ast/expression.hpp index e0fe825..2f58df6 100644 --- a/furc/include/furc/ast/expression.hpp +++ b/furc/include/furc/ast/expression.hpp @@ -88,6 +88,13 @@ enum class binop_expression_node_t { Mul, Div, Mod, + + Equal, + NotEqual, + LessThan, + GreaterThan, + LessEqual, + GreaterEqual, }; class binop_expression_node : public expression_node { diff --git a/furc/include/furc/front/token.hpp b/furc/include/furc/front/token.hpp index 87f7bda..3cf2f8b 100644 --- a/furc/include/furc/front/token.hpp +++ b/furc/include/furc/front/token.hpp @@ -41,6 +41,13 @@ enum class token_t { StarEq, SlashEq, PercentEq, + + DEq, + NotEq, + LessThan, + GreaterThan, + LessEq, + GreaterEq, }; 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::SlashEq: 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; } @@ -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::SlashEq: 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; } diff --git a/furc/src/ast.cpp b/furc/src/ast.cpp index 32a74be..600ccbd 100644 --- a/furc/src/ast.cpp +++ b/furc/src/ast.cpp @@ -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::Div: 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 { - return os << *m_lhs << " = " << *m_rhs; + return os << '(' << *m_lhs << ' ' << m_compound << "= " << *m_rhs << ')'; } bool var_assign_expression_node::equal(const node& rhsNode) const { diff --git a/furc/src/front/lexer.cpp b/furc/src/front/lexer.cpp index fd931c6..c09c59a 100644 --- a/furc/src/front/lexer.cpp +++ b/furc/src/front/lexer.cpp @@ -127,6 +127,12 @@ token_handle<> lexer::next_token() { { "*=", token_t::StarEq }, { "/=", token_t::SlashEq }, { "%=", 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; diff --git a/furc/src/front/parser.cpp b/furc/src/front/parser.cpp index c44505e..cd69149 100644 --- a/furc/src/front/parser.cpp +++ b/furc/src/front/parser.cpp @@ -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::SlashEq, rhsop_info::create(ast::binop_expression_node_t::Div) }, { 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); diff --git a/furc/src/main.cpp b/furc/src/main.cpp index 7228623..0aab92e 100644 --- a/furc/src/main.cpp +++ b/furc/src/main.cpp @@ -5,7 +5,7 @@ #include int main(void) { - furc::front::parser parser("", "func main() {\n return (x - -y) * z++;\n}"); + furc::front::parser parser("", "func main() {\n return x = y;\n}"); std::cout << parser.parse() << '\n'; return 0;