-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtoken.h
67 lines (41 loc) · 1.21 KB
/
token.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef PRATT_TOKEN_H
#define PRATT_TOKEN_H
#include "parser.h"
#include "production.h"
namespace pratt {
namespace token {
class Token {
public:
virtual pratt::production::Production* Nud(pratt::Parser*);
virtual pratt::production::Production* Led(pratt::Parser*, pratt::production::Production*);
virtual int Lbp();
};
class Integer : public Token {
public:
int Value;
Integer(int);
virtual pratt::production::Production* Nud(pratt::Parser*);
};
template<class P, int lbp> // Result production, Precedence
class InfixOp : public Token {
public:
virtual pratt::production::Production*
Led(pratt::Parser* p, pratt::production::Production* lhs) {
return new P(lhs, p->Expression(this->Lbp()));
}
virtual int Lbp() {
return lbp;
}
};
typedef InfixOp<pratt::production::Mul, pratt::BP_Multiplicative> Mul;
typedef InfixOp<pratt::production::Div, pratt::BP_Multiplicative> Div;
class Add : public InfixOp<pratt::production::Add, pratt::BP_Additive> {
public:
virtual pratt::production::Production* Nud(pratt::Parser*);
};
class Sub : public InfixOp<pratt::production::Sub, pratt::BP_Additive> {
public:
virtual pratt::production::Production* Nud(pratt::Parser*);
};
}} // namespace pratt::token
#endif