-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.hpp
More file actions
44 lines (28 loc) · 1.06 KB
/
Copy pathparser.hpp
File metadata and controls
44 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "token.hpp"
#include "ast.hpp"
#include <memory>
#include <vector>
#include <algorithm>
class Parser {
private:
std::vector<Token>& tokens;
size_t currentIndex;
std::vector<TokenType> mathFunctions = {TokenType::SIN, TokenType::COS, TokenType::TAN, TokenType::LOG, TokenType::ABS};
bool current_type_is(TokenType type);
bool current_type_in(std::vector<TokenType> tokenTypes);
TokenValue get_current_value();
Token& current();
void advance();
void eat(TokenType tokenType);
public:
Parser(std::vector<Token>& t) : tokens(t), currentIndex(0) {};
std::unique_ptr<ASTNode> parse_function();
std::unique_ptr<ASTNode> parse_expression();
std::unique_ptr<ASTNode> parse_rest_expression(std::unique_ptr<ASTNode> firstTerm);
std::unique_ptr<ASTNode> parse_term();
std::unique_ptr<ASTNode> parse_rest_term(std::unique_ptr<ASTNode> firstFactor);
std::unique_ptr<ASTNode> parse_unary();
std::unique_ptr<ASTNode> parse_power();
std::unique_ptr<ASTNode> parse_factor();
};