Original WRF subgrid support version from John Michalakes without fire
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / src / scan.y
blob18e3f24485e380c13deff4b71d14e009b52a6e0e
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 );
196 | WRFCONFORM
197 { WRFConform();
200 semicolon : semicolon ';'
201 { ScanWarning("Unnecessary ';'");
203 | ';'
205 atomlist : atomlist atomdef semicolon
206 | atomdef semicolon
207 | error semicolon
208 { ParserErrorMessage(); }
210 atomdef : ATOMID
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
219 | error semicolon
220 { ParserErrorMessage(); }
222 lookatspc : LKTID
223 { AddLookAt( $1 );
226 monitorlist : monitorlist monitorspc semicolon
227 | monitorspc semicolon
228 | error semicolon
229 { ParserErrorMessage(); }
231 monitorspc : MNIID
232 { AddMonitor( $1 );
235 translist : translist transspc semicolon
236 | transspc semicolon
237 | error semicolon
238 { ParserErrorMessage(); }
240 transspc : TPTID
241 { AddTransport( $1 );
244 uselist : uselist usefile semicolon
245 | usefile semicolon
246 | error semicolon
247 { ParserErrorMessage(); }
249 usefile : USEID
250 { AddUseFile( $1 );
253 setspclist : setspclist setspcspc semicolon
254 | setspcspc semicolon
255 | error semicolon
256 { ParserErrorMessage(); }
258 setspcspc : SSPID
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
267 | spc semicolon
268 | error semicolon
269 { ParserErrorMessage(); }
271 spc : spcname
272 | spcdef
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;
282 spcdef : SPCSPC
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
291 | atom
293 atom : SPCNR SPCSPC
294 { AddAtom( $2, $1 );
296 | SPCSPC
297 { AddAtom( $1, "1" );
300 initvalues : initvalues assignment semicolon
301 | assignment semicolon
302 | error semicolon
303 { ParserErrorMessage(); }
305 assignment : INISPC INIEQUAL INIVALUE
306 { AssignInitialValue( $1, $3 ); }
308 equations : equations equation semicolon
309 | equation semicolon
310 | error semicolon
311 { ParserErrorMessage();
312 eqState = LHS;
315 equation : eqntag lefths righths rate
316 { eqState = LHS;
317 StoreEquationRate( $4, $1 );
318 CheckEquation();
320 | lefths righths rate
321 { eqState = LHS;
322 StoreEquationRate( $3, " " );
323 CheckEquation();
325 rate : RATE rate
326 { strcpy( $$, $1 );
327 strcat( $$, $2 );
329 | RATE
330 { strcpy( $$, $1 );
333 eqntag : EQNLESS EQNTAG EQNGREATER
334 { strcpy( $$, $2 );
337 lefths : expresion EQNEQUAL
338 { eqState = RHS; }
340 righths : expresion EQNCOLON
341 { eqState = RAT; }
343 expresion : expresion EQNSIGN term
344 { ProcessTerm( eqState, $2, crt_coef, crt_term );
346 | EQNSIGN term
347 { ProcessTerm( eqState, $1, crt_coef, crt_term );
349 | term
350 { ProcessTerm( eqState, "+", crt_coef, crt_term );
353 term : EQNCOEF EQNSPC
354 { strcpy( crt_term, $2 );
355 strcpy( crt_coef, $1 );
357 | EQNSPC
358 { strcpy( crt_term, $1 );
359 strcpy( crt_coef, "1" );
362 lumps : lumps lump semicolon
363 | lump semicolon
364 | error semicolon
365 { ParserErrorMessage(); }
367 lump : LMPSPC LMPPLUS lump
368 { AddLumpSpecies( $1 );
370 | LMPSPC LMPCOLON LMPSPC
372 AddLumpSpecies( $1 );
373 CheckLump( $3 );
375 inlinecode : inlinecode INCODE
377 InlineBuf = AppendString( InlineBuf, $2, &InlineLen, MAX_INLINE );
379 | INCODE
381 InlineBuf = malloc( MAX_INLINE );
382 InlineLen = MAX_INLINE;
383 strcpy( InlineBuf, $1);
388 void yyerror( char * str )
392 void ParserErrorMessage()
394 yyerrok;
396 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
398 if( crtToken[0] == ';' ) {
399 ParserError("Misplaced ';'");
400 return;
402 switch( crtTokType ) {
403 case ATOMID:
404 ParserError("Missing ';' after '%s'", crtToken );
405 break;
407 case SPCSPC:
408 ParserError("Missing ';' or '+' after '%s'", crtToken );
409 break;
410 case SPCNR:
411 ParserError("Missing species after '%s'", crtToken );
412 break;
413 case SPCPLUS:
414 ParserError("Missing atom after '%s'", crtToken );
415 break;
416 case SPCEQUAL:
417 ParserError("Invalid '=' after '%s'", crtToken );
418 break;
420 case INISPC:
421 ParserError("Missing '=' after '%s'", crtToken );
422 break;
423 case INIEQUAL:
424 ParserError("Missing value after '%s'", crtToken );
425 break;
426 case INIVALUE:
427 ParserError("Missing ';' after '%s'", crtToken );
428 break;
430 case EQNSPC:
431 ParserError("Missing '+' or '=' after '%s'", crtToken );
432 break;
433 case EQNEQUAL:
434 ParserError("Invalid right hand side of equation");
435 break;
436 case EQNCOLON:
437 ParserError("Missing rate after '%s'", crtToken );
438 break;
439 case EQNSIGN:
440 ParserError("Missing coeficient after '%s'", crtToken );
441 break;
442 case EQNCOEF:
443 ParserError("Missing species after '%s'", crtToken );
444 break;
445 case RATE:
446 ParserError("Missing ';' after '%s'", crtToken );
447 break;
449 case LMPSPC:
450 ParserError("Missing '+' or ':' or ';' after '%s'", crtToken );
451 break;
452 case LMPPLUS:
453 ParserError("Missing species after '%s'", crtToken );
454 break;
455 case LMPCOLON:
456 ParserError("Missing species after '%s'", crtToken );
457 break;
458 case INLINE:
459 ParserError("Missing inline option after '%s'", crtToken );
460 break;
462 default:
463 ParserError("Syntax error after '%s'", crtToken );
468 int Parser( char * filename )
470 extern int yydebug;
471 FILE *f;
473 crt_filename = filename;
475 f = fopen( crt_filename, "r" );
476 if( f == 0 ) {
477 FatalError(7,"%s: File not found", crt_filename);
480 yyin = f;
481 nError = 0;
482 nWarning = 0;
483 yydebug = 0;
485 yyparse();
487 fclose( f );
489 return nError;