-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformer.h
More file actions
40 lines (32 loc) · 847 Bytes
/
Copy pathTransformer.h
File metadata and controls
40 lines (32 loc) · 847 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
32
33
34
35
36
37
38
39
40
#ifndef __TRANSFORMER_H__
#define __TRANSFORMER_H__
#include "Tokenizer.h"
#include <stack>
using namespace std;
namespace ds {
class InfixToPostfixTransformer {
public:
/**
* Helper method to do the transformation.
*/
static stack<Token> transform(const string &code) {
VList<Token> infix = tokenStreamToList(code);
return infixToPostfix(infix);
}
private:
/**
* Convert stream of tokens to a list.
*/
static VList<Token> tokenStreamToList(const string &code) {
Tokenizer lexer(code);
VList<Token> res;
for (Token token = lexer.next();
!token.is_one_of(Token::Kind::End, Token::Kind::Unexpected);
token = lexer.next())
res.addLast(token);
return res;
}
static stack<Token> infixToPostfix(const VList<Token> &infix);
};
} // namespace ds
#endif // __TRANSFORMER_H__