Parse binop expressions

Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
CHatingPython
2026-05-26 21:06:37 +02:00
committed by CHatingPython
parent e205d67443
commit f130553e20
8 changed files with 194 additions and 30 deletions
+2
View File
@@ -48,6 +48,8 @@ public:
literal_node_t literal_type() const override { return literal_node_t::Integer; }
const handle<front::integer_token>& value() const { return m_value; }
bool operator==(front::integer_token integer) const { return m_value == integer; }
public:
std::ostream& print(std::ostream& os) const override;
protected:
+3
View File
@@ -33,6 +33,9 @@ private:
ast::node_handle<ast::expression_node> parse_expression();
ast::node_handle<ast::literal_node> parse_literal();
ast::expression_node_h parse_expression_primary();
ast::expression_node_h parse_expression_rhs(const ast::expression_node_h& init, std::uint32_t precedence);
ast::function_body_handle parse_body();
private:
token_handle<> next_token();
+24 -1
View File
@@ -26,6 +26,12 @@ enum class token_t {
Colon,
Comma,
Dot,
Plus,
Minus,
Star,
Slash,
Percent,
};
static inline std::ostream& operator<<(std::ostream& os, token_t type) {
@@ -45,7 +51,13 @@ static inline std::ostream& operator<<(std::ostream& os, token_t type) {
case token_t::Colon: return os << "':'";
case token_t::Comma: return os << "','";
case token_t::Dot: return os << "'.'";
case token_t::Plus: return os << "'+'";
case token_t::Minus: return os << "'-'";
case token_t::Star: return os << "'*'";
case token_t::Slash: return os << "'/'";
case token_t::Percent: return os << "'%'";
}
return os;
}
static inline std::string operator+(const std::string& str, token_t type) {
@@ -65,7 +77,13 @@ static inline std::string operator+(const std::string& str, token_t type) {
case token_t::Colon: return str + "':'";
case token_t::Comma: return str + "','";
case token_t::Dot: return str + "'.'";
case token_t::Plus: return str + "'+'";
case token_t::Minus: return str + "'-'";
case token_t::Star: return str + "'*'";
case token_t::Slash: return str + "'/'";
case token_t::Percent: return str + "'%'";
}
return str;
}
enum class keyword_token {
@@ -144,7 +162,12 @@ struct token {
case token_t::Semicolon:
case token_t::Colon:
case token_t::Comma:
case token_t::Dot: return true;
case token_t::Dot:
case token_t::Plus:
case token_t::Minus:
case token_t::Star:
case token_t::Slash:
case token_t::Percent: return true;
}
}
};