1 |
mmeineke |
10 |
|
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 |
|
|
|
46 |
|
|
#include <stdlib.h> |
47 |
|
|
#include <stdio.h> |
48 |
|
|
#include <string.h> |
49 |
|
|
#include "node_list.h" |
50 |
|
|
#include "make_nodes.h" |
51 |
|
|
#include "parse_tree.h" |
52 |
chuckv |
131 |
#ifdef IS_MPI |
53 |
|
|
#define __is_lex__ |
54 |
chuckv |
138 |
#include "../headers/mpiBASS.h" |
55 |
chuckv |
118 |
#endif |
56 |
mmeineke |
10 |
|
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 |
|
|
| member { $$ = $1; } |
93 |
|
|
| constraint { $$ = $1; } |
94 |
|
|
| orientation { $$ = $1; } |
95 |
|
|
| position { $$ = $1; } |
96 |
|
|
| start_index { $$ = $1; } |
97 |
|
|
| block { $$ = $1; } |
98 |
|
|
; |
99 |
|
|
|
100 |
|
|
assignment: |
101 |
|
|
IDENTIFIER '=' INTEGER ';' |
102 |
|
|
{ $$ = assign_i( $1, $3 ); } |
103 |
|
|
| IDENTIFIER '=' DOUBLE ';' |
104 |
|
|
{ $$ = assign_d( $1, $3 ); } |
105 |
|
|
| IDENTIFIER '=' IDENTIFIER ';' |
106 |
|
|
{ $$ = assign_s( $1, $3 ); } |
107 |
|
|
| IDENTIFIER '=' QUOTED_STRING ';' |
108 |
|
|
{ $$ = assign_s( $1, $3 ); } |
109 |
|
|
; |
110 |
|
|
|
111 |
|
|
member: |
112 |
|
|
MEMBERS '(' INTEGER ',' INTEGER ')' ';' |
113 |
|
|
{ $$ = members_2( $3, $5 ); } |
114 |
|
|
| MEMBERS '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
115 |
|
|
{ $$ = members_3( $3, $5, $7 ); } |
116 |
|
|
| MEMBERS '(' INTEGER ',' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
117 |
|
|
{ $$ = members_4( $3, $5, $7, $9 ); } |
118 |
|
|
; |
119 |
|
|
|
120 |
|
|
constraint: |
121 |
|
|
CONSTRAINT '(' INTEGER ')' ';' |
122 |
|
|
{ $$ = constraint( (double)$3 ); } |
123 |
|
|
| CONSTRAINT '(' DOUBLE ')' ';' |
124 |
|
|
{ $$ = constraint( $3 ); } |
125 |
|
|
; |
126 |
|
|
|
127 |
|
|
orientation: |
128 |
|
|
ORIENTATION '(' DOUBLE ',' DOUBLE ',' DOUBLE ')' ';' |
129 |
|
|
{ $$ = orientation( $3, $5, $7 ); } |
130 |
|
|
| ORIENTATION '(' INTEGER ',' DOUBLE ',' DOUBLE ')' ';' |
131 |
|
|
{ $$ = orientation( (double)$3, $5, $7 ); } |
132 |
|
|
| ORIENTATION '(' DOUBLE ',' INTEGER ',' DOUBLE ')' ';' |
133 |
|
|
{ $$ = orientation( $3, (double)$5, $7 ); } |
134 |
|
|
| ORIENTATION '(' DOUBLE ',' DOUBLE ',' INTEGER ')' ';' |
135 |
|
|
{ $$ = orientation( $3, $5, (double)$7 ); } |
136 |
|
|
| ORIENTATION '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
137 |
|
|
{ $$ = orientation( (double)$3, (double)$5, (double)$7 ); } |
138 |
|
|
| ORIENTATION '(' DOUBLE ',' INTEGER ',' INTEGER ')' ';' |
139 |
|
|
{ $$ = orientation( $3, (double)$5, (double)$7 ); } |
140 |
|
|
| ORIENTATION '(' INTEGER ',' DOUBLE ',' INTEGER ')' ';' |
141 |
|
|
{ $$ = orientation( (double)$3, $5, (double)$7 ); } |
142 |
|
|
| ORIENTATION '(' INTEGER ',' INTEGER ',' DOUBLE ')' ';' |
143 |
|
|
{ $$ = orientation( (double)$3, (double)$5, $7 ); } |
144 |
|
|
; |
145 |
|
|
|
146 |
|
|
position: |
147 |
|
|
POSITION '(' DOUBLE ',' DOUBLE ',' DOUBLE ')' ';' |
148 |
|
|
{ $$ = position( $3, $5, $7 ); } |
149 |
|
|
| POSITION '(' INTEGER ',' DOUBLE ',' DOUBLE ')' ';' |
150 |
|
|
{ $$ = position( (double)$3, $5, $7 ); } |
151 |
|
|
| POSITION '(' DOUBLE ',' INTEGER ',' DOUBLE ')' ';' |
152 |
|
|
{ $$ = position( $3, (double)$5, $7 ); } |
153 |
|
|
| POSITION '(' DOUBLE ',' DOUBLE ',' INTEGER ')' ';' |
154 |
|
|
{ $$ = position( $3, $5, (double)$7 ); } |
155 |
|
|
| POSITION '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
156 |
|
|
{ $$ = position( (double)$3, (double)$5, (double)$7 ); } |
157 |
|
|
| POSITION '(' DOUBLE ',' INTEGER ',' INTEGER ')' ';' |
158 |
|
|
{ $$ = position( $3, (double)$5, (double)$7 ); } |
159 |
|
|
| POSITION '(' INTEGER ',' DOUBLE ',' INTEGER ')' ';' |
160 |
|
|
{ $$ = position( (double)$3, $5, (double)$7 ); } |
161 |
|
|
| POSITION '(' INTEGER ',' INTEGER ',' DOUBLE ')' ';' |
162 |
|
|
{ $$ = position( (double)$3, (double)$5, $7 ); } |
163 |
|
|
; |
164 |
|
|
|
165 |
|
|
start_index: |
166 |
|
|
START_INDEX int_list ';' |
167 |
|
|
{ $$ = start_index( $2 ); } |
168 |
|
|
; |
169 |
|
|
|
170 |
|
|
block: |
171 |
|
|
molecule_block { $$ = $1; } |
172 |
|
|
| atom_block { $$ = $1; } |
173 |
|
|
| bond_block { $$ = $1; } |
174 |
|
|
| bend_block { $$ = $1; } |
175 |
|
|
| torsion_block { $$ = $1; } |
176 |
|
|
| component_block { $$ = $1; } |
177 |
|
|
; |
178 |
|
|
|
179 |
|
|
molecule_block: |
180 |
|
|
MOLECULE '{' stmt_list '}' |
181 |
|
|
{ $$ = molecule_blk( $3 ); } |
182 |
|
|
; |
183 |
|
|
|
184 |
|
|
atom_block: |
185 |
|
|
ATOM ARRAY_INDEX '{' stmt_list '}' |
186 |
|
|
{ $$ = atom_blk( $2, $4 ); } |
187 |
|
|
; |
188 |
|
|
|
189 |
|
|
bond_block: |
190 |
|
|
BOND ARRAY_INDEX '{' stmt_list '}' |
191 |
|
|
{ $$ = bond_blk( $2, $4 ); } |
192 |
|
|
; |
193 |
|
|
|
194 |
|
|
bend_block: |
195 |
|
|
BEND ARRAY_INDEX '{' stmt_list '}' |
196 |
|
|
{ $$ = bend_blk( $2, $4 ); } |
197 |
|
|
; |
198 |
|
|
|
199 |
|
|
torsion_block: |
200 |
|
|
TORSION ARRAY_INDEX '{' stmt_list '}' |
201 |
|
|
{ $$ = torsion_blk( $2, $4 ); } |
202 |
|
|
; |
203 |
|
|
|
204 |
|
|
component_block: |
205 |
|
|
COMPONENT '{' stmt_list '}' |
206 |
|
|
{ $$ = component_blk( $3 ); } |
207 |
|
|
; |
208 |
|
|
|
209 |
|
|
stmt_list: |
210 |
|
|
stmt { $$ = $1; } |
211 |
|
|
| stmt_list stmt { |
212 |
|
|
$1->next_stmt = $2; |
213 |
|
|
$2->prev_stmt = $1; |
214 |
|
|
$$ = $2; |
215 |
|
|
} |
216 |
|
|
; |
217 |
|
|
|
218 |
|
|
int_list: |
219 |
|
|
'<' INTEGER { $$ = il_node( $2 ); } |
220 |
|
|
| int_list ',' INTEGER { |
221 |
|
|
struct integer_list_tag* temp; |
222 |
|
|
temp = il_node( $3 ); |
223 |
|
|
$1->next = temp; |
224 |
|
|
temp->prev = $1; |
225 |
|
|
$$ = temp; |
226 |
|
|
} |
227 |
|
|
| int_list '>' { $$ = il_top( $1 ); } |
228 |
|
|
; |
229 |
|
|
|
230 |
|
|
%% |
231 |
|
|
|
232 |
|
|
int yyerror( char *err_msg ){ |
233 |
|
|
|
234 |
|
|
fprintf( stderr, "yacc parse error in %s at line %d: %s\n", yyfile_name->my_name, yylineno, err_msg ); |
235 |
chuckv |
131 |
#ifdef IS_MPI |
236 |
chuckv |
118 |
mpiInterfaceExit(); |
237 |
|
|
#endif |
238 |
mmeineke |
10 |
exit(8); |
239 |
|
|
return 0; |
240 |
|
|
} |
241 |
|
|
|
242 |
|
|
void yacc_BASS( char* file_name ){ |
243 |
|
|
|
244 |
|
|
FILE* in_file; |
245 |
|
|
|
246 |
|
|
head_node = (struct node_tag* )malloc( sizeof( node ) ); |
247 |
|
|
|
248 |
|
|
head_node->type = GLOBAL_HEAD; |
249 |
|
|
head_node->index =0; |
250 |
|
|
head_node->next_stmt = NULL; |
251 |
|
|
head_node->prev_stmt = NULL; |
252 |
|
|
head_node->stmt_list = NULL; |
253 |
|
|
|
254 |
|
|
current_node = head_node; |
255 |
|
|
|
256 |
|
|
in_file = fopen( file_name, "r" ); |
257 |
|
|
if( in_file == NULL ){ |
258 |
|
|
fprintf( stderr, "yacc error: couldn't open file =>%s\n", file_name ); |
259 |
|
|
exit(0); |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
yyfile_name = (struct filename_list*)malloc( sizeof( struct filename_list ) ); |
263 |
|
|
yyfile_name->next = NULL; |
264 |
|
|
strcpy( yyfile_name->my_name, file_name ); |
265 |
|
|
change_in_file( in_file ); |
266 |
|
|
|
267 |
|
|
yyparse(); |
268 |
|
|
fclose( in_file ); |
269 |
|
|
kill_lists(); |
270 |
|
|
|
271 |
|
|
pt_me( head_node ); |
272 |
|
|
kill_tree( head_node ); |
273 |
|
|
head_node = NULL; |
274 |
|
|
} |