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 ******************************************************************************/
38 #include <sys/malloc.h>
65 void SemicolonError
();
74 %token JACOBIAN DOUBLE FUNCTION DEFVAR DEFRAD DEFFIX SETVAR SETRAD SETFIX
75 %token HESSIAN STOICMAT STOCHASTIC
76 %token INITVALUES EQUATIONS LUMP INIEQUAL EQNEQUAL EQNCOLON
77 %token LMPCOLON LMPPLUS SPCPLUS SPCEQUAL ATOMDECL CHECK CHECKALL REORDER
78 %token MEX DUMMYINDEX EQNTAGS
79 %token LOOKAT LOOKATALL TRANSPORT TRANSPORTALL MONITOR USES SPARSEDATA
81 %token WRITE_ATM WRITE_SPC WRITE_MAT WRITE_OPT INITIALIZE XGRID YGRID ZGRID
82 %token USE LANGUAGE INTFILE DRIVER RUN INLINE ENDINLINE
83 %token PARAMETER SPCSPC INISPC INIVALUE EQNSPC EQNSIGN EQNCOEF
84 %type
<str
> PARAMETER SPCSPC INISPC INIVALUE EQNSPC EQNSIGN EQNCOEF
85 %token RATE LMPSPC SPCNR ATOMID LKTID MNIID INLCTX INCODE SSPID
86 %type
<str
> RATE LMPSPC SPCNR ATOMID LKTID MNIID INLCTX INCODE SSPID
87 %token EQNLESS EQNTAG EQNGREATER
88 %type
<str
> EQNLESS EQNTAG EQNGREATER
90 %type
<str
> TPTID USEID
91 %type
<str
> rate eqntag
98 section
: JACOBIAN PARAMETER
116 | DUMMYINDEX PARAMETER
117 { CmdDummyindex
( $2 );
125 | STOCHASTIC PARAMETER
126 { CmdStochastic
( $2 );
144 | INITVALUES initvalues
146 | EQUATIONS equations
152 | MONITOR monitorlist
154 | TRANSPORT translist
173 { CmdLanguage
( $2 ); }
174 | INITIALIZE PARAMETER
175 { DefineInitializeNbr
( $2 ); }
177 { DefineXGrid
( $2 ); }
179 { DefineYGrid
( $2 ); }
181 { DefineZGrid
( $2 ); }
182 | INLINE INLCTX inlinecode ENDINLINE
184 AddInlineCode
( $2, InlineBuf
);
188 { ParserErrorMessage
(); }
190 { CmdIntegrator
( $2 ); }
197 | SPARSEDATA PARAMETER
204 semicolon
: semicolon
';'
205 { ScanWarning
("Unnecessary ';'");
209 atomlist
: atomlist atomdef semicolon
212 { ParserErrorMessage
(); }
215 { switch
( crt_section
) {
216 case ATOMDECL
: DeclareAtom
( $1 ); break
;
217 case CHECK
: SetAtomType
( $1, DO_CHECK
); break
;
221 lookatlist
: lookatlist lookatspc semicolon
222 | lookatspc semicolon
224 { ParserErrorMessage
(); }
230 monitorlist
: monitorlist monitorspc semicolon
231 | monitorspc semicolon
233 { ParserErrorMessage
(); }
239 translist
: translist transspc semicolon
242 { ParserErrorMessage
(); }
245 { AddTransport
( $1 );
248 uselist
: uselist usefile semicolon
251 { ParserErrorMessage
(); }
257 setspclist
: setspclist setspcspc semicolon
258 | setspcspc semicolon
260 { ParserErrorMessage
(); }
263 { switch
( crt_section
) {
264 case SETVAR
: SetSpcType
( VAR_SPC
, $1 ); break
;
265 case SETRAD
: SetSpcType
( RAD_SPC
, $1 ); break
;
266 case SETFIX
: SetSpcType
( FIX_SPC
, $1 ); break
;
270 species
: species spc semicolon
273 { ParserErrorMessage
(); }
278 spcname
: SPCSPC SPCEQUAL atoms
279 { switch
( crt_section
) {
280 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
281 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
282 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
287 { switch
( crt_section
) {
288 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
289 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
290 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
294 atoms
: atoms SPCPLUS atom
301 { AddAtom
( $1, "1" );
304 initvalues
: initvalues assignment semicolon
305 | assignment semicolon
307 { ParserErrorMessage
(); }
309 assignment
: INISPC INIEQUAL INIVALUE
310 { AssignInitialValue
( $1, $3 ); }
312 equations
: equations equation semicolon
315 { ParserErrorMessage
();
319 equation
: eqntag lefths righths rate
321 StoreEquationRate
( $4, $1 );
324 | lefths righths rate
326 StoreEquationRate
( $3, " " );
337 eqntag
: EQNLESS EQNTAG EQNGREATER
341 lefths
: expresion EQNEQUAL
344 righths
: expresion EQNCOLON
347 expresion
: expresion EQNSIGN term
348 { ProcessTerm
( eqState
, $2, crt_coef
, crt_term
);
351 { ProcessTerm
( eqState
, $1, crt_coef
, crt_term
);
354 { ProcessTerm
( eqState
, "+", crt_coef
, crt_term
);
357 term
: EQNCOEF EQNSPC
358 { strcpy
( crt_term
, $2 );
359 strcpy
( crt_coef
, $1 );
362 { strcpy
( crt_term
, $1 );
363 strcpy
( crt_coef
, "1" );
366 lumps
: lumps lump semicolon
369 { ParserErrorMessage
(); }
371 lump
: LMPSPC LMPPLUS lump
372 { AddLumpSpecies
( $1 );
374 | LMPSPC LMPCOLON LMPSPC
376 AddLumpSpecies
( $1 );
379 inlinecode
: inlinecode INCODE
381 InlineBuf
= AppendString
( InlineBuf
, $2, &InlineLen
, MAX_INLINE
);
385 InlineBuf
= malloc
( MAX_INLINE
);
386 InlineLen
= MAX_INLINE
;
387 strcpy
( InlineBuf
, $1);
392 void yyerror( char * str
)
396 void ParserErrorMessage
()
400 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
402 if
( crtToken
[0] == ';' ) {
403 ParserError
("Misplaced ';'");
406 switch
( crtTokType
) {
408 ParserError
("Missing ';' after '%s'", crtToken
);
412 ParserError
("Missing ';' or '+' after '%s'", crtToken
);
415 ParserError
("Missing species after '%s'", crtToken
);
418 ParserError
("Missing atom after '%s'", crtToken
);
421 ParserError
("Invalid '=' after '%s'", crtToken
);
425 ParserError
("Missing '=' after '%s'", crtToken
);
428 ParserError
("Missing value after '%s'", crtToken
);
431 ParserError
("Missing ';' after '%s'", crtToken
);
435 ParserError
("Missing '+' or '=' after '%s'", crtToken
);
438 ParserError
("Invalid right hand side of equation");
441 ParserError
("Missing rate after '%s'", crtToken
);
444 ParserError
("Missing coeficient after '%s'", crtToken
);
447 ParserError
("Missing species after '%s'", crtToken
);
450 ParserError
("Missing ';' after '%s'", crtToken
);
454 ParserError
("Missing '+' or ':' or ';' after '%s'", crtToken
);
457 ParserError
("Missing species after '%s'", crtToken
);
460 ParserError
("Missing species after '%s'", crtToken
);
463 ParserError
("Missing inline option after '%s'", crtToken
);
467 ParserError
("Syntax error after '%s'", crtToken
);
472 int Parser
( char * filename
)
477 crt_filename
= filename
;
479 f
= fopen
( crt_filename
, "r" );
481 FatalError
(7,"%s: File not found", crt_filename
);