1 /******************************************************************************
3 KPP - The Kinetic PreProcessor
4 Builds simulation code for chemical kinetic systems
6 Copyright (C) 1995-1996 Valeriu Damian and Adrian Sandu
7 Copyright (C) 1997-2005 Adrian Sandu
9 KPP is free software; you can redistribute it and/or modify it under the
10 terms of the GNU General Public License as published by the Free Software
11 Foundation (http://www.gnu.org/copyleft/gpl.html); either version 2 of the
12 License, or (at your option) any later version.
14 KPP is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, consult http://www.gnu.org/copyleft/gpl.html or
21 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
25 Computer Science Department
26 Virginia Polytechnic Institute and State University
28 E-mail: sandu@cs.vt.edu
30 ******************************************************************************/
61 void SemicolonError
();
70 %token JACOBIAN DOUBLE FUNCTION DEFVAR DEFRAD DEFFIX SETVAR SETRAD SETFIX
71 %token HESSIAN STOICMAT STOCHASTIC
72 %token INITVALUES EQUATIONS LUMP INIEQUAL EQNEQUAL EQNCOLON
73 %token LMPCOLON LMPPLUS SPCPLUS SPCEQUAL ATOMDECL CHECK CHECKALL REORDER
74 %token MEX DUMMYINDEX EQNTAGS
75 %token LOOKAT LOOKATALL TRANSPORT TRANSPORTALL MONITOR USES SPARSEDATA
77 %token WRITE_ATM WRITE_SPC WRITE_MAT WRITE_OPT INITIALIZE XGRID YGRID ZGRID
78 %token USE LANGUAGE INTFILE DRIVER RUN INLINE ENDINLINE
79 %token PARAMETER SPCSPC INISPC INIVALUE EQNSPC EQNSIGN EQNCOEF
80 %type
<str
> PARAMETER SPCSPC INISPC INIVALUE EQNSPC EQNSIGN EQNCOEF
81 %token RATE LMPSPC SPCNR ATOMID LKTID MNIID INLCTX INCODE SSPID
82 %type
<str
> RATE LMPSPC SPCNR ATOMID LKTID MNIID INLCTX INCODE SSPID
83 %token EQNLESS EQNTAG EQNGREATER
84 %type
<str
> EQNLESS EQNTAG EQNGREATER
86 %type
<str
> TPTID USEID
87 %type
<str
> rate eqntag
94 section
: JACOBIAN PARAMETER
112 | DUMMYINDEX PARAMETER
113 { CmdDummyindex
( $2 );
121 | STOCHASTIC PARAMETER
122 { CmdStochastic
( $2 );
140 | INITVALUES initvalues
142 | EQUATIONS equations
148 | MONITOR monitorlist
150 | TRANSPORT translist
169 { CmdLanguage
( $2 ); }
170 | INITIALIZE PARAMETER
171 { DefineInitializeNbr
( $2 ); }
173 { DefineXGrid
( $2 ); }
175 { DefineYGrid
( $2 ); }
177 { DefineZGrid
( $2 ); }
178 | INLINE INLCTX inlinecode ENDINLINE
180 AddInlineCode
( $2, InlineBuf
);
184 { ParserErrorMessage
(); }
186 { CmdIntegrator
( $2 ); }
193 | SPARSEDATA PARAMETER
197 semicolon
: semicolon
';'
198 { ScanWarning
("Unnecessary ';'");
202 atomlist
: atomlist atomdef semicolon
205 { ParserErrorMessage
(); }
208 { switch
( crt_section
) {
209 case ATOMDECL
: DeclareAtom
( $1 ); break
;
210 case CHECK
: SetAtomType
( $1, DO_CHECK
); break
;
214 lookatlist
: lookatlist lookatspc semicolon
215 | lookatspc semicolon
217 { ParserErrorMessage
(); }
223 monitorlist
: monitorlist monitorspc semicolon
224 | monitorspc semicolon
226 { ParserErrorMessage
(); }
232 translist
: translist transspc semicolon
235 { ParserErrorMessage
(); }
238 { AddTransport
( $1 );
241 uselist
: uselist usefile semicolon
244 { ParserErrorMessage
(); }
250 setspclist
: setspclist setspcspc semicolon
251 | setspcspc semicolon
253 { ParserErrorMessage
(); }
256 { switch
( crt_section
) {
257 case SETVAR
: SetSpcType
( VAR_SPC
, $1 ); break
;
258 case SETRAD
: SetSpcType
( RAD_SPC
, $1 ); break
;
259 case SETFIX
: SetSpcType
( FIX_SPC
, $1 ); break
;
263 species
: species spc semicolon
266 { ParserErrorMessage
(); }
271 spcname
: SPCSPC SPCEQUAL atoms
272 { switch
( crt_section
) {
273 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
274 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
275 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
280 { switch
( crt_section
) {
281 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
282 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
283 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
287 atoms
: atoms SPCPLUS atom
294 { AddAtom
( $1, "1" );
297 initvalues
: initvalues assignment semicolon
298 | assignment semicolon
300 { ParserErrorMessage
(); }
302 assignment
: INISPC INIEQUAL INIVALUE
303 { AssignInitialValue
( $1, $3 ); }
305 equations
: equations equation semicolon
308 { ParserErrorMessage
();
312 equation
: eqntag lefths righths rate
314 StoreEquationRate
( $4, $1 );
317 | lefths righths rate
319 StoreEquationRate
( $3, " " );
330 eqntag
: EQNLESS EQNTAG EQNGREATER
334 lefths
: expresion EQNEQUAL
337 righths
: expresion EQNCOLON
340 expresion
: expresion EQNSIGN term
341 { ProcessTerm
( eqState
, $2, crt_coef
, crt_term
);
344 { ProcessTerm
( eqState
, $1, crt_coef
, crt_term
);
347 { ProcessTerm
( eqState
, "+", crt_coef
, crt_term
);
350 term
: EQNCOEF EQNSPC
351 { strcpy
( crt_term
, $2 );
352 strcpy
( crt_coef
, $1 );
355 { strcpy
( crt_term
, $1 );
356 strcpy
( crt_coef
, "1" );
359 lumps
: lumps lump semicolon
362 { ParserErrorMessage
(); }
364 lump
: LMPSPC LMPPLUS lump
365 { AddLumpSpecies
( $1 );
367 | LMPSPC LMPCOLON LMPSPC
369 AddLumpSpecies
( $1 );
372 inlinecode
: inlinecode INCODE
374 InlineBuf
= AppendString
( InlineBuf
, $2, &InlineLen
, MAX_INLINE
);
378 InlineBuf
= malloc
( MAX_INLINE
);
379 InlineLen
= MAX_INLINE
;
380 strcpy
( InlineBuf
, $1);
385 void yyerror( char * str
)
389 void ParserErrorMessage
()
393 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
395 if
( crtToken
[0] == ';' ) {
396 ParserError
("Misplaced ';'");
399 switch
( crtTokType
) {
401 ParserError
("Missing ';' after '%s'", crtToken
);
405 ParserError
("Missing ';' or '+' after '%s'", crtToken
);
408 ParserError
("Missing species after '%s'", crtToken
);
411 ParserError
("Missing atom after '%s'", crtToken
);
414 ParserError
("Invalid '=' after '%s'", crtToken
);
418 ParserError
("Missing '=' after '%s'", crtToken
);
421 ParserError
("Missing value after '%s'", crtToken
);
424 ParserError
("Missing ';' after '%s'", crtToken
);
428 ParserError
("Missing '+' or '=' after '%s'", crtToken
);
431 ParserError
("Invalid right hand side of equation");
434 ParserError
("Missing rate after '%s'", crtToken
);
437 ParserError
("Missing coeficient after '%s'", crtToken
);
440 ParserError
("Missing species after '%s'", crtToken
);
443 ParserError
("Missing ';' after '%s'", crtToken
);
447 ParserError
("Missing '+' or ':' or ';' after '%s'", crtToken
);
450 ParserError
("Missing species after '%s'", crtToken
);
453 ParserError
("Missing species after '%s'", crtToken
);
456 ParserError
("Missing inline option after '%s'", crtToken
);
460 ParserError
("Syntax error after '%s'", crtToken
);
465 int Parser
( char * filename
)
470 crt_filename
= filename
;
472 f
= fopen
( crt_filename
, "r" );
474 FatalError
(7,"%s: File not found", crt_filename
);