-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathstmt.c
More file actions
198 lines (181 loc) · 5.42 KB
/
stmt.c
File metadata and controls
198 lines (181 loc) · 5.42 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/** **********************************************************************
** Module: Statement
** This module implements the Statement abstraction. A
** statement is, in effect, a typeless Expression. Due to the
** existence of complex language constructs, however, it often is
** not practical to implement the abstraction thus. For this reason,
** there is a separate module for statements. This abstraction
** supports various looping constructs, if/then/else, switch
** statements, and procedure calls.
** Constants:
** STATEMENT_NULL - the null statement
**
************************************************************************/
/*
* This code was developed with the support of the United States Government,
* and is not subject to copyright.
*
* $Log: stmt.c,v $
* Revision 1.3 1997/01/21 19:19:51 dar
* made C++ compatible
*
* Revision 1.2 1993/10/15 18:48:48 libes
* CADDETC certified
*
* Revision 1.6 1993/02/16 03:27:02 libes
* removed artificial begin/end nesting for improved reconstruction (printing)
* of original Express file
*
* Revision 1.5 1992/08/18 17:13:43 libes
* rm'd extraneous error messages
*
* Revision 1.4 1992/06/08 18:06:57 libes
* prettied up interface to print_objects_when_running
*
* Revision 4.1 90/09/13 15:13:01 clark
* BPR 2.1 alpha
*
*/
#include "express/stmt.h"
Statement STATEMENT_ESCAPE = STATEMENT_NULL;
Statement STATEMENT_SKIP = STATEMENT_NULL;
Statement STMTcreate( int type ) {
Statement s;
s = STMT_new();
SYMBOLset( s );
s->type = type;
return s;
}
/** Initialize the Statement module. */
void STMTinitialize( void ) {
STATEMENT_SKIP = STMTcreate( STMT_SKIP );
STATEMENT_ESCAPE = STMTcreate( STMT_ESCAPE );
}
/**
** \param lhs the left-hand-side of the assignment
** \param rhs the right-hand-side of the assignment
** \return the assignment statement created
**
** Create and return an assignment statement.
*/
Statement ASSIGNcreate( Expression lhs, Expression rhs ) {
Statement s;
s = STMTcreate( STMT_ASSIGN );
s->u.assign = ASSIGN_new();
s->u.assign->lhs = lhs;
s->u.assign->rhs = rhs;
return s;
}
/**
** \param selector expression to case on
** \param cases list of Case_Items
** \return the case statement created
**
** Create and return a case statement.
*/
Statement CASEcreate( Expression selector, Linked_List cases ) {
Statement s;
s = STMTcreate( STMT_CASE );
s->u.Case = CASE_new();
s->u.Case->selector = selector;
s->u.Case->cases = cases;
return( s );
}
/**
** \param statements - list of Statements making up the compound statement
** \return the compound statement created
**
** Create and return a compound statement.
*/
Statement COMP_STMTcreate( Linked_List statements ) {
Statement s;
s = STMTcreate( STMT_COMPOUND );
s->u.compound = COMP_STMT_new();
s->u.compound->statements = statements;
return s;
}
/**
** \param test the condition for the if
** \param then code executed for test == true
** \param otherwise code executed for test == false
** \return the if statement created
**
** Create and return an if statement.
*/
Statement CONDcreate( Expression test, Linked_List then, Linked_List otherwise ) {
Statement s;
s = STMTcreate( STMT_COND );
s->u.cond = COND_new();
s->u.cond->test = test;
s->u.cond->code = then;
s->u.cond->otherwise = otherwise;
return( s );
}
/**
** \param parameters list of actual parameter Expressions
** \return the procedure call generated
**
** Create and return a procedure call statement.
*/
Statement PCALLcreate( Linked_List parameters ) {
Statement s;
s = STMTcreate( STMT_PCALL );
s->u.proc = PCALL_new();
s->u.proc->parameters = parameters;
return s;
}
/**
** \return the loop generated
**
** Create and return a loop statement.
*/
Statement LOOPcreate( Scope scope, Expression while_expr, Expression until_expr, Linked_List statements ) {
Statement s = STMTcreate( STMT_LOOP );
s->u.loop = LOOP_new();
s->u.loop->scope = scope;
s->u.loop->while_expr = while_expr;
s->u.loop->until_expr = until_expr;
s->u.loop->statements = statements;
return( s );
}
Statement ALIAScreate( Scope scope, Variable variable, Linked_List statements ) {
Statement s = STMTcreate( STMT_ALIAS );
s->u.alias = ALIAS_new();
s->u.alias->scope = scope;
s->u.alias->variable = variable;
s->u.alias->statements = statements;
return( s );
}
/**
** \param control controlling expression
** \param start initial value
** \param end terminal value
** \param increment value by which to increment
** \return increment control created
**
** Create and return an increment control as specified.
*/
Scope INCR_CTLcreate( Symbol * control, Expression start,
Expression end, Expression increment ) {
Scope s = SCOPEcreate_tiny( OBJ_INCREMENT );
Expression e = EXPcreate_from_symbol( Type_Attribute, control );
Variable v = VARcreate( e, Type_Number );
DICTdefine( s->symbol_table, control->name,
v, control, OBJ_VARIABLE );
s->u.incr = INCR_new();
s->u.incr->init = start;
s->u.incr->end = end;
s->u.incr->increment = increment;
return s;
}
/**
** \param expression - value to return
** \return the return statement created
Create and return a return statement.
*/
Statement RETcreate( Expression expression ) {
Statement s = STMTcreate( STMT_RETURN );
s->u.ret = RET_new();
s->u.ret->value = expression;
return s;
}