added README_changes.txt
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / src / scan.y
blob44764a610e06a3490bb3ed9ba80f18fe4712d2a7
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 #ifdef MACOS
38 #include <sys/malloc.h>
39 #else
40 #include <malloc.h>
41 #endif
42 #include <string.h>
43 #include <unistd.h>
44 #include "scan.h"
46 #define __YYSCLASS
48 #define YYDEBUG 1
49 extern char yytext[];
50 extern FILE * yyin;
52 int nError = 0;
53 int nWarning = 0;
55 int crt_section;
56 int eqState;
57 int isPhoto = 0;
59 char crt_term[ 30 ];
60 char crt_coef[ 30 ];
62 char * InlineBuf;
63 int InlineLen;
65 void SemicolonError();
66 extern int yyerrflag;
70 %union{
71 char str[80];
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
80 %token WRFCONFORM
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
89 %token TPTID USEID
90 %type <str> TPTID USEID
91 %type <str> rate eqntag
95 program : section
96 | section program
98 section : JACOBIAN PARAMETER
99 { CmdJacobian( $2 );
101 | HESSIAN PARAMETER
102 { CmdHessian( $2 );
104 | STOICMAT PARAMETER
105 { CmdStoicmat( $2 );
107 | DOUBLE PARAMETER
108 { CmdDouble( $2 );
110 | REORDER PARAMETER
111 { CmdReorder( $2 );
113 | MEX PARAMETER
114 { CmdMex( $2 );
116 | DUMMYINDEX PARAMETER
117 { CmdDummyindex( $2 );
119 | EQNTAGS PARAMETER
120 { CmdEqntags( $2 );
122 | FUNCTION PARAMETER
123 { CmdFunction( $2 );
125 | STOCHASTIC PARAMETER
126 { CmdStochastic( $2 );
128 | ATOMDECL atomlist
130 | CHECK atomlist
132 | DEFVAR species
134 | DEFRAD species
136 | DEFFIX species
138 | SETVAR setspclist
140 | SETRAD setspclist
142 | SETFIX setspclist
144 | INITVALUES initvalues
146 | EQUATIONS equations
148 | LUMP lumps
150 | LOOKAT lookatlist
152 | MONITOR monitorlist
154 | TRANSPORT translist
156 | CHECKALL
157 { CheckAll(); }
158 | LOOKATALL
159 { LookAtAll(); }
160 | TRANSPORTALL
161 { TransportAll(); }
162 | WRITE_ATM
163 { WriteAtoms(); }
164 | WRITE_SPC
165 { WriteSpecies(); }
166 | WRITE_MAT
167 { WriteMatrices(); }
168 | WRITE_OPT
169 { WriteOptions(); }
170 | USE PARAMETER
171 { CmdUse( $2 ); }
172 | LANGUAGE PARAMETER
173 { CmdLanguage( $2 ); }
174 | INITIALIZE PARAMETER
175 { DefineInitializeNbr( $2 ); }
176 | XGRID PARAMETER
177 { DefineXGrid( $2 ); }
178 | YGRID PARAMETER
179 { DefineYGrid( $2 ); }
180 | ZGRID PARAMETER
181 { DefineZGrid( $2 ); }
182 | INLINE INLCTX inlinecode ENDINLINE
184 AddInlineCode( $2, InlineBuf );
185 free( InlineBuf );
187 | INLINE error
188 { ParserErrorMessage(); }
189 | INTFILE PARAMETER
190 { CmdIntegrator( $2 ); }
191 | DRIVER PARAMETER
192 { CmdDriver( $2 ); }
193 | RUN PARAMETER
194 { CmdRun( $2 ); }
195 | USES uselist
197 | SPARSEDATA PARAMETER
198 { SparseData( $2 );
200 | WRFCONFORM
201 { WRFConform();
204 semicolon : semicolon ';'
205 { ScanWarning("Unnecessary ';'");
207 | ';'
209 atomlist : atomlist atomdef semicolon
210 | atomdef semicolon
211 | error semicolon
212 { ParserErrorMessage(); }
214 atomdef : ATOMID
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
223 | error semicolon
224 { ParserErrorMessage(); }
226 lookatspc : LKTID
227 { AddLookAt( $1 );
230 monitorlist : monitorlist monitorspc semicolon
231 | monitorspc semicolon
232 | error semicolon
233 { ParserErrorMessage(); }
235 monitorspc : MNIID
236 { AddMonitor( $1 );
239 translist : translist transspc semicolon
240 | transspc semicolon
241 | error semicolon
242 { ParserErrorMessage(); }
244 transspc : TPTID
245 { AddTransport( $1 );
248 uselist : uselist usefile semicolon
249 | usefile semicolon
250 | error semicolon
251 { ParserErrorMessage(); }
253 usefile : USEID
254 { AddUseFile( $1 );
257 setspclist : setspclist setspcspc semicolon
258 | setspcspc semicolon
259 | error semicolon
260 { ParserErrorMessage(); }
262 setspcspc : SSPID
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
271 | spc semicolon
272 | error semicolon
273 { ParserErrorMessage(); }
275 spc : spcname
276 | spcdef
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;
286 spcdef : SPCSPC
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
295 | atom
297 atom : SPCNR SPCSPC
298 { AddAtom( $2, $1 );
300 | SPCSPC
301 { AddAtom( $1, "1" );
304 initvalues : initvalues assignment semicolon
305 | assignment semicolon
306 | error semicolon
307 { ParserErrorMessage(); }
309 assignment : INISPC INIEQUAL INIVALUE
310 { AssignInitialValue( $1, $3 ); }
312 equations : equations equation semicolon
313 | equation semicolon
314 | error semicolon
315 { ParserErrorMessage();
316 eqState = LHS;
319 equation : eqntag lefths righths rate
320 { eqState = LHS;
321 StoreEquationRate( $4, $1 );
322 CheckEquation();
324 | lefths righths rate
325 { eqState = LHS;
326 StoreEquationRate( $3, " " );
327 CheckEquation();
329 rate : RATE rate
330 { strcpy( $$, $1 );
331 strcat( $$, $2 );
333 | RATE
334 { strcpy( $$, $1 );
337 eqntag : EQNLESS EQNTAG EQNGREATER
338 { strcpy( $$, $2 );
341 lefths : expresion EQNEQUAL
342 { eqState = RHS; }
344 righths : expresion EQNCOLON
345 { eqState = RAT; }
347 expresion : expresion EQNSIGN term
348 { ProcessTerm( eqState, $2, crt_coef, crt_term );
350 | EQNSIGN term
351 { ProcessTerm( eqState, $1, crt_coef, crt_term );
353 | term
354 { ProcessTerm( eqState, "+", crt_coef, crt_term );
357 term : EQNCOEF EQNSPC
358 { strcpy( crt_term, $2 );
359 strcpy( crt_coef, $1 );
361 | EQNSPC
362 { strcpy( crt_term, $1 );
363 strcpy( crt_coef, "1" );
366 lumps : lumps lump semicolon
367 | lump semicolon
368 | error semicolon
369 { ParserErrorMessage(); }
371 lump : LMPSPC LMPPLUS lump
372 { AddLumpSpecies( $1 );
374 | LMPSPC LMPCOLON LMPSPC
376 AddLumpSpecies( $1 );
377 CheckLump( $3 );
379 inlinecode : inlinecode INCODE
381 InlineBuf = AppendString( InlineBuf, $2, &InlineLen, MAX_INLINE );
383 | INCODE
385 InlineBuf = malloc( MAX_INLINE );
386 InlineLen = MAX_INLINE;
387 strcpy( InlineBuf, $1);
392 void yyerror( char * str )
396 void ParserErrorMessage()
398 yyerrok;
400 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
402 if( crtToken[0] == ';' ) {
403 ParserError("Misplaced ';'");
404 return;
406 switch( crtTokType ) {
407 case ATOMID:
408 ParserError("Missing ';' after '%s'", crtToken );
409 break;
411 case SPCSPC:
412 ParserError("Missing ';' or '+' after '%s'", crtToken );
413 break;
414 case SPCNR:
415 ParserError("Missing species after '%s'", crtToken );
416 break;
417 case SPCPLUS:
418 ParserError("Missing atom after '%s'", crtToken );
419 break;
420 case SPCEQUAL:
421 ParserError("Invalid '=' after '%s'", crtToken );
422 break;
424 case INISPC:
425 ParserError("Missing '=' after '%s'", crtToken );
426 break;
427 case INIEQUAL:
428 ParserError("Missing value after '%s'", crtToken );
429 break;
430 case INIVALUE:
431 ParserError("Missing ';' after '%s'", crtToken );
432 break;
434 case EQNSPC:
435 ParserError("Missing '+' or '=' after '%s'", crtToken );
436 break;
437 case EQNEQUAL:
438 ParserError("Invalid right hand side of equation");
439 break;
440 case EQNCOLON:
441 ParserError("Missing rate after '%s'", crtToken );
442 break;
443 case EQNSIGN:
444 ParserError("Missing coeficient after '%s'", crtToken );
445 break;
446 case EQNCOEF:
447 ParserError("Missing species after '%s'", crtToken );
448 break;
449 case RATE:
450 ParserError("Missing ';' after '%s'", crtToken );
451 break;
453 case LMPSPC:
454 ParserError("Missing '+' or ':' or ';' after '%s'", crtToken );
455 break;
456 case LMPPLUS:
457 ParserError("Missing species after '%s'", crtToken );
458 break;
459 case LMPCOLON:
460 ParserError("Missing species after '%s'", crtToken );
461 break;
462 case INLINE:
463 ParserError("Missing inline option after '%s'", crtToken );
464 break;
466 default:
467 ParserError("Syntax error after '%s'", crtToken );
472 int Parser( char * filename )
474 extern int yydebug;
475 FILE *f;
477 crt_filename = filename;
479 f = fopen( crt_filename, "r" );
480 if( f == 0 ) {
481 FatalError(7,"%s: File not found", crt_filename);
484 yyin = f;
485 nError = 0;
486 nWarning = 0;
487 yydebug = 0;
489 yyparse();
491 fclose( f );
493 return nError;