-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsetree.h
145 lines (100 loc) · 3.58 KB
/
parsetree.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef PARSETREE_H
#define PARSETREE_H
#include "y.tab.h"
typedef enum parseType parseType;
enum parseType {
program,
body,
varSections,
varSection,
varDeclarations,
varDeclaration,
procedures,
procedure,
procedureHeader,
functionHeader,
paramList,
copyParameter,
referenceParameter,
instructionSequence,
instruction,
assignment,
varCall,
arrayCall,
conditionalInstruction,
elseSection,
whileLoop,
repeatLoop,
forLoop,
positiveAdvancement,
negativeAdvancement,
emptyAdvancement,
procedureCall,
paramListCall,
returnStatement,
condition,
negation,
expression,
value
};
char *stringFromParseType(parseType type);
typedef enum valueType valueType;
enum valueType {
string,
number,
token
};
typedef struct parseToken parseToken;
struct parseToken {
parseType type;
YYSTYPE *values;
valueType *valueTypes;
int nVal;
parseToken **subNodes;
int nNodes;
};
void freeToken(parseToken *token);
parseToken *createProgram(char *name, parseToken *varSections,
parseToken *procedures, parseToken *body);
parseToken *createBody(parseToken *instructionSequence, char *name);
parseToken *createVarSections(parseToken *prevVarSections,
parseToken *varSection);
parseToken *createVarSection(parseToken *varDeclarations);
parseToken *createVarDeclarations(parseToken *prevVarDeclarations,
parseToken *varDeclaration);
parseToken *createVarDeclaration( char *name, const int *arraySize);
parseToken *createProcedures(parseToken *prevProcedures, parseToken *procedure);
parseToken *createProcedure(parseToken *header, char *name, parseToken *paramList,
parseToken *varSection, parseToken *instructionSequence,
char *confirmIdentifier);
parseToken *createProcedureHeader( void );
parseToken *createFunctionHeader( void );
parseToken *createParamList(parseToken *prevParamList, parseToken *parameter);
parseToken *createCopyParameter(parseToken *varDeclaration);
parseToken *createReferenceParameter(parseToken *varDeclaration);
parseToken *createInstructionSequence(parseToken *newInstruction,
parseToken *prevInstructionSequence);
parseToken *createAssignment(parseToken *var, parseToken *expr);
parseToken *createVarCall(char *name);
parseToken *createArrayCall(char *name, parseToken *index);
parseToken *createConditional(parseToken *cond,
parseToken *instructions, parseToken *elseSection);
parseToken *createElseSection(parseToken *instructions);
parseToken *createWhileLoop(parseToken *condition, parseToken *instrutions);
parseToken *createRepeatLoop(parseToken *instructions, parseToken *condition);
parseToken *createForLoop(parseToken *assignment,
parseToken *target, parseToken *iteration, parseToken *instructions);
parseToken *createPositiveAdvancement(int num);
parseToken *createNegativeAdvancement(int num);
parseToken *createEmptyAdvancement( void );
parseToken *createProcedureCall(char *name, parseToken *paramList);
parseToken *createParamListCall(parseToken *prevParams, parseToken *param);
parseToken *createReturnStatement(parseToken *returnedExpression);
parseToken *createCondition(parseToken *firstOp, int opCode, parseToken *secondOp);
parseToken *createBrackets(parseToken *internal);
parseToken *createNegation(parseToken *internal);
parseToken *createBinaryExpression(parseToken *firstOp, int opCode, parseToken *secondOp);
parseToken *createUnaryExpression(parseToken *value);
parseToken *createValue(int num);
parseToken *createValueByCall(parseToken *call);
#endif //PARSETREE_H