diff --git a/CMakeLists.txt b/CMakeLists.txt index 9df12bb..96bc99e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(RiDDLe VERSION 0.2.0 LANGUAGES C CXX) include(CTest) enable_testing() -add_library(RiDDLe src/scope.cpp src/env.cpp src/core.cpp src/type.cpp src/constructor.cpp src/method.cpp src/item.cpp) +add_library(RiDDLe src/scope.cpp src/env.cpp src/core.cpp src/type.cpp src/constructor.cpp src/method.cpp src/conjunction.cpp src/item.cpp src/expression.cpp) target_include_directories(RiDDLe PUBLIC $) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/include/conjunction.hpp b/include/conjunction.hpp new file mode 100644 index 0000000..f5d093a --- /dev/null +++ b/include/conjunction.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "scope.hpp" +#include "env.hpp" + +namespace riddle +{ + class conjunction : public scope + { + public: + conjunction(std::shared_ptr parent, std::shared_ptr ctx); + + private: + std::shared_ptr ctx; + }; +} // namespace riddle diff --git a/include/core.hpp b/include/core.hpp index 84e8044..2d7c208 100644 --- a/include/core.hpp +++ b/include/core.hpp @@ -11,6 +11,20 @@ namespace riddle core(); virtual ~core() = default; + /** + * @brief Create a new bool expression. + * + * @return std::shared_ptr The bool expression. + */ + virtual std::shared_ptr new_bool() = 0; + /** + * @brief Create a new bool expression with a value. + * + * @param value The value of the bool expression. + * @return std::shared_ptr The bool expression. + */ + virtual std::shared_ptr new_bool(bool value) = 0; + /** * @brief Get a field by name. * diff --git a/include/expression.hpp b/include/expression.hpp new file mode 100644 index 0000000..8a1209f --- /dev/null +++ b/include/expression.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "item.hpp" +#include "lexer.hpp" + +namespace riddle +{ + class scope; + + class expression + { + public: + expression() = default; + virtual ~expression() = default; + + virtual std::shared_ptr evaluate(scope &scp, env &ctx) = 0; + }; + + class bool_expression final : public expression + { + public: + bool_expression(const bool_token &l) : l(l) {} + + std::shared_ptr evaluate(scope &scp, env &ctx) override; + + private: + bool_token l; + }; +} // namespace riddle diff --git a/include/lexer.hpp b/include/lexer.hpp new file mode 100644 index 0000000..485111e --- /dev/null +++ b/include/lexer.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include + +namespace riddle +{ + enum symbol + { + BOOL_ID, // `bool` + INT_ID, // `int` + REAL_ID, // `real` + TIME_ID, // `time` + STRING_ID, // `string` + TYPEDEF_ID, // `typedef` + ENUM_ID, // `enum` + CLASS_ID, // `class` + GOAL_ID, // `goal` + FACT_ID, // `fact` + PREDICATE_ID, // `predicate` + NEW_ID, // `new` + OR_ID, // `or` + FOR_ID, // `for` + THIS_ID, // `this` + VOID_ID, // `void` + RETURN_ID, // `return` + DOT_ID, // `.` + COMMA_ID, // `,` + COLON_ID, // `:` + SEMICOLON_ID, // `;` + LPAREN_ID, // `(` + RPAREN_ID, // `)` + LBRACKET_ID, // `[` + RBRACKET_ID, // `]` + LBRACE_ID, // `{` + RBRACE_ID, // `}` + PLUS_ID, // `+` + MINUS_ID, // `-` + STAR_ID, // `*` + SLASH_ID, // `/` + AMP_ID, // `&` + BAR_ID, // `|` + EQ_ID, // `=` + GT_ID, // `>` + LT_ID, // `<` + BANG_ID, // `!` + EQEQ_ID, // `==` + LTEQ_ID, // `<=` + GTEQ_ID, // `>=` + BANGEQ_ID, // `!=` + IMPLICATION_ID, // `->` + CARET_ID, // `^` + ID_ID, // (`a`..`z`|`A`..`Z`|`_`) (`a`..`z`|`A`..`Z`|`0`..`9`|`_`)* + BoolLiteral_ID, // `true` | `false` + IntLiteral_ID, // [0-9]+ + RealLiteral_ID, // [0-9]+ `.` [0-9]+)? | `.` [0-9]+ + StringLiteral_ID, // `" . . ."` + EOF_ID + }; + + class token + { + public: + token(const symbol &sym, const size_t &start_line, const size_t &start_pos, const size_t &end_line, const size_t &end_pos) : sym(sym), start_line(start_line), start_pos(start_pos), end_line(end_line), end_pos(end_pos) {} + virtual ~token() = default; + + const symbol sym; + const size_t start_line, start_pos, end_line, end_pos; + }; + + class bool_token final : public token + { + public: + bool_token(const bool &value, const size_t &start_line, const size_t &start_pos, const size_t &end_line, const size_t &end_pos) : token(BOOL_ID, start_line, start_pos, end_line, end_pos), value(value) {} + virtual ~bool_token() = default; + + const bool value; + }; + + class lexer + { + }; +} // namespace riddle diff --git a/src/conjunction.cpp b/src/conjunction.cpp new file mode 100644 index 0000000..7f5fdb7 --- /dev/null +++ b/src/conjunction.cpp @@ -0,0 +1,6 @@ +#include "conjunction.hpp" + +namespace riddle +{ + conjunction::conjunction(std::shared_ptr parent, std::shared_ptr ctx) : scope(parent->get_core(), parent), ctx(ctx) {} +} // namespace riddle \ No newline at end of file diff --git a/src/expression.cpp b/src/expression.cpp new file mode 100644 index 0000000..119ed59 --- /dev/null +++ b/src/expression.cpp @@ -0,0 +1,7 @@ +#include "expression.hpp" +#include "core.hpp" + +namespace riddle +{ + std::shared_ptr bool_expression::evaluate(scope &scp, env &ctx) { return scp.get_core().new_bool(l.value); } +} // namespace riddle