ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/BASS_parse/BASS.y
Revision: 118
Committed: Wed Sep 25 22:51:14 2002 UTC (22 years, 10 months ago) by chuckv
File size: 6566 byte(s)
Log Message:
begin the pain that is MPI.

abandon all hope ye who check out this branch..

P.S. we've added consistent BASS error checking

File Contents

# Content
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
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 #ifdef MPI
53 #include "../headers/mpiInterface.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 | start_index { $$ = $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 member:
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 start_index:
165 START_INDEX int_list ';'
166 { $$ = start_index( $2 ); }
167 ;
168
169 block:
170 molecule_block { $$ = $1; }
171 | atom_block { $$ = $1; }
172 | bond_block { $$ = $1; }
173 | bend_block { $$ = $1; }
174 | torsion_block { $$ = $1; }
175 | component_block { $$ = $1; }
176 ;
177
178 molecule_block:
179 MOLECULE '{' stmt_list '}'
180 { $$ = molecule_blk( $3 ); }
181 ;
182
183 atom_block:
184 ATOM ARRAY_INDEX '{' stmt_list '}'
185 { $$ = atom_blk( $2, $4 ); }
186 ;
187
188 bond_block:
189 BOND ARRAY_INDEX '{' stmt_list '}'
190 { $$ = bond_blk( $2, $4 ); }
191 ;
192
193 bend_block:
194 BEND ARRAY_INDEX '{' stmt_list '}'
195 { $$ = bend_blk( $2, $4 ); }
196 ;
197
198 torsion_block:
199 TORSION ARRAY_INDEX '{' stmt_list '}'
200 { $$ = torsion_blk( $2, $4 ); }
201 ;
202
203 component_block:
204 COMPONENT '{' stmt_list '}'
205 { $$ = component_blk( $3 ); }
206 ;
207
208 stmt_list:
209 stmt { $$ = $1; }
210 | stmt_list stmt {
211 $1->next_stmt = $2;
212 $2->prev_stmt = $1;
213 $$ = $2;
214 }
215 ;
216
217 int_list:
218 '<' INTEGER { $$ = il_node( $2 ); }
219 | int_list ',' INTEGER {
220 struct integer_list_tag* temp;
221 temp = il_node( $3 );
222 $1->next = temp;
223 temp->prev = $1;
224 $$ = temp;
225 }
226 | int_list '>' { $$ = il_top( $1 ); }
227 ;
228
229 %%
230
231 int yyerror( char *err_msg ){
232
233 fprintf( stderr, "yacc parse error in %s at line %d: %s\n", yyfile_name->my_name, yylineno, err_msg );
234 #ifdef MPI
235 mpiInterfaceExit();
236 #endif
237 exit(8);
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 fprintf( stderr, "yacc error: couldn't open file =>%s\n", file_name );
258 exit(0);
259 }
260
261 yyfile_name = (struct filename_list*)malloc( sizeof( struct filename_list ) );
262 yyfile_name->next = NULL;
263 strcpy( yyfile_name->my_name, file_name );
264 change_in_file( in_file );
265
266 yyparse();
267 fclose( in_file );
268 kill_lists();
269
270 pt_me( head_node );
271 kill_tree( head_node );
272 head_node = NULL;
273 }