sapphire/src/Parser.h

29 lines
732 B
C
Raw Normal View History

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"
#include "Error.h"
2022-06-14 14:29:51 +00:00
#include "Lexer.h"
#include "Result.h"
2022-06-16 13:56:10 +00:00
#include "sapphirepch.h"
2022-06-02 16:25:01 +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
Result<ExprNode> factor();
Result<ExprNode> expr();
Result<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
};