9 int yyerror(list
<Cmd
> & cmd_list
, const char *s
);
11 /* define global variable needed by yyparse here*/
15 void ClearCmd
(Cmd
&cmd
);
31 %parse
-param
{ list
<Cmd
> & cmd_list
}
33 %token
<sval
> ASSIGN KEYWORD BOOL_PARAMETER REAL_PARAMETER INT_PARAMETER STRING_PARAMETER
34 %token
<ival
> INT_NUMBER
35 %token
<dval
> REAL_NUMBER
37 %token
<ival
> BLANK COMMENT BAD_WORD
40 %type
<dval
> real_expr
54 : ASSIGN STRING
'=' real_expr
57 printf
("line %d: --YACC assign --\n",yylineno
-1);
61 arg.arg_value.dval
=$4;
62 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
64 cmd.lineno
= yylineno
-1;
65 cmd_list.push_back
(cmd
);
71 printf
("line %d: --YACC command %s--\n",yylineno
-1,$1);
74 cmd.lineno
= yylineno
-1;
75 cmd_list.push_back
(cmd
);
81 printf
("line %d: --YACC command %s--\n",yylineno
-1,$1);
84 cmd.lineno
= yylineno
-1;
85 cmd_list.push_back
(cmd
);
94 real_expr: REAL_NUMBER
100 list
<Cmd
>::iterator pcmd
;
101 for
(pcmd
=cmd_list.begin
();pcmd
!=cmd_list.end
();pcmd
++)
102 if
(!strcmp
(pcmd
->KeyWord.c_str
(),"ASSIGN"))
104 ARG_MAP
::iterator parg
;
105 if
((parg
=pcmd
->arg_map.find
($1))!=pcmd
->arg_map.end
())
107 assign_value
=parg
->second.arg_value.dval
;
114 return
yyerror(cmd_list
, $1);
118 | real_expr
'+' real_expr
120 | real_expr
'-' real_expr
122 | real_expr
'*' real_expr
124 | real_expr
'/' real_expr
126 |
'-' real_expr %prec
'*'
130 int_expr
: INT_NUMBER
134 | int_expr
'+' int_expr
136 | int_expr
'-' int_expr
138 | int_expr
'*' int_expr
140 | int_expr
'/' int_expr
142 |
'-' int_expr %prec
'*'
147 : parameter REAL_PARAMETER
'=' real_expr
150 printf
("--PARAMETER ASSIGN REAL--\n");
154 arg.arg_value.dval
=$4;
155 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
157 | REAL_PARAMETER
'=' real_expr
160 printf
("--PARAMETER ASSIGN REAL--\n");
164 arg.arg_value.dval
=$3;
165 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
167 | parameter INT_PARAMETER
'=' int_expr
170 printf
("--PARAMETER ASSIGN INT--\n");
173 arg.arg_type
=INTERGER
;
174 arg.arg_value.ival
=$4;
175 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
177 | INT_PARAMETER
'=' int_expr
180 printf
("--PARAMETER ASSIGN INT--\n");
183 arg.arg_type
=INTERGER
;
184 arg.arg_value.ival
=$3;
185 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
187 | parameter STRING_PARAMETER
'=' STRING
190 printf
("--PARAMETER ASSIGN STRING--\n");
194 strcpy
(arg.arg_value.sval
,$4);
195 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
197 | STRING_PARAMETER
'=' STRING
200 printf
("--PARAMETER ASSIGN STRING--\n");
204 strcpy
(arg.arg_value.sval
,$3);
205 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
207 | parameter STRING_PARAMETER
210 printf
("--PARAMETER ASSIGN EMPTY STRING--\n");
212 // in this case, assign an empty string
215 strcpy
(arg.arg_value.sval
,"");
216 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
221 printf
("--PARAMETER ASSIGN EMPTY STRING--\n");
223 // in this case, assign an empty string
226 strcpy
(arg.arg_value.sval
,"");
227 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
229 | parameter BOOL_PARAMETER
'=' BOOL
232 printf
("--PARAMETER ASSIGN BOOL--\n");
235 arg.arg_type
=BOOLVAR
;
236 arg.arg_value.bval
=$4;
237 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
239 | BOOL_PARAMETER
'=' BOOL
242 printf
("--PARAMETER ASSIGN BOOL--\n");
245 arg.arg_type
=BOOLVAR
;
246 arg.arg_value.bval
=$3;
247 cmd.arg_map.insert
(pair
<const string, Arg
>(arg.arg_label
,arg
));
255 int yyerror(list
<Cmd
> & cmd_list
, const char *s
)
257 printf
("\nYACC report: line %d unrecognized word(s), %s.\n",yylineno
,s
);
261 void ClearCmd
(Cmd
&cmd
)