-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add expression and bool_item classes for enhanced expression evaluation
- Loading branch information
1 parent
19fafa0
commit 83dc361
Showing
8 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
#pragma once | ||
|
||
#include "item.hpp" | ||
#include "lexer.hpp" | ||
|
||
namespace riddle | ||
{ | ||
class scope; | ||
|
||
class expression | ||
{ | ||
public: | ||
expression() = default; | ||
virtual ~expression() = default; | ||
|
||
[[nodiscard]] virtual std::shared_ptr<item> evaluate(env &e) const = 0; | ||
/** | ||
* @brief Evaluates the expression within the given scope and environment context. | ||
* | ||
* @param scp The scope in which the expression is evaluated. | ||
* @param ctx The environment context used during evaluation. | ||
* @return std::shared_ptr<item> A shared pointer to the evaluated item. | ||
*/ | ||
[[nodiscard]] virtual std::shared_ptr<item> evaluate(const scope &scp, env &ctx) const = 0; | ||
}; | ||
|
||
class bool_expression : public expression | ||
{ | ||
public: | ||
bool_expression(std::unique_ptr<bool_token> l) noexcept : l(std::move(l)) {} | ||
|
||
[[nodiscard]] std::shared_ptr<item> evaluate(const scope &scp, env &ctx) const override; | ||
|
||
private: | ||
std::unique_ptr<bool_token> l; | ||
}; | ||
} // namespace riddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "expression.hpp" | ||
#include "core.hpp" | ||
|
||
namespace riddle | ||
{ | ||
std::shared_ptr<item> bool_expression::evaluate(const scope &, env &ctx) const { return ctx.get_core().new_bool(l->value); } | ||
} // namespace riddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
#include "item.hpp" | ||
#include "item.hpp" | ||
#include "type.hpp" | ||
|
||
namespace riddle | ||
{ | ||
bool_item::bool_item(bool_type &tp, const utils::lit &l) : item(tp), value(l) {} | ||
} // namespace riddle |