Skip to content

Commit df516f8

Browse files
feat(parser): implement constructors for expression and variable nodes
1 parent b1cefd1 commit df516f8

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

wheel_parser/nodes.cxx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#include <vector>
22
#include "wheel_parser/ast/nodes.hxx"
3+
#include "wheel_parser/ast/symbol.hxx"
34

45
using wheel_parser::ast::Node;
56
using wheel_parser::ast::StatementNode;
67
using wheel_parser::ast::FunctionDeclaration;
78
using wheel_parser::ast::BlockStatement;
89
using wheel_parser::ast::NodeKind;
10+
using wheel_parser::ast::ExpressionNode;
11+
using wheel_parser::ast::LiteralExpression;
12+
using wheel_parser::ast::IdentifierExpression;
13+
using wheel_parser::ast::VariableDeclaration;
914

1015
Node::Node(NodeKind node_kind,
1116
const Token* token) noexcept : node_kind(node_kind), token(token) {}
@@ -21,6 +26,25 @@ FunctionDeclaration::FunctionDeclaration(const Token *token,
2126
func_name(func_name), func_params(std::move(func_params)), func_body(func_body) {}
2227

2328
BlockStatement::BlockStatement(const Token *token,
24-
std::vector<StatementNode*> statements) noexcept :
25-
StatementNode(NodeKind::BlockStatement, token),
26-
statements(std::move(statements)){}
29+
std::vector<StatementNode*> statements) noexcept :
30+
StatementNode(NodeKind::BlockStatement, token),
31+
statements(std::move(statements)) {}
32+
33+
ExpressionNode::ExpressionNode(NodeKind node_kind,
34+
const Token *token) noexcept : Node(node_kind, token) {}
35+
36+
LiteralExpression::LiteralExpression(const Token *token) noexcept :
37+
ExpressionNode(NodeKind::LiteralExpression, token) {}
38+
39+
IdentifierExpression::IdentifierExpression(const Token *token,
40+
SymbolID identifier_id) noexcept :
41+
ExpressionNode(NodeKind::IdentifierExpression, token),
42+
identifier_id(identifier_id) {}
43+
44+
45+
VariableDeclaration::VariableDeclaration(const Token *token,
46+
SymbolID var_type, SymbolID var_name,
47+
ExpressionNode *initializer) noexcept :
48+
StatementNode(NodeKind::VariableDeclaration, token),
49+
var_type(var_type), var_name(var_name),
50+
initializer(initializer) {}

0 commit comments

Comments
 (0)