36 lines
928 B
C++
36 lines
928 B
C++
#pragma once
|
|
#include "AST/NumberNode.h"
|
|
#include "AST/ProgramNode.h"
|
|
#include "AST/SumNode.h"
|
|
#include "Error.h"
|
|
#include "Lexer.h"
|
|
#include "Result.h"
|
|
#include "sapphirepch.h"
|
|
#include "llvm/IR/Type.h"
|
|
|
|
/* Parser class for the Sapphire compiler. */
|
|
class Parser
|
|
{
|
|
private:
|
|
Parser(const TokenStream& tokens);
|
|
TokenStream tokens;
|
|
int index = -1;
|
|
int advance();
|
|
Token* current_token;
|
|
|
|
std::unordered_map<std::string, llvm::Type*> m_type_map;
|
|
|
|
Result<ExprNode> factor();
|
|
Result<ExprNode> expr();
|
|
Result<ExprNode> term();
|
|
|
|
Result<TopLevelNode> toplevel();
|
|
Result<TopLevelNode> function();
|
|
|
|
public:
|
|
/* Construct a new Parser with the given TokenStream. */
|
|
static std::shared_ptr<Parser> new_parser(const TokenStream& tokens);
|
|
/* Parse the stored TokenStream and return the top-level node of the result Abstract Syntax Tree. */
|
|
std::shared_ptr<ProgramNode> parse();
|
|
};
|