Skip to content

Commit

Permalink
fix #12
Browse files Browse the repository at this point in the history
  • Loading branch information
michael.burzan committed Jan 7, 2025
1 parent b59f6a6 commit 140b658
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/ast/ConstantDeclarationNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
class ConstantDeclarationNode : public AstNode, public std::enable_shared_from_this<ConstantDeclarationNode> {
public:
~ConstantDeclarationNode() = default;
ConstantDeclarationNode(const std::string& var_name, const AstPtr& expression);
ConstantDeclarationNode(const std::string& var_name, const AstPtr& type, const AstPtr& expression);
void accept(const std::shared_ptr<Visitor>& v) override;

private:
std::string _var_name;
AstPtr _type;
AstPtr _expression;
};

Expand Down
3 changes: 2 additions & 1 deletion include/ast/VariableDeclarationNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class VariableDeclarationNode : public AstNode, public std::enable_shared_from_this<VariableDeclarationNode> {
public:
~VariableDeclarationNode() = default;
VariableDeclarationNode(const std::string& var_name, const AstPtr& expression);
VariableDeclarationNode(const std::string& var_name, const AstPtr& type, const AstPtr& expression);
void accept(const std::shared_ptr<Visitor>& v) override;
auto var_name() const -> const std::string& {
return _var_name;
Expand All @@ -19,6 +19,7 @@ class VariableDeclarationNode : public AstNode, public std::enable_shared_from_t

private:
std::string _var_name;
AstPtr _type;
AstPtr _expression;
};

Expand Down
4 changes: 2 additions & 2 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ auto Parser::parse_variable_declaration() -> ParserResult {
if (!accept(TokenKind::SEMICOLON)) {
}
_context.pop();
return {std::make_shared<VariableDeclarationNode>(var_name, expression.result())};
return {std::make_shared<VariableDeclarationNode>(var_name, type.result(), expression.result())};
}
return Epsilon;
}
Expand Down Expand Up @@ -242,7 +242,7 @@ auto Parser::parse_constant_declaration() -> ParserResult {
if (!accept(TokenKind::SEMICOLON)) {
}
_context.pop();
return {std::make_shared<ConstantDeclarationNode>(var_name, expression.result())};
return {std::make_shared<ConstantDeclarationNode>(var_name, type.result(), expression.result())};
}
return Epsilon;
}
Expand Down
5 changes: 3 additions & 2 deletions src/ast/ConstantDeclarationNode.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "ConstantDeclarationNode.h"
#include "Visitor.h"

ConstantDeclarationNode::ConstantDeclarationNode(const std::string& var_name, const AstPtr& expression)
: _var_name(var_name), _expression(expression) {
ConstantDeclarationNode::ConstantDeclarationNode(const std::string& var_name, const AstPtr& type,
const AstPtr& expression)
: _var_name(var_name), _type(type), _expression(expression) {
// Constructor implementation
}

Expand Down
6 changes: 4 additions & 2 deletions src/ast/VariableDeclarationNode.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "AstNode.h"
#include "Visitor.h"
#include "VariableDeclarationNode.h"

VariableDeclarationNode::VariableDeclarationNode(const std::string& var_name, const AstPtr& expression)
: _var_name(var_name), _expression(expression) {
VariableDeclarationNode::VariableDeclarationNode(const std::string& var_name, const AstPtr& type,
const AstPtr& expression)
: _var_name(var_name), _type(type), _expression(expression) {
// Constructor implementation
}

Expand Down

0 comments on commit 140b658

Please sign in to comment.