GSC Interpreter
A Turing-complete interpreter developed for a compiler course
|
The Interpreter class evaluates statements and expressions in the GSC. More...
#include <interpreter.hpp>
Public Member Functions | |
void | interpret (const std::vector< std::shared_ptr< Stmt > > &statements) |
Interpret the given statement list and execute them. | |
![]() | |
virtual | ~ExprVisitor ()=default |
![]() | |
virtual | ~StmtVisitor ()=default |
Private Member Functions | |
std::any | evaluate (std::shared_ptr< Expr > expr) |
void | execute (std::shared_ptr< Stmt > stmt) |
void | executeBlock (const std::vector< std::shared_ptr< Stmt > > statements, std::shared_ptr< Environment > environment) |
std::any | visitBinaryExpr (std::shared_ptr< Binary > expr) override |
std::any | visitLogicalExpr (std::shared_ptr< Logical > expr) override |
std::any | visitGroupingExpr (std::shared_ptr< Grouping > expr) override |
std::any | visitLiteralExpr (std::shared_ptr< Literal > expr) override |
std::any | visitUnaryExpr (std::shared_ptr< Unary > expr) override |
std::any | visitAssignExpr (std::shared_ptr< Assign > expr) override |
std::any | visitVariableExpr (std::shared_ptr< Variable > expr) override |
std::any | visitBlockStmt (std::shared_ptr< Block > stmt) override |
std::any | visitExpressionStmt (std::shared_ptr< Expression > stmt) override |
std::any | visitPrintStmt (std::shared_ptr< Print > stmt) override |
std::any | visitIfStmt (std::shared_ptr< If > stmt) override |
std::any | visitWhileStmt (std::shared_ptr< While > stmt) override |
std::any | visitVarStmt (std::shared_ptr< Var > stmt) override |
template<class... N> | |
void | checkNumberOperands (const Token &op, N... operands) |
bool | isTruthy (const std::any &value) const |
bool | isEqual (const std::any &a, const std::any &b) const |
std::string | stringify (const std::any &value) const |
Private Attributes | |
std::shared_ptr< Environment > | environment {new Environment} |
The Interpreter class evaluates statements and expressions in the GSC.
Definition at line 16 of file interpreter.hpp.
|
private |
Definition at line 42 of file interpreter.cpp.
|
private |
Definition at line 17 of file interpreter.cpp.
|
private |
Definition at line 21 of file interpreter.cpp.
|
private |
Definition at line 23 of file interpreter.cpp.
void Interpreter::interpret | ( | const std::vector< std::shared_ptr< Stmt > > & | statements | ) |
Interpret the given statement list and execute them.
statements | A vector of shared pointers to Stmt objects representing |
hadRuntimeError
variable to true. Definition at line 6 of file interpreter.cpp.
|
private |
Definition at line 63 of file interpreter.cpp.
|
private |
Definition at line 49 of file interpreter.cpp.
|
private |
Definition at line 79 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 185 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 120 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements StmtVisitor.
Definition at line 195 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements StmtVisitor.
Definition at line 201 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 95 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements StmtVisitor.
Definition at line 212 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 99 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 172 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements StmtVisitor.
Definition at line 206 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 103 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements ExprVisitor.
Definition at line 191 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements StmtVisitor.
Definition at line 229 of file interpreter.cpp.
|
overrideprivatevirtual |
Implements StmtVisitor.
Definition at line 222 of file interpreter.cpp.
|
private |
Definition at line 18 of file interpreter.hpp.