2022-06-02 16:25:01 +00:00
|
|
|
#pragma once
|
2022-06-08 15:39:51 +00:00
|
|
|
#include "AST/NumberNode.h"
|
2022-07-15 12:28:05 +00:00
|
|
|
#include "AST/SumNode.h"
|
2022-06-08 17:34:16 +00:00
|
|
|
#include "Error.h"
|
2022-06-14 14:29:51 +00:00
|
|
|
#include "Lexer.h"
|
2022-06-16 13:56:10 +00:00
|
|
|
#include "sapphirepch.h"
|
2022-06-02 16:25:01 +00:00
|
|
|
|
2022-06-08 17:34:16 +00:00
|
|
|
/* Parser class for the Sapphire compiler. */
|
2022-06-02 16:25:01 +00:00
|
|
|
class Parser
|
|
|
|
{
|
2022-06-14 14:29:51 +00:00
|
|
|
private:
|
2022-06-16 13:56:10 +00:00
|
|
|
Parser(const TokenStream& tokens);
|
|
|
|
TokenStream tokens;
|
2022-07-15 12:28:05 +00:00
|
|
|
int index = -1;
|
|
|
|
int advance();
|
|
|
|
Token* current_token;
|
2022-06-14 14:29:51 +00:00
|
|
|
|
2022-07-15 12:28:05 +00:00
|
|
|
std::shared_ptr<NumberNode> factor();
|
|
|
|
std::shared_ptr<ExprNode> expr();
|
|
|
|
std::shared_ptr<ExprNode> term();
|
2022-06-14 14:29:51 +00:00
|
|
|
|
|
|
|
public:
|
2022-06-16 13:56:10 +00:00
|
|
|
/* 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();
|
2022-06-02 16:25:01 +00:00
|
|
|
};
|