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 ******************************************************************************/
47 /* extern int yyerrstatus; */
62 void SemicolonError
();
71 %token JACOBIAN DOUBLE FUNCTION DEFVAR DEFRAD DEFFIX SETVAR SETRAD SETFIX
72 %token HESSIAN STOICMAT STOCHASTIC
73 %token INITVALUES EQUATIONS LUMP INIEQUAL EQNEQUAL EQNCOLON
74 %token LMPCOLON LMPPLUS SPCPLUS SPCEQUAL ATOMDECL CHECK CHECKALL REORDER
75 %token MEX DUMMYINDEX EQNTAGS
76 %token LOOKAT LOOKATALL TRANSPORT TRANSPORTALL MONITOR USES SPARSEDATA
78 %token WRITE_ATM WRITE_SPC WRITE_MAT WRITE_OPT INITIALIZE XGRID YGRID ZGRID
79 %token USE LANGUAGE INTFILE DRIVER RUN INLINE ENDINLINE
80 %token PARAMETER SPCSPC INISPC INIVALUE EQNSPC EQNSIGN EQNCOEF
81 %type
<str
> PARAMETER SPCSPC INISPC INIVALUE EQNSPC EQNSIGN EQNCOEF
82 %token RATE LMPSPC SPCNR ATOMID LKTID MNIID INLCTX INCODE SSPID
83 %type
<str
> RATE LMPSPC SPCNR ATOMID LKTID MNIID INLCTX INCODE SSPID
84 %token EQNLESS EQNTAG EQNGREATER
85 %type
<str
> EQNLESS EQNTAG EQNGREATER
87 %type
<str
> TPTID USEID
88 %type
<str
> rate eqntag
95 section
: JACOBIAN PARAMETER
113 | DUMMYINDEX PARAMETER
114 { CmdDummyindex
( $2 );
122 | STOCHASTIC PARAMETER
123 { CmdStochastic
( $2 );
141 | INITVALUES initvalues
143 | EQUATIONS equations
149 | MONITOR monitorlist
151 | TRANSPORT translist
170 { CmdLanguage
( $2 ); }
171 | INITIALIZE PARAMETER
172 { DefineInitializeNbr
( $2 ); }
174 { DefineXGrid
( $2 ); }
176 { DefineYGrid
( $2 ); }
178 { DefineZGrid
( $2 ); }
179 | INLINE INLCTX inlinecode ENDINLINE
181 AddInlineCode
( $2, InlineBuf
);
185 { ParserErrorMessage
(); }
187 { CmdIntegrator
( $2 ); }
194 | SPARSEDATA PARAMETER
201 semicolon
: semicolon
';'
202 { ScanWarning
("Unnecessary ';'");
206 atomlist
: atomlist atomdef semicolon
209 { ParserErrorMessage
(); }
212 { switch
( crt_section
) {
213 case ATOMDECL
: DeclareAtom
( $1 ); break
;
214 case CHECK
: SetAtomType
( $1, DO_CHECK
); break
;
218 lookatlist
: lookatlist lookatspc semicolon
219 | lookatspc semicolon
221 { ParserErrorMessage
(); }
227 monitorlist
: monitorlist monitorspc semicolon
228 | monitorspc semicolon
230 { ParserErrorMessage
(); }
236 translist
: translist transspc semicolon
239 { ParserErrorMessage
(); }
242 { AddTransport
( $1 );
245 uselist
: uselist usefile semicolon
248 { ParserErrorMessage
(); }
254 setspclist
: setspclist setspcspc semicolon
255 | setspcspc semicolon
257 { ParserErrorMessage
(); }
260 { switch
( crt_section
) {
261 case SETVAR
: SetSpcType
( VAR_SPC
, $1 ); break
;
262 case SETRAD
: SetSpcType
( RAD_SPC
, $1 ); break
;
263 case SETFIX
: SetSpcType
( FIX_SPC
, $1 ); break
;
267 species
: species spc semicolon
270 { ParserErrorMessage
(); }
275 spcname
: SPCSPC SPCEQUAL atoms
276 { switch
( crt_section
) {
277 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
278 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
279 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
284 { switch
( crt_section
) {
285 case DEFVAR
: DeclareSpecies
( VAR_SPC
, $1 ); break
;
286 case DEFRAD
: DeclareSpecies
( RAD_SPC
, $1 ); break
;
287 case DEFFIX
: DeclareSpecies
( FIX_SPC
, $1 ); break
;
291 atoms
: atoms SPCPLUS atom
298 { AddAtom
( $1, "1" );
301 initvalues
: initvalues assignment semicolon
302 | assignment semicolon
304 { ParserErrorMessage
(); }
306 assignment
: INISPC INIEQUAL INIVALUE
307 { AssignInitialValue
( $1, $3 ); }
309 equations
: equations equation semicolon
312 { ParserErrorMessage
();
316 equation
: eqntag lefths righths rate
318 StoreEquationRate
( $4, $1 );
321 | lefths righths rate
323 StoreEquationRate
( $3, " " );
334 eqntag
: EQNLESS EQNTAG EQNGREATER
338 lefths
: expresion EQNEQUAL
341 righths
: expresion EQNCOLON
344 expresion
: expresion EQNSIGN term
345 { ProcessTerm
( eqState
, $2, crt_coef
, crt_term
);
348 { ProcessTerm
( eqState
, $1, crt_coef
, crt_term
);
351 { ProcessTerm
( eqState
, "+", crt_coef
, crt_term
);
354 term
: EQNCOEF EQNSPC
355 { strcpy
( crt_term
, $2 );
356 strcpy
( crt_coef
, $1 );
359 { strcpy
( crt_term
, $1 );
360 strcpy
( crt_coef
, "1" );
363 lumps
: lumps lump semicolon
366 { ParserErrorMessage
(); }
368 lump
: LMPSPC LMPPLUS lump
369 { AddLumpSpecies
( $1 );
371 | LMPSPC LMPCOLON LMPSPC
373 AddLumpSpecies
( $1 );
376 inlinecode
: inlinecode INCODE
378 InlineBuf
= AppendString
( InlineBuf
, $2, &InlineLen
, MAX_INLINE
);
382 InlineBuf
= malloc
( MAX_INLINE
);
383 InlineLen
= MAX_INLINE
;
384 strcpy
( InlineBuf
, $1);
389 void yyerror( char * str
)
393 void ParserErrorMessage
()
399 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
401 if
( crtToken
[0] == ';' ) {
402 ParserError
("Misplaced ';'");
405 switch
( crtTokType
) {
407 ParserError
("Missing ';' after '%s'", crtToken
);
411 ParserError
("Missing ';' or '+' after '%s'", crtToken
);
414 ParserError
("Missing species after '%s'", crtToken
);
417 ParserError
("Missing atom after '%s'", crtToken
);
420 ParserError
("Invalid '=' after '%s'", crtToken
);
424 ParserError
("Missing '=' after '%s'", crtToken
);
427 ParserError
("Missing value after '%s'", crtToken
);
430 ParserError
("Missing ';' after '%s'", crtToken
);
434 ParserError
("Missing '+' or '=' after '%s'", crtToken
);
437 ParserError
("Invalid right hand side of equation");
440 ParserError
("Missing rate after '%s'", crtToken
);
443 ParserError
("Missing coeficient after '%s'", crtToken
);
446 ParserError
("Missing species after '%s'", crtToken
);
449 ParserError
("Missing ';' after '%s'", crtToken
);
453 ParserError
("Missing '+' or ':' or ';' after '%s'", crtToken
);
456 ParserError
("Missing species after '%s'", crtToken
);
459 ParserError
("Missing species after '%s'", crtToken
);
462 ParserError
("Missing inline option after '%s'", crtToken
);
466 ParserError
("Syntax error after '%s'", crtToken
);
471 int Parser
( char * filename
)
476 crt_filename
= filename
;
478 f
= fopen
( crt_filename
, "r" );
480 FatalError
(7,"%s: File not found", crt_filename
);