Merge branch 'master' into devel
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / src / scan.y
blob0ff3ae3d5cbb929eaeccc62189d8aabd9de8cb56
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;
47 /* extern int yyerrstatus; */
49 int nError = 0;
50 int nWarning = 0;
52 int crt_section;
53 int eqState;
54 int isPhoto = 0;
56 char crt_term[ 30 ];
57 char crt_coef[ 30 ];
59 char * InlineBuf;
60 int InlineLen;
62 void SemicolonError();
63 extern int yyerrflag;
67 %union{
68 char str[80];
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
77 %token WRFCONFORM
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
86 %token TPTID USEID
87 %type <str> TPTID USEID
88 %type <str> rate eqntag
92 program : section
93 | section program
95 section : JACOBIAN PARAMETER
96 { CmdJacobian( $2 );
98 | HESSIAN PARAMETER
99 { CmdHessian( $2 );
101 | STOICMAT PARAMETER
102 { CmdStoicmat( $2 );
104 | DOUBLE PARAMETER
105 { CmdDouble( $2 );
107 | REORDER PARAMETER
108 { CmdReorder( $2 );
110 | MEX PARAMETER
111 { CmdMex( $2 );
113 | DUMMYINDEX PARAMETER
114 { CmdDummyindex( $2 );
116 | EQNTAGS PARAMETER
117 { CmdEqntags( $2 );
119 | FUNCTION PARAMETER
120 { CmdFunction( $2 );
122 | STOCHASTIC PARAMETER
123 { CmdStochastic( $2 );
125 | ATOMDECL atomlist
127 | CHECK atomlist
129 | DEFVAR species
131 | DEFRAD species
133 | DEFFIX species
135 | SETVAR setspclist
137 | SETRAD setspclist
139 | SETFIX setspclist
141 | INITVALUES initvalues
143 | EQUATIONS equations
145 | LUMP lumps
147 | LOOKAT lookatlist
149 | MONITOR monitorlist
151 | TRANSPORT translist
153 | CHECKALL
154 { CheckAll(); }
155 | LOOKATALL
156 { LookAtAll(); }
157 | TRANSPORTALL
158 { TransportAll(); }
159 | WRITE_ATM
160 { WriteAtoms(); }
161 | WRITE_SPC
162 { WriteSpecies(); }
163 | WRITE_MAT
164 { WriteMatrices(); }
165 | WRITE_OPT
166 { WriteOptions(); }
167 | USE PARAMETER
168 { CmdUse( $2 ); }
169 | LANGUAGE PARAMETER
170 { CmdLanguage( $2 ); }
171 | INITIALIZE PARAMETER
172 { DefineInitializeNbr( $2 ); }
173 | XGRID PARAMETER
174 { DefineXGrid( $2 ); }
175 | YGRID PARAMETER
176 { DefineYGrid( $2 ); }
177 | ZGRID PARAMETER
178 { DefineZGrid( $2 ); }
179 | INLINE INLCTX inlinecode ENDINLINE
181 AddInlineCode( $2, InlineBuf );
182 free( InlineBuf );
184 | INLINE error
185 { ParserErrorMessage(); }
186 | INTFILE PARAMETER
187 { CmdIntegrator( $2 ); }
188 | DRIVER PARAMETER
189 { CmdDriver( $2 ); }
190 | RUN PARAMETER
191 { CmdRun( $2 ); }
192 | USES uselist
194 | SPARSEDATA PARAMETER
195 { SparseData( $2 );
197 | WRFCONFORM
198 { WRFConform();
201 semicolon : semicolon ';'
202 { ScanWarning("Unnecessary ';'");
204 | ';'
206 atomlist : atomlist atomdef semicolon
207 | atomdef semicolon
208 | error semicolon
209 { ParserErrorMessage(); }
211 atomdef : ATOMID
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
220 | error semicolon
221 { ParserErrorMessage(); }
223 lookatspc : LKTID
224 { AddLookAt( $1 );
227 monitorlist : monitorlist monitorspc semicolon
228 | monitorspc semicolon
229 | error semicolon
230 { ParserErrorMessage(); }
232 monitorspc : MNIID
233 { AddMonitor( $1 );
236 translist : translist transspc semicolon
237 | transspc semicolon
238 | error semicolon
239 { ParserErrorMessage(); }
241 transspc : TPTID
242 { AddTransport( $1 );
245 uselist : uselist usefile semicolon
246 | usefile semicolon
247 | error semicolon
248 { ParserErrorMessage(); }
250 usefile : USEID
251 { AddUseFile( $1 );
254 setspclist : setspclist setspcspc semicolon
255 | setspcspc semicolon
256 | error semicolon
257 { ParserErrorMessage(); }
259 setspcspc : SSPID
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
268 | spc semicolon
269 | error semicolon
270 { ParserErrorMessage(); }
272 spc : spcname
273 | spcdef
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;
283 spcdef : SPCSPC
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
292 | atom
294 atom : SPCNR SPCSPC
295 { AddAtom( $2, $1 );
297 | SPCSPC
298 { AddAtom( $1, "1" );
301 initvalues : initvalues assignment semicolon
302 | assignment semicolon
303 | error semicolon
304 { ParserErrorMessage(); }
306 assignment : INISPC INIEQUAL INIVALUE
307 { AssignInitialValue( $1, $3 ); }
309 equations : equations equation semicolon
310 | equation semicolon
311 | error semicolon
312 { ParserErrorMessage();
313 eqState = LHS;
316 equation : eqntag lefths righths rate
317 { eqState = LHS;
318 StoreEquationRate( $4, $1 );
319 CheckEquation();
321 | lefths righths rate
322 { eqState = LHS;
323 StoreEquationRate( $3, " " );
324 CheckEquation();
326 rate : RATE rate
327 { strcpy( $$, $1 );
328 strcat( $$, $2 );
330 | RATE
331 { strcpy( $$, $1 );
334 eqntag : EQNLESS EQNTAG EQNGREATER
335 { strcpy( $$, $2 );
338 lefths : expresion EQNEQUAL
339 { eqState = RHS; }
341 righths : expresion EQNCOLON
342 { eqState = RAT; }
344 expresion : expresion EQNSIGN term
345 { ProcessTerm( eqState, $2, crt_coef, crt_term );
347 | EQNSIGN term
348 { ProcessTerm( eqState, $1, crt_coef, crt_term );
350 | term
351 { ProcessTerm( eqState, "+", crt_coef, crt_term );
354 term : EQNCOEF EQNSPC
355 { strcpy( crt_term, $2 );
356 strcpy( crt_coef, $1 );
358 | EQNSPC
359 { strcpy( crt_term, $1 );
360 strcpy( crt_coef, "1" );
363 lumps : lumps lump semicolon
364 | lump semicolon
365 | error semicolon
366 { ParserErrorMessage(); }
368 lump : LMPSPC LMPPLUS lump
369 { AddLumpSpecies( $1 );
371 | LMPSPC LMPCOLON LMPSPC
373 AddLumpSpecies( $1 );
374 CheckLump( $3 );
376 inlinecode : inlinecode INCODE
378 InlineBuf = AppendString( InlineBuf, $2, &InlineLen, MAX_INLINE );
380 | INCODE
382 InlineBuf = malloc( MAX_INLINE );
383 InlineLen = MAX_INLINE;
384 strcpy( InlineBuf, $1);
389 void yyerror( char * str )
393 void ParserErrorMessage()
395 #ifndef YYBISON
396 yyerrok;
397 #endif
399 Message("[%d,%s] -> [%d,%s]", crtTokType, crtToken, nextTokType, nextToken );
401 if( crtToken[0] == ';' ) {
402 ParserError("Misplaced ';'");
403 return;
405 switch( crtTokType ) {
406 case ATOMID:
407 ParserError("Missing ';' after '%s'", crtToken );
408 break;
410 case SPCSPC:
411 ParserError("Missing ';' or '+' after '%s'", crtToken );
412 break;
413 case SPCNR:
414 ParserError("Missing species after '%s'", crtToken );
415 break;
416 case SPCPLUS:
417 ParserError("Missing atom after '%s'", crtToken );
418 break;
419 case SPCEQUAL:
420 ParserError("Invalid '=' after '%s'", crtToken );
421 break;
423 case INISPC:
424 ParserError("Missing '=' after '%s'", crtToken );
425 break;
426 case INIEQUAL:
427 ParserError("Missing value after '%s'", crtToken );
428 break;
429 case INIVALUE:
430 ParserError("Missing ';' after '%s'", crtToken );
431 break;
433 case EQNSPC:
434 ParserError("Missing '+' or '=' after '%s'", crtToken );
435 break;
436 case EQNEQUAL:
437 ParserError("Invalid right hand side of equation");
438 break;
439 case EQNCOLON:
440 ParserError("Missing rate after '%s'", crtToken );
441 break;
442 case EQNSIGN:
443 ParserError("Missing coeficient after '%s'", crtToken );
444 break;
445 case EQNCOEF:
446 ParserError("Missing species after '%s'", crtToken );
447 break;
448 case RATE:
449 ParserError("Missing ';' after '%s'", crtToken );
450 break;
452 case LMPSPC:
453 ParserError("Missing '+' or ':' or ';' after '%s'", crtToken );
454 break;
455 case LMPPLUS:
456 ParserError("Missing species after '%s'", crtToken );
457 break;
458 case LMPCOLON:
459 ParserError("Missing species after '%s'", crtToken );
460 break;
461 case INLINE:
462 ParserError("Missing inline option after '%s'", crtToken );
463 break;
465 default:
466 ParserError("Syntax error after '%s'", crtToken );
471 int Parser( char * filename )
473 extern int yydebug;
474 FILE *f;
476 crt_filename = filename;
478 f = fopen( crt_filename, "r" );
479 if( f == 0 ) {
480 FatalError(7,"%s: File not found", crt_filename);
483 yyin = f;
484 nError = 0;
485 nWarning = 0;
486 yydebug = 0;
488 yyparse();
490 fclose( f );
492 return nError;