-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
59 lines (54 loc) · 1023 Bytes
/
parser.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
#ifndef _PARSER_H
#define _PARSER_H
#include <sstream>
#include <string>
#include "command_type.h"
using std::istringstream;
using std::string;
class Parser {
public:
/**
Opens the input file and gets ready
to parse it
*/
Parser(istringstream &iss);
/**
Are there more commands in the input ?
*/
bool hasMoreCommands();
/**
Reads the next command from the input
and makes it the current command.
Should be called only if hasMoreCommands()
is true.
Initially there is no current command
*/
void advance();
/**
Returns the type of the current
VM command
*/
TYPE_COMMAND commandType();
/**
Returns the 1st argument
of VM command.
In case of C_ARITHMETIC,
the command itself (add, sub,...)
is returned.
Should not be called if the
current cmd is C_RETURN
*/
string arg1();
/**
Returns the 2nd argument
of VM command.
Should be called only if the
current cmd is C_PUSH, C_POP,
C_FUNCTION, C_CALL
*/
string arg2();
private:
istringstream &m_in;
string m_currentCommand;
};
#endif