ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/BASSyacc.y
Revision: 1099
Committed: Mon Apr 12 20:33:12 2004 UTC (20 years, 2 months ago) by gezelter
File size: 4893 byte(s)
Log Message:
Changes for RigidBody dynamics

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 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 %token <s_ptr> LIST_STRING
24
25 %type <node_ptr> stmt
26 %type <node_ptr> stmt_list
27 %type <node_ptr> assignment
28 %type <node_ptr> members
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> zconstraint_block
40 %type <node_ptr> rigidbody_block
41
42
43 %{
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47
48 #include "node_list.h"
49 #include "make_nodes.h"
50 #include "parse_tree.h"
51 #include "simError.h"
52 #ifdef IS_MPI
53 #define __is_lex__
54 #include "mpiBASS.h"
55 #endif
56
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 | members { $$ = $1; }
93 | constraint { $$ = $1; }
94 | orientation { $$ = $1; }
95 | position { $$ = $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 members:
111 MEMBERS LIST_STRING ';'
112 { $$ = members( $2 ); }
113 ;
114
115 constraint:
116 CONSTRAINT LIST_STRING ';'
117 { $$ = constraint( $2 ); }
118 ;
119
120 orientation:
121 ORIENTATION LIST_STRING ';'
122 { $$ = orientation( $2 ); }
123 ;
124
125 position:
126 POSITION LIST_STRING ';'
127 { $$ = position( $2 ); }
128 ;
129
130 block:
131 molecule_block { $$ = $1; }
132 | atom_block { $$ = $1; }
133 | bond_block { $$ = $1; }
134 | bend_block { $$ = $1; }
135 | torsion_block { $$ = $1; }
136 | zconstraint_block { $$ = $1; }
137 | rigidbody_block { $$ = $1; }
138 | component_block { $$ = $1; }
139 ;
140
141 molecule_block:
142 MOLECULE '{' stmt_list '}'
143 { $$ = molecule_blk( $3 ); }
144 ;
145
146 atom_block:
147 ATOM ARRAY_INDEX '{' stmt_list '}'
148 { $$ = atom_blk( $2, $4 ); }
149 ;
150
151 bond_block:
152 BOND ARRAY_INDEX '{' stmt_list '}'
153 { $$ = bond_blk( $2, $4 ); }
154 ;
155
156 bend_block:
157 BEND ARRAY_INDEX '{' stmt_list '}'
158 { $$ = bend_blk( $2, $4 ); }
159 ;
160
161 torsion_block:
162 TORSION ARRAY_INDEX '{' stmt_list '}'
163 { $$ = torsion_blk( $2, $4 ); }
164 ;
165
166 zconstraint_block:
167 ZCONSTRAINT ARRAY_INDEX '{' stmt_list '}'
168 { $$ = zconstraint_blk( $2, $4 ); }
169 ;
170
171 rigidbody_block:
172 RIGIDBODY ARRAY_INDEX '{' stmt_list '}'
173 { $$ = rigidbody_blk( $2, $4 ); }
174 ;
175
176 component_block:
177 COMPONENT '{' stmt_list '}'
178 { $$ = component_blk( $3 ); }
179 ;
180
181 stmt_list:
182 stmt { $$ = $1; }
183 | stmt_list stmt {
184 $1->next_stmt = $2;
185 $2->prev_stmt = $1;
186 $$ = $2;
187 }
188 ;
189
190 %%
191
192 extern int yyerror( char *err_msg ){
193
194 sprintf( painCave.errMsg, "OOPSE parse error in %s at line %d: %s\n",
195 yyfile_name->my_name, yylineno + 1, err_msg );
196 painCave.isFatal = 1;
197 simError();
198 return 0;
199 }
200
201 void yacc_BASS( char* file_name ){
202
203 FILE* in_file;
204
205 head_node = (struct node_tag* )malloc( sizeof( node ) );
206
207 head_node->type = GLOBAL_HEAD;
208 head_node->index =0;
209 head_node->next_stmt = NULL;
210 head_node->prev_stmt = NULL;
211 head_node->stmt_list = NULL;
212
213 current_node = head_node;
214
215 in_file = fopen( file_name, "r" );
216 if( in_file == NULL ){
217 sprintf( painCave.errMsg, "yacc error: couldn't open file =>%s\n",
218 file_name );
219 painCave.isFatal = 1;
220 simError();
221 }
222
223 yyfile_name =
224 (struct filename_list*)malloc( sizeof( struct filename_list ) );
225 yyfile_name->next = NULL;
226 strcpy( yyfile_name->my_name, file_name );
227 change_in_file( in_file );
228
229 yyparse();
230
231 #ifdef IS_MPI
232 strcpy( checkPointMsg, "yyParse successful." );
233 MPIcheckPoint();
234 painCave.isEventLoop = 1;
235 #endif // is_mpi
236
237 fclose( in_file );
238 kill_lists();
239
240 pt_me( head_node );
241
242 #ifdef IS_MPI
243 painCave.isEventLoop = 0;
244 #endif // is_mpi
245
246 kill_tree( head_node );
247 head_node = NULL;
248 }