1 |
|
2 |
/* define some general tokens */ |
3 |
|
4 |
%token MOLECULE ATOM BOND BEND TORSION POSITION MEMBERS MEMBER CONSTRAINT |
5 |
%token COMPONENT START_INDEX DEFINED ORIENTATION ZCONSTRAINT RIGIDBODY |
6 |
|
7 |
/* more advanced tokens */ |
8 |
|
9 |
%union { |
10 |
int i_val; /* integer value */ |
11 |
double d_val; /* double value */ |
12 |
char * s_ptr; /* string pointer */ |
13 |
struct node_tag* node_ptr; /* pointer to the statement node tree */ |
14 |
} |
15 |
|
16 |
%token <i_val> INTEGER |
17 |
%token <i_val> ARRAY_INDEX |
18 |
|
19 |
%token <d_val> DOUBLE |
20 |
|
21 |
%token <s_ptr> IDENTIFIER |
22 |
%token <s_ptr> QUOTED_STRING |
23 |
|
24 |
%type <node_ptr> stmt |
25 |
%type <node_ptr> stmt_list |
26 |
%type <node_ptr> assignment |
27 |
%type <node_ptr> members |
28 |
%type <node_ptr> constraint |
29 |
%type <node_ptr> orientation |
30 |
%type <node_ptr> position |
31 |
%type <node_ptr> block |
32 |
%type <node_ptr> molecule_block |
33 |
%type <node_ptr> atom_block |
34 |
%type <node_ptr> bond_block |
35 |
%type <node_ptr> bend_block |
36 |
%type <node_ptr> torsion_block |
37 |
%type <node_ptr> component_block |
38 |
%type <node_ptr> zconstraint_block |
39 |
%type <node_ptr> rigidbody_block |
40 |
%type <node_ptr> member_block |
41 |
|
42 |
|
43 |
%{ |
44 |
#include <stdlib.h> |
45 |
#include <stdio.h> |
46 |
#include <string.h> |
47 |
|
48 |
#include "node_list.h" |
49 |
#include "make_nodes.h" |
50 |
#include "parse_tree.h" |
51 |
#include "simError.h" |
52 |
#ifdef IS_MPI |
53 |
#define __is_lex__ |
54 |
#include "mpiBASS.h" |
55 |
#endif |
56 |
|
57 |
extern int yylineno; |
58 |
|
59 |
struct filename_list{ |
60 |
char my_name[300]; |
61 |
struct filename_list* next; |
62 |
}; |
63 |
extern struct filename_list* yyfile_name; |
64 |
|
65 |
extern void change_in_file( FILE* in_file ); |
66 |
extern void yacc_model( char* file_name ); |
67 |
extern void kill_lists(void); |
68 |
|
69 |
/* top of the node list */ |
70 |
|
71 |
struct node_tag* head_node; |
72 |
struct node_tag* current_node; |
73 |
|
74 |
%} |
75 |
|
76 |
%% |
77 |
|
78 |
program: |
79 |
commands |
80 |
; |
81 |
|
82 |
commands: /* NULL */ |
83 |
| commands stmt { |
84 |
current_node->next_stmt = $2; |
85 |
$2->prev_stmt = current_node; |
86 |
current_node = $2; |
87 |
} |
88 |
; |
89 |
|
90 |
stmt: |
91 |
assignment { $$ = $1; } |
92 |
| members { $$ = $1; } |
93 |
| constraint { $$ = $1; } |
94 |
| orientation { $$ = $1; } |
95 |
| position { $$ = $1; } |
96 |
| block { $$ = $1; } |
97 |
; |
98 |
|
99 |
assignment: |
100 |
IDENTIFIER '=' INTEGER ';' |
101 |
{ $$ = assign_i( $1, $3 ); } |
102 |
| IDENTIFIER '=' DOUBLE ';' |
103 |
{ $$ = assign_d( $1, $3 ); } |
104 |
| IDENTIFIER '=' IDENTIFIER ';' |
105 |
{ $$ = assign_s( $1, $3 ); } |
106 |
| IDENTIFIER '=' QUOTED_STRING ';' |
107 |
{ $$ = assign_s( $1, $3 ); } |
108 |
; |
109 |
|
110 |
members: |
111 |
MEMBERS '(' INTEGER ',' INTEGER ')' ';' |
112 |
{ $$ = members_2( $3, $5 ); } |
113 |
| MEMBERS '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
114 |
{ $$ = members_3( $3, $5, $7 ); } |
115 |
| MEMBERS '(' INTEGER ',' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
116 |
{ $$ = members_4( $3, $5, $7, $9 ); } |
117 |
; |
118 |
|
119 |
constraint: |
120 |
CONSTRAINT '(' INTEGER ')' ';' |
121 |
{ $$ = constraint( (double)$3 ); } |
122 |
| CONSTRAINT '(' DOUBLE ')' ';' |
123 |
{ $$ = constraint( $3 ); } |
124 |
; |
125 |
|
126 |
orientation: |
127 |
ORIENTATION '(' DOUBLE ',' DOUBLE ',' DOUBLE ')' ';' |
128 |
{ $$ = orientation( $3, $5, $7 ); } |
129 |
| ORIENTATION '(' INTEGER ',' DOUBLE ',' DOUBLE ')' ';' |
130 |
{ $$ = orientation( (double)$3, $5, $7 ); } |
131 |
| ORIENTATION '(' DOUBLE ',' INTEGER ',' DOUBLE ')' ';' |
132 |
{ $$ = orientation( $3, (double)$5, $7 ); } |
133 |
| ORIENTATION '(' DOUBLE ',' DOUBLE ',' INTEGER ')' ';' |
134 |
{ $$ = orientation( $3, $5, (double)$7 ); } |
135 |
| ORIENTATION '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
136 |
{ $$ = orientation( (double)$3, (double)$5, (double)$7 ); } |
137 |
| ORIENTATION '(' DOUBLE ',' INTEGER ',' INTEGER ')' ';' |
138 |
{ $$ = orientation( $3, (double)$5, (double)$7 ); } |
139 |
| ORIENTATION '(' INTEGER ',' DOUBLE ',' INTEGER ')' ';' |
140 |
{ $$ = orientation( (double)$3, $5, (double)$7 ); } |
141 |
| ORIENTATION '(' INTEGER ',' INTEGER ',' DOUBLE ')' ';' |
142 |
{ $$ = orientation( (double)$3, (double)$5, $7 ); } |
143 |
; |
144 |
|
145 |
position: |
146 |
POSITION '(' DOUBLE ',' DOUBLE ',' DOUBLE ')' ';' |
147 |
{ $$ = position( $3, $5, $7 ); } |
148 |
| POSITION '(' INTEGER ',' DOUBLE ',' DOUBLE ')' ';' |
149 |
{ $$ = position( (double)$3, $5, $7 ); } |
150 |
| POSITION '(' DOUBLE ',' INTEGER ',' DOUBLE ')' ';' |
151 |
{ $$ = position( $3, (double)$5, $7 ); } |
152 |
| POSITION '(' DOUBLE ',' DOUBLE ',' INTEGER ')' ';' |
153 |
{ $$ = position( $3, $5, (double)$7 ); } |
154 |
| POSITION '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
155 |
{ $$ = position( (double)$3, (double)$5, (double)$7 ); } |
156 |
| POSITION '(' DOUBLE ',' INTEGER ',' INTEGER ')' ';' |
157 |
{ $$ = position( $3, (double)$5, (double)$7 ); } |
158 |
| POSITION '(' INTEGER ',' DOUBLE ',' INTEGER ')' ';' |
159 |
{ $$ = position( (double)$3, $5, (double)$7 ); } |
160 |
| POSITION '(' INTEGER ',' INTEGER ',' DOUBLE ')' ';' |
161 |
{ $$ = position( (double)$3, (double)$5, $7 ); } |
162 |
; |
163 |
|
164 |
block: |
165 |
molecule_block { $$ = $1; } |
166 |
| atom_block { $$ = $1; } |
167 |
| bond_block { $$ = $1; } |
168 |
| bend_block { $$ = $1; } |
169 |
| torsion_block { $$ = $1; } |
170 |
| zconstraint_block { $$ = $1; } |
171 |
| rigidbody_block { $$ = $1; } |
172 |
| member_block { $$ = $1; } |
173 |
| component_block { $$ = $1; } |
174 |
; |
175 |
|
176 |
molecule_block: |
177 |
MOLECULE '{' stmt_list '}' |
178 |
{ $$ = molecule_blk( $3 ); } |
179 |
; |
180 |
|
181 |
atom_block: |
182 |
ATOM ARRAY_INDEX '{' stmt_list '}' |
183 |
{ $$ = atom_blk( $2, $4 ); } |
184 |
; |
185 |
|
186 |
bond_block: |
187 |
BOND ARRAY_INDEX '{' stmt_list '}' |
188 |
{ $$ = bond_blk( $2, $4 ); } |
189 |
; |
190 |
|
191 |
bend_block: |
192 |
BEND ARRAY_INDEX '{' stmt_list '}' |
193 |
{ $$ = bend_blk( $2, $4 ); } |
194 |
; |
195 |
|
196 |
torsion_block: |
197 |
TORSION ARRAY_INDEX '{' stmt_list '}' |
198 |
{ $$ = torsion_blk( $2, $4 ); } |
199 |
; |
200 |
|
201 |
zconstraint_block: |
202 |
ZCONSTRAINT ARRAY_INDEX '{' stmt_list '}' |
203 |
{ $$ = zconstraint_blk( $2, $4 ); } |
204 |
; |
205 |
|
206 |
rigidbody_block: |
207 |
RIGIDBODY ARRAY_INDEX '{' stmt_list '}' |
208 |
{ $$ = rigidbody_blk( $2, $4 ); } |
209 |
; |
210 |
|
211 |
member_block: |
212 |
MEMBER ARRAY_INDEX '{' stmt_list '}' |
213 |
{ $$ = member_blk( $2, $4 ); } |
214 |
; |
215 |
|
216 |
component_block: |
217 |
COMPONENT '{' stmt_list '}' |
218 |
{ $$ = component_blk( $3 ); } |
219 |
; |
220 |
|
221 |
stmt_list: |
222 |
stmt { $$ = $1; } |
223 |
| stmt_list stmt { |
224 |
$1->next_stmt = $2; |
225 |
$2->prev_stmt = $1; |
226 |
$$ = $2; |
227 |
} |
228 |
; |
229 |
|
230 |
%% |
231 |
|
232 |
int yyerror( char *err_msg ){ |
233 |
|
234 |
sprintf( painCave.errMsg, "yacc parse error in %s at line %d: %s\n", |
235 |
yyfile_name->my_name, yylineno, err_msg ); |
236 |
painCave.isFatal = 1; |
237 |
simError(); |
238 |
return 0; |
239 |
} |
240 |
|
241 |
void yacc_BASS( char* file_name ){ |
242 |
|
243 |
FILE* in_file; |
244 |
|
245 |
head_node = (struct node_tag* )malloc( sizeof( node ) ); |
246 |
|
247 |
head_node->type = GLOBAL_HEAD; |
248 |
head_node->index =0; |
249 |
head_node->next_stmt = NULL; |
250 |
head_node->prev_stmt = NULL; |
251 |
head_node->stmt_list = NULL; |
252 |
|
253 |
current_node = head_node; |
254 |
|
255 |
in_file = fopen( file_name, "r" ); |
256 |
if( in_file == NULL ){ |
257 |
sprintf( painCave.errMsg, "yacc error: couldn't open file =>%s\n", |
258 |
file_name ); |
259 |
painCave.isFatal = 1; |
260 |
simError(); |
261 |
} |
262 |
|
263 |
yyfile_name = |
264 |
(struct filename_list*)malloc( sizeof( struct filename_list ) ); |
265 |
yyfile_name->next = NULL; |
266 |
strcpy( yyfile_name->my_name, file_name ); |
267 |
change_in_file( in_file ); |
268 |
|
269 |
yyparse(); |
270 |
|
271 |
#ifdef IS_MPI |
272 |
strcpy( checkPointMsg, "yyParse successful." ); |
273 |
MPIcheckPoint(); |
274 |
painCave.isEventLoop = 1; |
275 |
#endif // is_mpi |
276 |
|
277 |
fclose( in_file ); |
278 |
kill_lists(); |
279 |
|
280 |
pt_me( head_node ); |
281 |
|
282 |
#ifdef IS_MPI |
283 |
painCave.isEventLoop = 0; |
284 |
#endif // is_mpi |
285 |
|
286 |
kill_tree( head_node ); |
287 |
head_node = NULL; |
288 |
} |