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