-
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 new bool expression methods to core class
- Loading branch information
1 parent
d9aa57c
commit 4ba0a23
Showing
7 changed files
with
155 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "scope.hpp" | ||
#include "env.hpp" | ||
|
||
namespace riddle | ||
{ | ||
class conjunction : public scope | ||
{ | ||
public: | ||
conjunction(std::shared_ptr<scope> parent, std::shared_ptr<env> ctx); | ||
|
||
private: | ||
std::shared_ptr<env> ctx; | ||
}; | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<item> evaluate(scope &scp, env &ctx) = 0; | ||
}; | ||
|
||
class bool_expression final : public expression | ||
{ | ||
public: | ||
bool_expression(const bool_token &l) : l(l) {} | ||
|
||
std::shared_ptr<item> evaluate(scope &scp, env &ctx) override; | ||
|
||
private: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
|
||
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 |
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,6 @@ | ||
#include "conjunction.hpp" | ||
|
||
namespace riddle | ||
{ | ||
conjunction::conjunction(std::shared_ptr<scope> parent, std::shared_ptr<env> ctx) : scope(parent->get_core(), parent), ctx(ctx) {} | ||
} // 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "expression.hpp" | ||
#include "core.hpp" | ||
|
||
namespace riddle | ||
{ | ||
std::shared_ptr<item> bool_expression::evaluate(scope &scp, env &ctx) { return scp.get_core().new_bool(l.value); } | ||
} // namespace riddle |