#ifndef __DRAGON_LISP_DRIVER_H__ #define __DRAGON_LISP_DRIVER_H__ #include #include #include "DragonLispScanner.h" #include "DragonLisp.tab.hh" #include "AST.h" namespace DragonLisp { class DLDriver { private: DLParser* parser = nullptr; DLScanner* scanner = nullptr; DragonLisp::location location; Context* context = nullptr; public: DLDriver() = default; virtual ~DLDriver(); int parse(const std::string& f); int parse(std::istream& in, const std::string& s = "stream input"); void error(const DLParser::location_type& l, const std::string& m); void error(const std::string& m); void execute(std::variant, std::shared_ptr> ast); // Identifier AST static std::shared_ptr constructLValueAST(std::string name); // ArrayRef AST static std::shared_ptr constructLValueAST(std::string name, std::shared_ptr index); // FuncDef AST static std::shared_ptr constructFuncDefAST(std::string name, std::vector args, std::vector> body); // Literal AST static std::shared_ptr constructLiteralAST(bool value); static std::shared_ptr constructLiteralAST(std::int64_t value); static std::shared_ptr constructLiteralAST(double value); static std::shared_ptr constructLiteralAST(std::string value); // BinaryExpr AST static std::shared_ptr constructBinaryExprAST(std::shared_ptr lhs, std::shared_ptr rhs, Token op); // UnaryExpr AST static std::shared_ptr constructUnaryExprAST(std::shared_ptr expr, Token op); // ListExpr AST static std::shared_ptr constructListExprAST(std::vector> exprs, Token op); // If AST static std::shared_ptr constructIfAST(std::shared_ptr cond, std::shared_ptr then, std::shared_ptr els); // Func Call AST static std::shared_ptr constructFuncCallAST(std::string name, std::vector> args); // Var Op AST static std::shared_ptr constructVarOpAST(std::string name, std::shared_ptr value, Token op); // LVal Op AST static std::shared_ptr constructLValOpAST(std::shared_ptr lval, std::shared_ptr value, Token op); // Return AST static std::shared_ptr constructReturnAST(std::shared_ptr value); static std::shared_ptr constructReturnAST(std::shared_ptr value, std::string name); // Loop AST static std::shared_ptr constructLoopAST(std::vector> body); static std::shared_ptr constructLoopAST(std::string id, std::shared_ptr from, std::shared_ptr to, std::vector> body); static std::shared_ptr constructLoopAST(std::string id, std::shared_ptr to, std::vector> body); }; } // end namespace DragonLisp #endif // __DRAGON_LISP_DRIVER_H__