-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.h
More file actions
104 lines (83 loc) · 1.96 KB
/
Copy pathexecute.h
File metadata and controls
104 lines (83 loc) · 1.96 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef _COMPILER_H_
#define _COMPILER_H_
#include <string>
#include <vector>
extern int mem[1000];
extern int next_available;
extern std::vector<int> inputs;
extern int next_input;
enum ArithmeticOperatorType
{
OPERATOR_NONE = 123,
OPERATOR_PLUS,
OPERATOR_MINUS,
OPERATOR_MULT,
OPERATOR_DIV
};
enum ConditionalOperatorType
{
CONDITION_GREATER = 345,
CONDITION_LESS,
CONDITION_NOTEQUAL
};
enum InstructionType
{
NOOP = 1000,
IN,
OUT,
ASSIGN,
CJMP,
JMP
};
struct InstructionNode
{
InstructionType type;
union
{
struct
{
int lhs_loc;
int op1_loc;
int op2_loc;
/*
* If op == OPERATOR_NONE then only opernd1 is meaningful.
* Otherwise both opernds are meaningful
*/
ArithmeticOperatorType op;
} assign_inst;
struct
{
int var_loc;
} input_inst;
struct
{
int var_loc;
} output_inst;
struct
{
ConditionalOperatorType condition_op;
int op1_loc;
int op2_loc;
struct InstructionNode *target;
} cjmp_inst;
struct
{
struct InstructionNode *target;
} jmp_inst;
};
struct InstructionNode *next; // next statement in the list or NULL
};
void debug(const char *format, ...);
//---------------------------------------------------------
// You should write the following function:
struct InstructionNode *parse_Generate_Intermediate_Representation();
/*
NOTE:
You need to write a function with the above signature. This function
is supposed to parse the input program and generate an intermediate
representation for it. The output of this function is passed to the
execute_program function in main().
Write your code in a separate file and include this header file in
your code.
*/
#endif /* _COMPILER_H_ */