29 lines
732 B
C++
29 lines
732 B
C++
#pragma once
|
|
#include "AST/NumberNode.h"
|
|
#include "AST/SumNode.h"
|
|
#include "Error.h"
|
|
#include "Lexer.h"
|
|
#include "Result.h"
|
|
#include "sapphirepch.h"
|
|
|
|
/* Parser class for the Sapphire compiler. */
|
|
class Parser
|
|
{
|
|
private:
|
|
Parser(const TokenStream& tokens);
|
|
TokenStream tokens;
|
|
int index = -1;
|
|
int advance();
|
|
Token* current_token;
|
|
|
|
Result<ExprNode> factor();
|
|
Result<ExprNode> expr();
|
|
Result<ExprNode> term();
|
|
|
|
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<ASTNode> parse();
|
|
};
|