feat(furc/AST): add binary and unary operations

This commit is contained in:
2026-08-07 11:23:16 +02:00
parent db485af7f6
commit 2d40b9337c
2 changed files with 62 additions and 0 deletions
+56
View File
@@ -102,6 +102,9 @@ class expr_node : public stmt_node {
public: public:
enum expr_type_e { enum expr_type_e {
Literal, Literal,
BinaryOp,
UnaryOp,
}; };
public: public:
category_e category() const override { return ast_node_cat::Expression; } category_e category() const override { return ast_node_cat::Expression; }
@@ -111,6 +114,59 @@ public:
virtual expr_type_e expr_type() const = 0; virtual expr_type_e expr_type() const = 0;
}; };
struct binary_op_expr_node final : public expr_node {
enum binary_op_type {
Add = 0,
Sub,
Mul,
Div,
Mod,
Shl,
Shr,
BinAnd,
BinOr,
BinXor,
And,
Or,
Equals,
NotEquals,
LessThan,
LessEquals,
GreaterThan,
GreaterEquals,
};
expr_type_e expr_type() const override { return BinaryOp; }
expr_node* lhs;
expr_node* rhs;
binary_op_type type;
};
struct unary_op_expr_node final : public expr_node {
enum unary_op_type {
Positive = 0,
Negative,
PreInc,
PreDec,
PostInc,
PostDec,
BinNot,
Not,
Sizeof,
Pointerof,
Lengthof,
};
expr_type_e expr_type() const override { return UnaryOp; }
expr_node* lhs;
unary_op_type type;
};
class lit_node : public expr_node { class lit_node : public expr_node {
public: public:
enum lit_type_e { enum lit_type_e {
+6
View File
@@ -31,6 +31,8 @@ struct token {
Star, /**< `*` */ Star, /**< `*` */
Slash, /**< `/` */ Slash, /**< `/` */
Percent, /**< `%` */ Percent, /**< `%` */
DblLT, /**< `<<` */
DblGT, /**< `>>` */
Ampersand, /**< `&` */ Ampersand, /**< `&` */
Pipe, /**< `|` */ Pipe, /**< `|` */
Hat, /**< `^` */ Hat, /**< `^` */
@@ -39,6 +41,7 @@ struct token {
DblPlus, /**< `++` */ DblPlus, /**< `++` */
DblMinus, /**< `--` */ DblMinus, /**< `--` */
Tilde, /**< `~` */
ExMark, /**< `!` */ ExMark, /**< `!` */
CatEars, /**< `^^` */ CatEars, /**< `^^` */
@@ -144,6 +147,8 @@ struct token {
case token::Star: return os << "*"; case token::Star: return os << "*";
case token::Slash: return os << "/"; case token::Slash: return os << "/";
case token::Percent: return os << "%"; case token::Percent: return os << "%";
case token::DblLT: return os << "<<";
case token::DblGT: return os << ">>";
case token::Ampersand: return os << "&"; case token::Ampersand: return os << "&";
case token::Pipe: return os << "|"; case token::Pipe: return os << "|";
case token::Hat: return os << "^"; case token::Hat: return os << "^";
@@ -151,6 +156,7 @@ struct token {
case token::DblPipe: return os << "||"; case token::DblPipe: return os << "||";
case token::DblPlus: return os << "++"; case token::DblPlus: return os << "++";
case token::DblMinus: return os << "--"; case token::DblMinus: return os << "--";
case token::Tilde: return os << "~";
case token::ExMark: return os << "!"; case token::ExMark: return os << "!";
case token::CatEars: return os << "^^"; case token::CatEars: return os << "^^";
case token::Equals: return os << "="; case token::Equals: return os << "=";