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