| 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 |
mmeineke |
157 |
#include "../headers/simError.h" |
| 53 |
chuckv |
131 |
#ifdef IS_MPI |
| 54 |
|
|
#define __is_lex__ |
| 55 |
chuckv |
138 |
#include "../headers/mpiBASS.h" |
| 56 |
chuckv |
118 |
#endif |
| 57 |
mmeineke |
10 |
|
| 58 |
|
|
extern int yylineno; |
| 59 |
|
|
|
| 60 |
|
|
struct filename_list{ |
| 61 |
|
|
char my_name[300]; |
| 62 |
|
|
struct filename_list* next; |
| 63 |
|
|
}; |
| 64 |
|
|
extern struct filename_list* yyfile_name; |
| 65 |
|
|
|
| 66 |
|
|
extern void change_in_file( FILE* in_file ); |
| 67 |
|
|
extern void yacc_model( char* file_name ); |
| 68 |
|
|
extern void kill_lists(void); |
| 69 |
|
|
|
| 70 |
|
|
/* top of the node list */ |
| 71 |
|
|
|
| 72 |
|
|
struct node_tag* head_node; |
| 73 |
|
|
struct node_tag* current_node; |
| 74 |
|
|
|
| 75 |
|
|
%} |
| 76 |
|
|
|
| 77 |
|
|
%% |
| 78 |
|
|
|
| 79 |
|
|
program: |
| 80 |
|
|
commands |
| 81 |
|
|
; |
| 82 |
|
|
|
| 83 |
|
|
commands: /* NULL */ |
| 84 |
|
|
| commands stmt { |
| 85 |
|
|
current_node->next_stmt = $2; |
| 86 |
|
|
$2->prev_stmt = current_node; |
| 87 |
|
|
current_node = $2; |
| 88 |
|
|
} |
| 89 |
|
|
; |
| 90 |
|
|
|
| 91 |
|
|
stmt: |
| 92 |
|
|
assignment { $$ = $1; } |
| 93 |
|
|
| member { $$ = $1; } |
| 94 |
|
|
| constraint { $$ = $1; } |
| 95 |
|
|
| orientation { $$ = $1; } |
| 96 |
|
|
| position { $$ = $1; } |
| 97 |
|
|
| start_index { $$ = $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 |
|
|
member: |
| 113 |
|
|
MEMBERS '(' INTEGER ',' INTEGER ')' ';' |
| 114 |
|
|
{ $$ = members_2( $3, $5 ); } |
| 115 |
|
|
| MEMBERS '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
| 116 |
|
|
{ $$ = members_3( $3, $5, $7 ); } |
| 117 |
|
|
| MEMBERS '(' INTEGER ',' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
| 118 |
|
|
{ $$ = members_4( $3, $5, $7, $9 ); } |
| 119 |
|
|
; |
| 120 |
|
|
|
| 121 |
|
|
constraint: |
| 122 |
|
|
CONSTRAINT '(' INTEGER ')' ';' |
| 123 |
|
|
{ $$ = constraint( (double)$3 ); } |
| 124 |
|
|
| CONSTRAINT '(' DOUBLE ')' ';' |
| 125 |
|
|
{ $$ = constraint( $3 ); } |
| 126 |
|
|
; |
| 127 |
|
|
|
| 128 |
|
|
orientation: |
| 129 |
|
|
ORIENTATION '(' DOUBLE ',' DOUBLE ',' DOUBLE ')' ';' |
| 130 |
|
|
{ $$ = orientation( $3, $5, $7 ); } |
| 131 |
|
|
| ORIENTATION '(' INTEGER ',' DOUBLE ',' DOUBLE ')' ';' |
| 132 |
|
|
{ $$ = orientation( (double)$3, $5, $7 ); } |
| 133 |
|
|
| ORIENTATION '(' DOUBLE ',' INTEGER ',' DOUBLE ')' ';' |
| 134 |
|
|
{ $$ = orientation( $3, (double)$5, $7 ); } |
| 135 |
|
|
| ORIENTATION '(' DOUBLE ',' DOUBLE ',' INTEGER ')' ';' |
| 136 |
|
|
{ $$ = orientation( $3, $5, (double)$7 ); } |
| 137 |
|
|
| ORIENTATION '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
| 138 |
|
|
{ $$ = orientation( (double)$3, (double)$5, (double)$7 ); } |
| 139 |
|
|
| ORIENTATION '(' DOUBLE ',' INTEGER ',' INTEGER ')' ';' |
| 140 |
|
|
{ $$ = orientation( $3, (double)$5, (double)$7 ); } |
| 141 |
|
|
| ORIENTATION '(' INTEGER ',' DOUBLE ',' INTEGER ')' ';' |
| 142 |
|
|
{ $$ = orientation( (double)$3, $5, (double)$7 ); } |
| 143 |
|
|
| ORIENTATION '(' INTEGER ',' INTEGER ',' DOUBLE ')' ';' |
| 144 |
|
|
{ $$ = orientation( (double)$3, (double)$5, $7 ); } |
| 145 |
|
|
; |
| 146 |
|
|
|
| 147 |
|
|
position: |
| 148 |
|
|
POSITION '(' DOUBLE ',' DOUBLE ',' DOUBLE ')' ';' |
| 149 |
|
|
{ $$ = position( $3, $5, $7 ); } |
| 150 |
|
|
| POSITION '(' INTEGER ',' DOUBLE ',' DOUBLE ')' ';' |
| 151 |
|
|
{ $$ = position( (double)$3, $5, $7 ); } |
| 152 |
|
|
| POSITION '(' DOUBLE ',' INTEGER ',' DOUBLE ')' ';' |
| 153 |
|
|
{ $$ = position( $3, (double)$5, $7 ); } |
| 154 |
|
|
| POSITION '(' DOUBLE ',' DOUBLE ',' INTEGER ')' ';' |
| 155 |
|
|
{ $$ = position( $3, $5, (double)$7 ); } |
| 156 |
|
|
| POSITION '(' INTEGER ',' INTEGER ',' INTEGER ')' ';' |
| 157 |
|
|
{ $$ = position( (double)$3, (double)$5, (double)$7 ); } |
| 158 |
|
|
| POSITION '(' DOUBLE ',' INTEGER ',' INTEGER ')' ';' |
| 159 |
|
|
{ $$ = position( $3, (double)$5, (double)$7 ); } |
| 160 |
|
|
| POSITION '(' INTEGER ',' DOUBLE ',' INTEGER ')' ';' |
| 161 |
|
|
{ $$ = position( (double)$3, $5, (double)$7 ); } |
| 162 |
|
|
| POSITION '(' INTEGER ',' INTEGER ',' DOUBLE ')' ';' |
| 163 |
|
|
{ $$ = position( (double)$3, (double)$5, $7 ); } |
| 164 |
|
|
; |
| 165 |
|
|
|
| 166 |
|
|
start_index: |
| 167 |
|
|
START_INDEX int_list ';' |
| 168 |
|
|
{ $$ = start_index( $2 ); } |
| 169 |
|
|
; |
| 170 |
|
|
|
| 171 |
|
|
block: |
| 172 |
|
|
molecule_block { $$ = $1; } |
| 173 |
|
|
| atom_block { $$ = $1; } |
| 174 |
|
|
| bond_block { $$ = $1; } |
| 175 |
|
|
| bend_block { $$ = $1; } |
| 176 |
|
|
| torsion_block { $$ = $1; } |
| 177 |
|
|
| component_block { $$ = $1; } |
| 178 |
|
|
; |
| 179 |
|
|
|
| 180 |
|
|
molecule_block: |
| 181 |
|
|
MOLECULE '{' stmt_list '}' |
| 182 |
|
|
{ $$ = molecule_blk( $3 ); } |
| 183 |
|
|
; |
| 184 |
|
|
|
| 185 |
|
|
atom_block: |
| 186 |
|
|
ATOM ARRAY_INDEX '{' stmt_list '}' |
| 187 |
|
|
{ $$ = atom_blk( $2, $4 ); } |
| 188 |
|
|
; |
| 189 |
|
|
|
| 190 |
|
|
bond_block: |
| 191 |
|
|
BOND ARRAY_INDEX '{' stmt_list '}' |
| 192 |
|
|
{ $$ = bond_blk( $2, $4 ); } |
| 193 |
|
|
; |
| 194 |
|
|
|
| 195 |
|
|
bend_block: |
| 196 |
|
|
BEND ARRAY_INDEX '{' stmt_list '}' |
| 197 |
|
|
{ $$ = bend_blk( $2, $4 ); } |
| 198 |
|
|
; |
| 199 |
|
|
|
| 200 |
|
|
torsion_block: |
| 201 |
|
|
TORSION ARRAY_INDEX '{' stmt_list '}' |
| 202 |
|
|
{ $$ = torsion_blk( $2, $4 ); } |
| 203 |
|
|
; |
| 204 |
|
|
|
| 205 |
|
|
component_block: |
| 206 |
|
|
COMPONENT '{' stmt_list '}' |
| 207 |
|
|
{ $$ = component_blk( $3 ); } |
| 208 |
|
|
; |
| 209 |
|
|
|
| 210 |
|
|
stmt_list: |
| 211 |
|
|
stmt { $$ = $1; } |
| 212 |
|
|
| stmt_list stmt { |
| 213 |
|
|
$1->next_stmt = $2; |
| 214 |
|
|
$2->prev_stmt = $1; |
| 215 |
|
|
$$ = $2; |
| 216 |
|
|
} |
| 217 |
|
|
; |
| 218 |
|
|
|
| 219 |
|
|
int_list: |
| 220 |
|
|
'<' INTEGER { $$ = il_node( $2 ); } |
| 221 |
|
|
| int_list ',' INTEGER { |
| 222 |
|
|
struct integer_list_tag* temp; |
| 223 |
|
|
temp = il_node( $3 ); |
| 224 |
|
|
$1->next = temp; |
| 225 |
|
|
temp->prev = $1; |
| 226 |
|
|
$$ = temp; |
| 227 |
|
|
} |
| 228 |
|
|
| int_list '>' { $$ = il_top( $1 ); } |
| 229 |
|
|
; |
| 230 |
|
|
|
| 231 |
|
|
%% |
| 232 |
|
|
|
| 233 |
|
|
int yyerror( char *err_msg ){ |
| 234 |
|
|
|
| 235 |
mmeineke |
157 |
sprintf( painCave.errMsg, "yacc parse error in %s at line %d: %s\n", |
| 236 |
|
|
yyfile_name->my_name, yylineno, err_msg ); |
| 237 |
|
|
painCave.isFatal = 1; |
| 238 |
|
|
simError(); |
| 239 |
mmeineke |
10 |
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 |
mmeineke |
157 |
sprintf( painCave.errMsg, "yacc error: couldn't open file =>%s\n", |
| 259 |
|
|
file_name ); |
| 260 |
|
|
painCave.isFatal = 1; |
| 261 |
|
|
simError(); |
| 262 |
mmeineke |
10 |
} |
| 263 |
|
|
|
| 264 |
mmeineke |
157 |
yyfile_name = |
| 265 |
|
|
(struct filename_list*)malloc( sizeof( struct filename_list ) ); |
| 266 |
mmeineke |
10 |
yyfile_name->next = NULL; |
| 267 |
|
|
strcpy( yyfile_name->my_name, file_name ); |
| 268 |
|
|
change_in_file( in_file ); |
| 269 |
|
|
|
| 270 |
|
|
yyparse(); |
| 271 |
mmeineke |
163 |
|
| 272 |
|
|
#ifdef IS_MPI |
| 273 |
|
|
strcpy( checkPointMsg, "yyParse successful." ); |
| 274 |
|
|
MPIcheckPoint(); |
| 275 |
|
|
painCave.isEventLoop = 1; |
| 276 |
|
|
#endif // is_mpi |
| 277 |
|
|
|
| 278 |
mmeineke |
10 |
fclose( in_file ); |
| 279 |
|
|
kill_lists(); |
| 280 |
|
|
|
| 281 |
|
|
pt_me( head_node ); |
| 282 |
|
|
kill_tree( head_node ); |
| 283 |
|
|
head_node = NULL; |
| 284 |
|
|
} |