-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
50 lines (44 loc) · 1.07 KB
/
Copy pathparser.h
File metadata and controls
50 lines (44 loc) · 1.07 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
45
46
47
48
49
50
/**
* @author Thadeu <thadeutucci@gmail.com>
* @date 2019
* Parser.
* expr : term ((PLUS | MINUS) term)*
* term : factor ((MUL | DIV) factor)*
* factor : INTEGER | LPAREN expr RPAREN
*/
#pragma once
#include <iostream>
#include <memory>
#include "node.h"
enum TokenType
{
leftParen,
rightParen,
plusMinusOperator,
multDivOperator,
number,
undefined
};
class Parser
{
public:
// Constructor with expression to be parsed.
Parser(const string& expression);
// Init parsing.
std::unique_ptr<ASTNode> parse();
// Put next token in the currentToken variable.
void nextToken();
private:
// Current string to be parsed.
const string& expression;
// Current token to be parsed.
char currentToken;
// Current token index related to expression string.
int currentTokenIdx;
TokenType getCurrentTokenType();
// Prints error message and set error flag to true
void assertTokenType(TokenType);
std::unique_ptr<ASTNode> expr();
std::unique_ptr<ASTNode> term();
std::unique_ptr<ASTNode> factor();
};