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
200 semicolon
: semicolon
';'
201 { ScanWarning
("Unnecessary ';'");
205 atomlist
: atomlist atomdef semicolon
208 { ParserErrorMessage
(); }
211 { switch
( crt_section
) {
212 case ATOMDECL
: DeclareAtom
( $1 ); break
;
213 case CHECK
: SetAtomType
( $1, DO_CHECK
); break
;
217 lookatlist
: lookatlist lookatspc semicolon
218 | lookatspc semicolon
220 { ParserErrorMessage
(); }
226 monitorlist
: monitorlist monitorspc semicolon
227 | monitorspc semicolon
229 { ParserErrorMessage
(); }
235 translist
: translist transspc semicolon
238 { ParserErrorMessage
(); }
241 { AddTransport
( $1 );
244 uselist
: uselist usefile semicolon
247 { ParserErrorMessage
(); }
253 setspclist
: setspclist setspcspc semicolon
254 | setspcspc semicolon
256 { ParserErrorMessage
(); }
259 { switch
( crt_section
) {
260 case SETVAR
: SetSpcType
( VAR_SPC
, $1 ); break
;
261 case SETRAD
: SetSpcType
( RAD_SPC
, $1 ); break
;
262 case SETFIX
: SetSpcType
( FIX_SPC
, $1 ); break
;
266 species
: species spc semicolon
269 { ParserErrorMessage
(); }
274 spcname
: SPCSPC SPCEQUAL atoms
275 { switch
( crt_section
) {
276 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
277 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
278 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
283 { switch
( crt_section
) {
284 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
285 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
286 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
290 atoms
: atoms SPCPLUS atom
297 { AddAtom
( $1, "1" );
300 initvalues
: initvalues assignment semicolon
301 | assignment semicolon
303 { ParserErrorMessage
(); }
305 assignment
: INISPC INIEQUAL INIVALUE
306 { AssignInitialValue
( $1, $3 ); }
308 equations
: equations equation semicolon
311 { ParserErrorMessage
();
315 equation
: eqntag lefths righths rate
317 StoreEquationRate
( $4, $1 );
320 | lefths righths rate
322 StoreEquationRate
( $3, " " );
333 eqntag
: EQNLESS EQNTAG EQNGREATER
337 lefths
: expresion EQNEQUAL
340 righths
: expresion EQNCOLON
343 expresion
: expresion EQNSIGN term
344 { ProcessTerm
( eqState
, $2, crt_coef
, crt_term
);
347 { ProcessTerm
( eqState
, $1, crt_coef
, crt_term
);
350 { ProcessTerm
( eqState
, "+", crt_coef
, crt_term
);
353 term
: EQNCOEF EQNSPC
354 { strcpy
( crt_term
, $2 );
355 strcpy
( crt_coef
, $1 );
358 { strcpy
( crt_term
, $1 );
359 strcpy
( crt_coef
, "1" );
362 lumps
: lumps lump semicolon
365 { ParserErrorMessage
(); }
367 lump
: LMPSPC LMPPLUS lump
368 { AddLumpSpecies
( $1 );
370 | LMPSPC LMPCOLON LMPSPC
372 AddLumpSpecies
( $1 );
375 inlinecode
: inlinecode INCODE
377 InlineBuf
= AppendString
( InlineBuf
, $2, &InlineLen
, MAX_INLINE
);
381 InlineBuf
= malloc
( MAX_INLINE
);
382 InlineLen
= MAX_INLINE
;
383 strcpy
( InlineBuf
, $1);
388 void yyerror( char * str
)
392 void ParserErrorMessage
()
396 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
398 if
( crtToken
[0] == ';' ) {
399 ParserError
("Misplaced ';'");
402 switch
( crtTokType
) {
404 ParserError
("Missing ';' after '%s'", crtToken
);
408 ParserError
("Missing ';' or '+' after '%s'", crtToken
);
411 ParserError
("Missing species after '%s'", crtToken
);
414 ParserError
("Missing atom after '%s'", crtToken
);
417 ParserError
("Invalid '=' after '%s'", crtToken
);
421 ParserError
("Missing '=' after '%s'", crtToken
);
424 ParserError
("Missing value after '%s'", crtToken
);
427 ParserError
("Missing ';' after '%s'", crtToken
);
431 ParserError
("Missing '+' or '=' after '%s'", crtToken
);
434 ParserError
("Invalid right hand side of equation");
437 ParserError
("Missing rate after '%s'", crtToken
);
440 ParserError
("Missing coeficient after '%s'", crtToken
);
443 ParserError
("Missing species after '%s'", crtToken
);
446 ParserError
("Missing ';' after '%s'", crtToken
);
450 ParserError
("Missing '+' or ':' or ';' after '%s'", crtToken
);
453 ParserError
("Missing species after '%s'", crtToken
);
456 ParserError
("Missing species after '%s'", crtToken
);
459 ParserError
("Missing inline option after '%s'", crtToken
);
463 ParserError
("Syntax error after '%s'", crtToken
);
468 int Parser
( char * filename
)
473 crt_filename
= filename
;
475 f
= fopen
( crt_filename
, "r" );
477 FatalError
(7,"%s: File not found", crt_filename
);