-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cpp
More file actions
31 lines (27 loc) · 877 Bytes
/
Token.cpp
File metadata and controls
31 lines (27 loc) · 877 Bytes
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
#include "Token.h"
bool Token::isOperator()
{
return (*this == tok_add || *this == tok_sub ||
*this == tok_mod ||
*this == tok_mul || *this == tok_div ||
*this == tok_and || *this == tok_or);
}
int Token::getPrecedence()
{
if /**/ (*this == tok_and || *this == tok_or) return prec_high;
else if (*this == tok_mul || *this == tok_div ||
*this == tok_mod) return prec_normal;
else if (*this == tok_add || *this == tok_sub) return prec_low;
return 0;
}
string Token::print() // DEBUG
{
if /**/ (*this == tok_add) return "+";
else if (*this == tok_sub) return "-";
else if (*this == tok_mul) return "*";
else if (*this == tok_div) return "/";
else if (*this == tok_mod) return "%";
else if (*this == tok_and) return "&&";
else if (*this == tok_or ) return "||";
return "unkown operator: \"" + *this + "\"";
}