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