added README_changes.txt
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / src.org / scan.y
blobb861c6c1f06d14c59ffbe43d71a2e73e9dd2638a
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
17 details.
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.
24 Adrian Sandu
25 Computer Science Department
26 Virginia Polytechnic Institute and State University
27 Blacksburg, VA 24060
28 E-mail: sandu@cs.vt.edu
30 ******************************************************************************/
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <malloc.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include "scan.h"
42 #define __YYSCLASS
44 #define YYDEBUG 1
45 extern char yytext[];
46 extern FILE * yyin;
48 int nError = 0;
49 int nWarning = 0;
51 int crt_section;
52 int eqState;
53 int isPhoto = 0;
55 char crt_term[ 30 ];
56 char crt_coef[ 30 ];
58 char * InlineBuf;
59 int InlineLen;
61 void SemicolonError();
62 extern int yyerrflag;
66 %union{
67 char str[80];
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
76 %token WRFCONFORM
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
85 %token TPTID USEID
86 %type <str> TPTID USEID
87 %type <str> rate eqntag
91 program : section
92 | section program
94 section : JACOBIAN PARAMETER
95 { CmdJacobian( $2 );
97 | HESSIAN PARAMETER
98 { CmdHessian( $2 );
100 | STOICMAT PARAMETER
101 { CmdStoicmat( $2 );
103 | DOUBLE PARAMETER
104 { CmdDouble( $2 );
106 | REORDER PARAMETER
107 { CmdReorder( $2 );
109 | MEX PARAMETER
110 { CmdMex( $2 );
112 | DUMMYINDEX PARAMETER
113 { CmdDummyindex( $2 );
115 | EQNTAGS PARAMETER
116 { CmdEqntags( $2 );
118 | FUNCTION PARAMETER
119 { CmdFunction( $2 );
121 | STOCHASTIC PARAMETER
122 { CmdStochastic( $2 );
124 | ATOMDECL atomlist
126 | CHECK atomlist
128 | DEFVAR species
130 | DEFRAD species
132 | DEFFIX species
134 | SETVAR setspclist
136 | SETRAD setspclist
138 | SETFIX setspclist
140 | INITVALUES initvalues
142 | EQUATIONS equations
144 | LUMP lumps
146 | LOOKAT lookatlist
148 | MONITOR monitorlist
150 | TRANSPORT translist
152 | CHECKALL
153 { CheckAll(); }
154 | LOOKATALL
155 { LookAtAll(); }
156 | TRANSPORTALL
157 { TransportAll(); }
158 | WRITE_ATM
159 { WriteAtoms(); }
160 | WRITE_SPC
161 { WriteSpecies(); }
162 | WRITE_MAT
163 { WriteMatrices(); }
164 | WRITE_OPT
165 { WriteOptions(); }
166 | USE PARAMETER
167 { CmdUse( $2 ); }
168 | LANGUAGE PARAMETER
169 { CmdLanguage( $2 ); }
170 | INITIALIZE PARAMETER
171 { DefineInitializeNbr( $2 ); }
172 | XGRID PARAMETER
173 { DefineXGrid( $2 ); }
174 | YGRID PARAMETER
175 { DefineYGrid( $2 ); }
176 | ZGRID PARAMETER
177 { DefineZGrid( $2 ); }
178 | INLINE INLCTX inlinecode ENDINLINE
180 AddInlineCode( $2, InlineBuf );
181 free( InlineBuf );
183 | INLINE error
184 { ParserErrorMessage(); }
185 | INTFILE PARAMETER
186 { CmdIntegrator( $2 ); }
187 | DRIVER PARAMETER
188 { CmdDriver( $2 ); }
189 | RUN PARAMETER
190 { CmdRun( $2 ); }
191 | USES uselist
193 | SPARSEDATA PARAMETER
194 { SparseData( $2 );
197 semicolon : semicolon ';'
198 { ScanWarning("Unnecessary ';'");
200 | ';'
202 atomlist : atomlist atomdef semicolon
203 | atomdef semicolon
204 | error semicolon
205 { ParserErrorMessage(); }
207 atomdef : ATOMID
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
216 | error semicolon
217 { ParserErrorMessage(); }
219 lookatspc : LKTID
220 { AddLookAt( $1 );
223 monitorlist : monitorlist monitorspc semicolon
224 | monitorspc semicolon
225 | error semicolon
226 { ParserErrorMessage(); }
228 monitorspc : MNIID
229 { AddMonitor( $1 );
232 translist : translist transspc semicolon
233 | transspc semicolon
234 | error semicolon
235 { ParserErrorMessage(); }
237 transspc : TPTID
238 { AddTransport( $1 );
241 uselist : uselist usefile semicolon
242 | usefile semicolon
243 | error semicolon
244 { ParserErrorMessage(); }
246 usefile : USEID
247 { AddUseFile( $1 );
250 setspclist : setspclist setspcspc semicolon
251 | setspcspc semicolon
252 | error semicolon
253 { ParserErrorMessage(); }
255 setspcspc : SSPID
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
264 | spc semicolon
265 | error semicolon
266 { ParserErrorMessage(); }
268 spc : spcname
269 | spcdef
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;
279 spcdef : SPCSPC
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
288 | atom
290 atom : SPCNR SPCSPC
291 { AddAtom( $2, $1 );
293 | SPCSPC
294 { AddAtom( $1, "1" );
297 initvalues : initvalues assignment semicolon
298 | assignment semicolon
299 | error semicolon
300 { ParserErrorMessage(); }
302 assignment : INISPC INIEQUAL INIVALUE
303 { AssignInitialValue( $1, $3 ); }
305 equations : equations equation semicolon
306 | equation semicolon
307 | error semicolon
308 { ParserErrorMessage();
309 eqState = LHS;
312 equation : eqntag lefths righths rate
313 { eqState = LHS;
314 StoreEquationRate( $4, $1 );
315 CheckEquation();
317 | lefths righths rate
318 { eqState = LHS;
319 StoreEquationRate( $3, " " );
320 CheckEquation();
322 rate : RATE rate
323 { strcpy( $$, $1 );
324 strcat( $$, $2 );
326 | RATE
327 { strcpy( $$, $1 );
330 eqntag : EQNLESS EQNTAG EQNGREATER
331 { strcpy( $$, $2 );
334 lefths : expresion EQNEQUAL
335 { eqState = RHS; }
337 righths : expresion EQNCOLON
338 { eqState = RAT; }
340 expresion : expresion EQNSIGN term
341 { ProcessTerm( eqState, $2, crt_coef, crt_term );
343 | EQNSIGN term
344 { ProcessTerm( eqState, $1, crt_coef, crt_term );
346 | term
347 { ProcessTerm( eqState, "+", crt_coef, crt_term );
350 term : EQNCOEF EQNSPC
351 { strcpy( crt_term, $2 );
352 strcpy( crt_coef, $1 );
354 | EQNSPC
355 { strcpy( crt_term, $1 );
356 strcpy( crt_coef, "1" );
359 lumps : lumps lump semicolon
360 | lump semicolon
361 | error semicolon
362 { ParserErrorMessage(); }
364 lump : LMPSPC LMPPLUS lump
365 { AddLumpSpecies( $1 );
367 | LMPSPC LMPCOLON LMPSPC
369 AddLumpSpecies( $1 );
370 CheckLump( $3 );
372 inlinecode : inlinecode INCODE
374 InlineBuf = AppendString( InlineBuf, $2, &InlineLen, MAX_INLINE );
376 | INCODE
378 InlineBuf = malloc( MAX_INLINE );
379 InlineLen = MAX_INLINE;
380 strcpy( InlineBuf, $1);
385 void yyerror( char * str )
389 void ParserErrorMessage()
391 yyerrok;
393 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
395 if( crtToken[0] == ';' ) {
396 ParserError("Misplaced ';'");
397 return;
399 switch( crtTokType ) {
400 case ATOMID:
401 ParserError("Missing ';' after '%s'", crtToken );
402 break;
404 case SPCSPC:
405 ParserError("Missing ';' or '+' after '%s'", crtToken );
406 break;
407 case SPCNR:
408 ParserError("Missing species after '%s'", crtToken );
409 break;
410 case SPCPLUS:
411 ParserError("Missing atom after '%s'", crtToken );
412 break;
413 case SPCEQUAL:
414 ParserError("Invalid '=' after '%s'", crtToken );
415 break;
417 case INISPC:
418 ParserError("Missing '=' after '%s'", crtToken );
419 break;
420 case INIEQUAL:
421 ParserError("Missing value after '%s'", crtToken );
422 break;
423 case INIVALUE:
424 ParserError("Missing ';' after '%s'", crtToken );
425 break;
427 case EQNSPC:
428 ParserError("Missing '+' or '=' after '%s'", crtToken );
429 break;
430 case EQNEQUAL:
431 ParserError("Invalid right hand side of equation");
432 break;
433 case EQNCOLON:
434 ParserError("Missing rate after '%s'", crtToken );
435 break;
436 case EQNSIGN:
437 ParserError("Missing coeficient after '%s'", crtToken );
438 break;
439 case EQNCOEF:
440 ParserError("Missing species after '%s'", crtToken );
441 break;
442 case RATE:
443 ParserError("Missing ';' after '%s'", crtToken );
444 break;
446 case LMPSPC:
447 ParserError("Missing '+' or ':' or ';' after '%s'", crtToken );
448 break;
449 case LMPPLUS:
450 ParserError("Missing species after '%s'", crtToken );
451 break;
452 case LMPCOLON:
453 ParserError("Missing species after '%s'", crtToken );
454 break;
455 case INLINE:
456 ParserError("Missing inline option after '%s'", crtToken );
457 break;
459 default:
460 ParserError("Syntax error after '%s'", crtToken );
465 int Parser( char * filename )
467 extern int yydebug;
468 FILE *f;
470 crt_filename = filename;
472 f = fopen( crt_filename, "r" );
473 if( f == 0 ) {
474 FatalError(7,"%s: File not found", crt_filename);
477 yyin = f;
478 nError = 0;
479 nWarning = 0;
480 yydebug = 0;
482 yyparse();
484 fclose( f );
486 return nError;