]> andersk Git - splint.git/blob - src/cgrammar.y
commitng to fix cvs archive. Code works with gcc272 but not 295. Currently passed...
[splint.git] / src / cgrammar.y
1 /*;-*-C-*-;
2 ** Copyright (c) Massachusetts Institute of Technology 1994-1998.
3 **          All Rights Reserved.
4 **          Unpublished rights reserved under the copyright laws of
5 **          the United States.
6 **
7 ** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 ** OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
9 **
10 ** This code is distributed freely and may be used freely under the 
11 ** following conditions:
12 **
13 **     1. This notice may not be removed or altered.
14 **
15 **     2. Works derived from this code are not distributed for
16 **        commercial gain without explicit permission from MIT 
17 **        (for permission contact lclint-request@sds.lcs.mit.edu).
18 */
19 %{
20 /*
21 **
22 ** cgrammar.y
23 **
24 ** Yacc/Bison grammar for extended ANSI C used by LCLint.
25 **
26 ** original grammar by Nate Osgood ---
27 **    hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
28 **
29 ** changes for LCLint --- handle typedef names correctly
30 ** fix struct/union parsing bug (empty struct is accepted)
31 ** add productions to handle macros --- require
32 ** error correction --- main source of conflicts in grammar.
33 ** need to process initializations sequentially, L->R
34 **
35 ** production names are cryptic, so more productions fit on one line
36 **
37 ** conflicts:  87 shift/reduce, 18 reduce/reduce
38 ** most of these are due to handling macros
39 ** a few are due to handling type expressions
40 */
41
42 /*@=allmacros@*/
43
44 extern int yylex ();
45 extern void swallowMacro (void);
46
47 # include "lclintMacros.nf"
48 # include "basic.h"
49 # include "cgrammar.h"
50 # include "exprChecks.h"
51
52 /*@-allmacros@*/
53 /*@-matchfields@*/
54
55 # define SHOWCSYM FALSE
56 void yyerror (char *s);
57
58 /*
59 ** This is necessary, or else when the bison-generated code #include's malloc.h,
60 ** there will be a parse error.
61 **
62 ** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
63 ** in bison-generated files under Win32.
64 */
65
66 # ifdef WIN32
67 # undef malloc
68 # undef calloc
69 # undef realloc
70 # endif
71
72 void checkandsetBufState(idDecl id, exprNode is);
73 %}
74
75 %union
76 {
77  lltok tok;
78  int count;
79  specialClauseKind sck;
80  qual typequal;
81  qualList tquallist;
82  ctype ctyp;
83  sRef sr;
84  /*@only@*/ qtype qtyp;
85  /*@only@*/ cstring cname;
86  /*@only@*/ idDecl ntyp;
87  /*@only@*/ idDeclList ntyplist;
88  /*@only@*/ uentryList flist;
89  /*@owned@*/ uentryList entrylist;
90  /*@observer@*/ /*@dependent@*/ uentry entry;
91  /*@only@*/ uentry oentry;
92  /*@only@*/ exprNode expr;
93  /*@only@*/ enumNameList enumnamelist;
94  /*@only@*/ exprNodeList alist;
95  /*@only@*/ sRefSet srset; 
96  /*@only@*/ cstringList cstringlist;
97   /*drl
98     added 1/19/2001
99   */
100   constraint con;
101   constraintList conL;
102   constraintExpr conE;
103   /* drl */
104 }
105
106 /* standard C tokens */
107
108 %token <tok> BADTOK SKIPTOK
109 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
110 %token <tok> GOTO CONTINUE BREAK RETURN
111 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN 
112 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
113 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
114 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
115 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
116 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
117 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
118 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
119 %token <tok> CSTRUCT CUNION CENUM
120 %token <tok> VA_ARG VA_DCL
121 %token <tok> QGLOBALS
122 %token <tok> QMODIFIES 
123 %token <tok> QNOMODS
124 %token <tok> QCONSTANT
125 %token <tok> QFUNCTION
126 %token <tok> QITER
127 %token <tok> QDEFINES 
128 %token <tok> QUSES
129 %token <tok> QALLOCATES
130 %token <tok> QSETS
131 %token <tok> QRELEASES 
132 %token <tok> QPRECLAUSE 
133 %token <tok> QPOSTCLAUSE 
134 %token <tok> QALT 
135 %token <tok> QUNDEF QKILLED
136 %token <tok> QENDMACRO
137
138 /* additional tokens introduced by lclint pre-processor. */
139 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
140
141 /* break comments: */
142 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
143 %token <tok> QINNERCONTINUE
144
145 /* case fall-through marker: */
146 %token <tok> QFALLTHROUGH
147
148 /* used in scanner only */
149 %token <tok> QLINTNOTREACHED
150 %token <tok> QLINTFALLTHROUGH
151 %token <tok> QLINTFALLTHRU
152 %token <tok> QARGSUSED
153 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
154
155 /* not-reached marker: (used like a label) */
156 %token <tok> QNOTREACHED
157
158 /* type qualifiers: */
159 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
160 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
161 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
162 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
163 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL 
164 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
165 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
166 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
167 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
168 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
169 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID 
170 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
171
172 %token <tok> QNULLTERMINATED
173 %token <tok> QSETBUFFERSIZE
174 %token <tok> QBUFFERCONSTRAINT
175 %token <tok> QENSURESCONSTRAINT
176 %token <tok> QSETSTRINGLENGTH
177 %token <tok> QMAXSET
178 %token <tok> QMAXREAD
179 %token <tok> QTESTINRANGE
180
181
182
183 /* identifiers, literals */
184 %token <entry> IDENTIFIER
185 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID 
186 %token <expr>  CCONSTANT
187 %token <entry> ITER_NAME ITER_ENDNAME 
188 %type <entry> endIter 
189 %type <sr> globId
190 %token <ctyp>  TYPE_NAME 
191 %type <cname> enumerator newId  /*@-varuse@*/ /* yacc declares yytranslate here */
192 %type <count> pointers /*@=varuse@*/
193
194 %type <tok> doHeader specialTag endSpecialTag stateSpecialClause endStateTag 
195 %type <sck> specialClauseType
196
197 /* type construction */
198 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
199 %type <ctyp> suSpc enumSpc typeName typeSpecifier
200
201 %type <ntyp> namedDecl namedDeclBase optNamedDecl
202 %type <ntyp> plainNamedDecl plainNamedDeclBase
203 %type <ntyp> structNamedDecl
204 %type <ntyp> fcnDefHdrAux plainFcn
205
206 %type <oentry> paramDecl 
207 %type <entry> id 
208
209 %type <ntyplist> structNamedDeclList
210
211 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
212 %type <alist> argumentExprList iterArgList
213 %type <alist> initList
214 %type <flist> structDeclList structDecl
215 %type <srset> locModifies locPlainModifies modList specClauseList
216 %type <sr>    mExpr modListExpr specClauseListExpr
217
218 /*drl*/
219 %type <con>    BufConstraint
220 %type <tok> relationalOp
221 %type <tok> BufBinaryOp
222 %type <tok> bufferModifier
223
224 %type <conE> BufConstraintExpr
225
226 %type <conE> BufConstraintTerm
227 %type <sr> BufConstraintSrefExpr
228
229 %type <conL>    BufConstraintList
230
231 %type <tok>  BufUnaryOp
232
233 %type <enumnamelist> enumeratorList 
234 %type <cstringlist> fieldDesignator
235
236 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
237 %type <expr> openScope closeScope 
238 %type <expr> instanceDecl namedInitializer optDeclarators
239 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
240 %type <expr> unaryExpr castExpr timesExpr plusExpr
241 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
242 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
243 %type <expr> xorExpr bitorExpr andExpr
244 %type <expr> orExpr conditionalExpr assignExpr 
245 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
246 %type <expr> xorIterExpr bitorIterExpr andIterExpr
247 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
248 %type <expr> expr optExpr constantExpr
249 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
250 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
251 %type <expr> labeledStmt caseStmt defaultStmt 
252 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
253 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt 
254 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr 
255 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
256 %type <expr> tst1
257
258 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
259 %type <tquallist> optGlobQuals
260 %type <qtyp> completeType completeTypeSpecifier optCompleteType
261 %type <qtyp> completeTypeSpecifierAux altType typeExpression 
262 %type <expr> lclintassertion
263
264 %start file
265
266 %%
267
268 file
269  :              
270  | externalDefs
271
272 externalDefs
273  : externalDef
274  | externalDefs externalDef 
275
276 externalDef
277  : fcnDef optSemi { uentry_clearDecl (); } 
278  | constantDecl   { uentry_clearDecl (); } 
279  | fcnDecl        { uentry_clearDecl (); }
280  | iterDecl       { uentry_clearDecl (); } 
281  | macroDef       { uentry_clearDecl (); } 
282  | initializer    { uentry_checkDecl (); exprNode_free ($1); }
283  | error          { uentry_clearDecl (); } 
284
285 constantDecl
286  : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
287    { checkConstant ($2, $4); }
288  | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
289    { checkValueConstant ($2, $4, $8) ; }
290
291 fcnDecl
292  : QFUNCTION { context_enterFunctionDecl (); } plainFcn optSemi QENDMACRO 
293    { declareStaticFunction ($3); context_quietExitFunction (); 
294      context_exitFunctionDecl (); }
295
296 plainFcn
297  : plainNamedDecl
298    { 
299      qtype qint = qtype_create (ctype_int);
300      $$ = idDecl_fixBase ($1, qint);
301      qtype_free (qint);
302    }
303  | completeTypeSpecifier NotType plainNamedDecl
304    { $$ = idDecl_fixBase ($3, $1); }
305
306 plainNamedDecl
307  : plainNamedDeclBase
308  | pointers plainNamedDeclBase 
309    { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
310
311 namedDeclBase
312  : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
313  | IsType TLPAREN NotType namedDecl IsType TRPAREN
314    { $$ = idDecl_expectFunction ($4); }
315  | namedDeclBase TLSQBR TRSQBR 
316    { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
317  | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
318    { 
319      $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
320    }
321  | namedDeclBase PushType TLPAREN TRPAREN 
322    { setCurrentParams (uentryList_missingParams); 
323         }
324  optGlobMods  optGlobBufConstraints
325    { /* need to support globals and modifies here! */
326      ctype ct = ctype_makeFunction (idDecl_getCtype ($1), 
327                                     uentryList_makeMissingParams ());
328
329      $$ = idDecl_replaceCtype ($1, ct);
330      context_popLoc (); 
331    }
332  | namedDeclBase PushType TLPAREN genericParamList TRPAREN 
333    { setCurrentParams ($4); 
334         } 
335  optGlobMods  optGlobBufConstraints
336    { clearCurrentParams ();
337      $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
338      context_popLoc ();
339
340      //     printf("Done nameDeclBase\n");
341    }
342
343 plainNamedDeclBase
344  : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
345  | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
346    { $$ = idDecl_expectFunction ($4); }
347  | plainNamedDeclBase TLSQBR TRSQBR 
348    { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
349  | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
350    { 
351      int value;
352
353      if (exprNode_hasValue ($4) 
354          && multiVal_isInt (exprNode_getValue ($4)))
355        {
356          value = (int) multiVal_forceInt (exprNode_getValue ($4));
357        }
358      else
359        {
360          value = 0;
361        }
362
363      $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
364    }
365  | plainNamedDeclBase PushType TLPAREN TRPAREN 
366    { setCurrentParams (uentryList_missingParams); 
367         }
368    optPlainGlobMods 
369    { /* need to support globals and modifies here! */
370      ctype ct = ctype_makeFunction (idDecl_getCtype ($1), 
371                                     uentryList_makeMissingParams ());
372
373      $$ = idDecl_replaceCtype ($1, ct);
374      context_popLoc (); 
375    }
376  | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN 
377    { setCurrentParams ($4); 
378         } 
379    optPlainGlobMods
380    { clearCurrentParams ();
381      $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
382      context_popLoc (); 
383    }
384
385 iterDecl
386  : QITER newId TLPAREN genericParamList TRPAREN 
387    { setCurrentParams ($4); } optPlainGlobMods 
388    { clearCurrentParams (); } optSemi QENDMACRO
389    { declareCIter ($2, $4); }
390
391 macroDef
392  : LLMACRO macroBody TENDMACRO     { exprNode_checkMacroBody ($2); }
393  | LLMACROITER iterBody TENDMACRO  { exprNode_checkIterBody ($2); }
394  | LLMACROEND endBody TENDMACRO    { exprNode_checkIterEnd ($2); }
395  | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); } 
396
397 fcnDefHdr
398   : fcnDefHdrAux { declareFunction ($1); }
399
400 optGlobMods
401  : { setProcessingGlobMods (); } optGlobModsRest
402    { clearProcessingGlobMods (); }
403
404
405 /*drl*/
406
407 optGlobBufConstraints
408  : { setProcessingGlobMods (); } optGlobBufConstraintsRest
409    { clearProcessingGlobMods (); }
410
411
412 optGlobBufConstraintsRest
413  : optGlobBufConstraintsAux optGlobEnsuresConstraintsAux
414
415
416 optGlobEnsuresConstraintsAux
417 : {
418   DPRINTF ( ("doing optGlobEnsuresConstraintsAux\n") );
419 context_setProtectVars (); enterParamsTemp (); 
420      sRef_setGlobalScopeSafe (); 
421
422 }  QENSURESCONSTRAINT BufConstraintList  QENDMACRO
423 {
424   setEnsuresConstraints ($3);
425   exitParamsTemp ();
426      sRef_clearGlobalScopeSafe (); 
427      context_releaseVars ();
428   DPRINTF (("done optGlobBufConstraintsAux\n"));}
429  | /*empty*/
430
431
432 optGlobBufConstraintsAux
433 : {
434   DPRINTF ( ("doing optGlobBufConstraintsAux\n") );
435 context_setProtectVars (); enterParamsTemp (); 
436      sRef_setGlobalScopeSafe (); 
437
438 }  QBUFFERCONSTRAINT BufConstraintList  QENDMACRO
439 {
440   setFunctionConstraints ($3);
441   exitParamsTemp ();
442      sRef_clearGlobalScopeSafe (); 
443      context_releaseVars ();
444   DPRINTF (("done optGlobBufConstraintsAux\n"));}
445  | /*empty*/
446
447 BufConstraintList
448 : BufConstraint BufConstraintList{ $$ = constraintList_add ($2, $1); }
449 | BufConstraint {constraintList c; c = constraintList_new(); c = constraintList_add (c, $1); $$ = c}
450
451 BufConstraint
452 :  BufConstraintExpr relationalOp BufConstraintExpr TSEMI  {
453  $$ = makeConstraintParse3 ($1, $2, $3);
454  DPRINTF(("Done BufConstraint1\n")); }
455
456 bufferModifier
457  : QMAXSET
458  |QMAXREAD
459
460 relationalOp
461  : GE_OP
462  | LE_OP
463  | EQ_OP
464
465 BufConstraintExpr
466  : BufConstraintTerm 
467  | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3);  DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
468  | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
469    DPRINTF( ("Got BufConstraintExpr BINary Op ") );
470    $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
471
472 BufConstraintTerm
473 : BufConstraintSrefExpr { $$ =  constraintExpr_makeTermsRef($1);} 
474  | CCONSTANT {  char *t; int c;
475   t =  cstring_toCharsSafe (exprNode_unparse($1));
476   c = atoi( t );
477   $$ = constraintExpr_makeIntLiteral (c);
478 }
479
480
481 BufConstraintSrefExpr
482 : id                              {
483    $$ =
484      checkbufferConstraintClausesId ($1);}
485  | NEW_IDENTIFIER                  { $$ = fixSpecClausesId ($1); }
486
487  | BufConstraintSrefExpr TLSQBR TRSQBR       { $$ = sRef_makeAnyArrayFetch ($1); }
488  |  BufConstraintSrefExpr  TLSQBR CCONSTANT TRSQBR {
489      char *t; int c;
490   t =  cstring_toCharsSafe (exprNode_unparse($3));
491   c = atoi( t );
492    $$ = sRef_makeArrayFetchKnown($1, c); }
493  | TMULT  BufConstraintSrefExpr               { $$ = sRef_constructPointer ($2); }
494  | TLPAREN BufConstraintSrefExpr TRPAREN     { $$ = $2; }  
495  |  BufConstraintSrefExpr TDOT newId          { cstring_markOwned ($3);
496                                             $$ = sRef_buildField ($1, $3); }
497  |  BufConstraintSrefExpr ARROW_OP newId      { cstring_markOwned ($3);
498                                             $$ = sRef_makeArrow ($1, $3); }
499
500 /*
501 | BufConstraintTerm TLSQBR TRSQBR       { $$ = sRef_makeAnyArrayFetch ($1); }
502  | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
503  | TLPAREN specClauseListExpr TRPAREN     { $$ = $2; }  
504  | specClauseListExpr TDOT newId          { cstring_markOwned ($3);
505                                             $$ = sRef_buildField ($1, $3); }
506 */
507
508 /*BufConstraintExpr
509 : BufConstraintTerm 
510 */
511
512 BufUnaryOp
513 : bufferModifier 
514 ;
515
516 BufBinaryOp
517  : TPLUS
518 | TMINUS
519 ;
520
521
522 koptPlainGlobMods
523  : { setProcessingGlobMods (); } optPlainGlobModsRest
524    { clearProcessingGlobMods (); }
525
526
527 /*: id  {  $$ = unentry_getSref($1);  checkModifiesId ($1); }
528 | NEW_INDENTIFIER { $$ = fixModifiesId ($1)} */
529
530 /*end*/
531
532
533 optPlainGlobMods
534  : { setProcessingGlobMods (); } optPlainGlobModsRest
535    { clearProcessingGlobMods (); }
536
537 optGlobModsRest
538  : optGlobModsAux 
539  | specialClauses optGlobModsAux
540
541 optPlainGlobModsRest
542  : optPlainGlobModsAux 
543  | specialClauses optPlainGlobModsAux
544
545 specialClauses
546  : specialClause
547  | specialClause specialClauses
548  
549 globIdList
550  : globIdListExpr                     { ; }
551  | globIdList TCOMMA globIdListExpr   { ; }
552  
553 globIdListExpr 
554  : optGlobQuals globId { globListAdd ($2, $1); }
555
556 globId
557  : id             { $$ = uentry_getSref ($1); }
558  | NEW_IDENTIFIER { $$ = globListUnrecognized ($1); }
559
560 globQual
561  : QUNDEF   { $$ = qual_createUndef (); }
562  | QKILLED  { $$ = qual_createKilled (); }
563  | QOUT     { $$ = qual_createOut (); }
564  | QIN      { $$ = qual_createIn (); }
565  | QPARTIAL { $$ = qual_createPartial (); }
566
567 optGlobQuals
568  : /* empty */         { $$ = qualList_undefined; }
569  | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
570
571 optGlobModsAux  
572  : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi 
573    QENDMACRO optMods
574    { unsetProcessingGlobals (); }
575  | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi 
576    QENDMACRO optMods
577    { unsetProcessingGlobals (); }
578  | QNOMODS 
579    { setFunctionNoGlobals ();
580      setFunctionModifies (sRefSet_single (sRef_makeNothing ())); 
581    }
582  | fcnMods
583  | /* empty */
584
585 optPlainGlobModsAux
586  : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi 
587    optMods
588    { unsetProcessingGlobals (); }
589  | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi 
590    optMods
591    { unsetProcessingGlobals (); }
592  | QNOMODS 
593    { setFunctionNoGlobals ();
594      setFunctionModifies (sRefSet_single (sRef_makeNothing ())); 
595    }
596  | fcnPlainMods
597  | /* empty */
598
599 optMods
600  : fcnMods
601  | /* empty */
602
603 fcnMods
604  : QMODIFIES 
605    {
606      context_setProtectVars (); enterParamsTemp (); 
607      sRef_setGlobalScopeSafe (); 
608    }
609    locModifies
610    { 
611      setFunctionModifies ($3); exitParamsTemp ();
612      sRef_clearGlobalScopeSafe (); 
613      context_releaseVars ();
614    }
615
616 fcnPlainMods
617  : QMODIFIES 
618    {
619      context_setProtectVars (); enterParamsTemp (); 
620      sRef_setGlobalScopeSafe (); 
621    }
622    locPlainModifies
623    { 
624      setFunctionModifies ($3); exitParamsTemp ();
625      sRef_clearGlobalScopeSafe (); 
626      context_releaseVars ();
627    }
628
629 specialTag
630  : QDEFINES
631  | QUSES
632  | QALLOCATES
633  | QSETS
634  | QRELEASES
635
636 endStateTag
637  : QENDMACRO
638
639 endSpecialTag
640  : QENDMACRO
641
642 stateSpecialClause
643  : QPRECLAUSE
644  | QPOSTCLAUSE
645
646 specialClauseType
647  : QONLY       { $$ = SP_ISONLY; }
648  | QOBSERVER   { $$ = SP_ISOBSERVER; }
649  | QEXPOSED    { $$ = SP_ISEXPOSED; }
650  | QDEPENDENT  { $$ = SP_ISDEPENDENT; }
651  | QOWNED      { $$ = SP_ISOWNED; }
652  | QSHARED     { $$ = SP_ISSHARED; }
653  | QISNULL     { $$ = SP_ISNULL; }
654  | QNOTNULL    { $$ = SP_ISNOTNULL; }
655  
656 specialClause
657  : specialTag NotType
658    {
659      context_setProtectVars (); 
660      enterParamsTemp (); 
661      sRef_setGlobalScopeSafe (); 
662    }
663    specClauseList optSemi endSpecialTag IsType
664    { 
665      setFunctionSpecialClause ($1, $4, $6); 
666      exitParamsTemp ();
667      sRef_clearGlobalScopeSafe (); 
668      context_releaseVars ();
669    }
670   | stateSpecialClause NotType specialClauseType 
671     {
672       context_setProtectVars (); 
673       enterParamsTemp (); 
674       sRef_setGlobalScopeSafe (); 
675     }
676     specClauseList optSemi endStateTag IsType
677     { 
678       setFunctionStateSpecialClause ($1, $3, $5, $7); 
679       exitParamsTemp ();
680       sRef_clearGlobalScopeSafe (); 
681       context_releaseVars ();
682     }
683
684 fcnDefHdrAux
685  : namedDecl                               
686    { 
687      qtype qint = qtype_create (ctype_int);
688      $$ = idDecl_fixBase ($1, qint);
689      qtype_free (qint);
690    }
691  | completeTypeSpecifier NotType namedDecl 
692    { $$ = idDecl_fixBase ($3, $1); }
693  
694 fcnBody
695  : TLBRACE { checkDoneParams (); context_enterInnerContext (); } 
696    compoundStmtRest 
697    {  
698      exprNode_checkFunctionBody ($3); $$ = $3; 
699      context_exitInner ($3); 
700    }
701  | initializerList 
702    { doneParams (); context_enterInnerContext (); }
703    compoundStmt 
704    {
705      context_exitInner ($3);
706      exprNode_checkFunctionBody ($3); 
707      $$ = $3; /* old style */ 
708    } 
709  
710 fcnDef
711  : fcnDefHdr fcnBody 
712    { 
713      context_setFunctionDefined (exprNode_loc ($2)); 
714      /* exprNode_checkFunction (context_getHeader (), $2); */
715      /* DRL 8 8 2000 */
716      
717      context_exitFunction ();
718    }
719
720 locModifies
721  : modList optSemi QENDMACRO { $$ = $1; }
722  | optSemi QENDMACRO         { $$ = sRefSet_new (); }
723
724 locPlainModifies
725  : modList optSemi           { $$ = $1; }
726  | optSemi                   { $$ = sRefSet_new (); }
727  
728 modListExpr
729  : id                              { $$ = uentry_getSref ($1); checkModifiesId ($1); }
730  | NEW_IDENTIFIER                  { $$ = fixModifiesId ($1); }
731  | modListExpr TLSQBR TRSQBR       { $$ = modListArrayFetch ($1, sRef_undefined); }
732  | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
733  | TMULT modListExpr               { $$ = modListPointer ($2); }
734  | TLPAREN modListExpr TRPAREN     { $$ = $2; }  
735  | modListExpr TDOT newId          { $$ = modListFieldAccess ($1, $3); }
736  | modListExpr ARROW_OP newId      { $$ = modListArrowAccess ($1, $3); }
737
738
739 mExpr
740   : modListExpr { $$ = $1; }
741   | CCONSTANT   { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
742     /* arithmetic? */
743
744 modList
745   : modListExpr                { $$ = sRefSet_single ($1); }
746   | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
747
748 specClauseListExpr
749  : id                                     
750    { $$ = checkSpecClausesId ($1); }
751  | NEW_IDENTIFIER                         
752    { $$ = fixSpecClausesId ($1); }
753  | specClauseListExpr TLSQBR TRSQBR       { $$ = sRef_makeAnyArrayFetch ($1); }
754  | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
755  | TMULT specClauseListExpr               { $$ = sRef_constructPointer ($2); }
756  | TLPAREN specClauseListExpr TRPAREN     { $$ = $2; }  
757  | specClauseListExpr TDOT newId          { cstring_markOwned ($3);
758                                             $$ = sRef_buildField ($1, $3); }
759  | specClauseListExpr ARROW_OP newId      { cstring_markOwned ($3);
760                                             $$ = sRef_makeArrow ($1, $3); }
761
762 specClauseList
763   : specClauseListExpr                       
764     { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); } 
765       else { $$ = sRefSet_undefined; } 
766     }
767   | specClauseList TCOMMA specClauseListExpr 
768     { if (sRef_isValid ($3))
769         {
770           $$ = sRefSet_insert ($1, $3); 
771         }
772       else
773         {
774           $$ = $1;
775         }
776     }
777
778 primaryExpr
779  : id { $$ = exprNode_fromIdentifier ($1); }
780  | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); } 
781  | CCONSTANT      { $$ = $1; }
782  | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
783  | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); } 
784  | QEXTENSION { $$ = exprNode_makeError (); }
785  
786 postfixExpr
787  : primaryExpr 
788  | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
789  | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
790  | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
791  | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
792  | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
793  | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
794  | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
795  | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
796  
797 argumentExprList
798  : assignExpr { $$ = exprNodeList_singleton ($1); }
799  | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
800  
801 unaryExpr
802  : postfixExpr 
803  | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
804  | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
805  | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
806  | TMULT castExpr  { $$ = exprNode_preOp ($2, $1); }
807  | TPLUS castExpr  { $$ = exprNode_preOp ($2, $1); }
808  | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
809  | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
810  | TEXCL castExpr  { $$ = exprNode_preOp ($2, $1); }
811  | sizeofExpr      { $$ = $1; }
812  | offsetofExpr    { $$ = $1; }
813
814 fieldDesignator
815  : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
816  | newId                      { $$ = cstringList_single ($1); }
817
818 offsetofExpr
819  : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
820    { $$ = exprNode_offsetof ($4, $7); }
821
822 sizeofExpr
823  : IsType { context_setProtectVars (); } 
824    sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
825
826 sizeofExprAux 
827  : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); } 
828  | CSIZEOF unaryExpr                      { $$ = exprNode_sizeofExpr ($2); }
829  | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); } 
830  | CALIGNOF unaryExpr                      { $$ = exprNode_alignofExpr ($2); }
831  
832 castExpr
833  : unaryExpr 
834  | TLPAREN typeExpression TRPAREN castExpr 
835    { $$ = exprNode_cast ($1, $4, $2); } 
836  
837 timesExpr
838  : castExpr 
839  | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
840  | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
841  | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
842
843 plusExpr
844  : timesExpr 
845  | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
846  | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
847
848 shiftExpr
849  : plusExpr 
850  | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
851  | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
852
853 relationalExpr
854  : shiftExpr 
855  | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
856  | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
857  | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
858  | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
859  
860 equalityExpr 
861  : relationalExpr 
862  | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
863  | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
864
865 bitandExpr
866  : equalityExpr 
867  | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
868
869 xorExpr
870  : bitandExpr 
871  | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
872
873
874 bitorExpr
875  : xorExpr 
876  | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
877
878 andExpr 
879  : bitorExpr 
880  | andExpr AND_OP 
881    { exprNode_produceGuards ($1); 
882      context_enterAndClause ($1); 
883    } 
884    bitorExpr 
885    { 
886      $$ = exprNode_op ($1, $4, $2); 
887      context_exitAndClause ($$, $4);
888    }
889
890 orExpr
891  : andExpr 
892  | orExpr OR_OP 
893    { 
894      exprNode_produceGuards ($1);
895      context_enterOrClause ($1); 
896    } 
897    andExpr 
898    { 
899      $$ = exprNode_op ($1, $4, $2); 
900      context_exitOrClause ($$, $4);
901    }
902
903 conditionalExpr 
904  : orExpr 
905  | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON 
906    { context_enterFalseClause ($1); } conditionalExpr
907    { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
908
909 assignExpr
910  : conditionalExpr 
911  | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
912  | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
913  | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
914  | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
915  | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
916  | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
917  | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
918  | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
919  | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
920  | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
921  | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
922
923 expr
924  : assignExpr 
925  | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); } 
926
927 optExpr
928  : /* empty */ { $$ = exprNode_undefined; }
929  | expr 
930
931 constantExpr
932  : conditionalExpr 
933
934 /* instance_orTypeDecl_and_possible_initialization */
935
936 initializer
937  : instanceDecl { $$ = $1; }
938  | VA_DCL       { doVaDcl (); $$ = exprNode_makeError (); } 
939  | typeDecl     { $$ = exprNode_makeError (); }
940
941 instanceDecl
942  : completeTypeSpecifier IsType TSEMI { $$ = exprNode_makeError (); }
943     /*
944      ** This causes r/r conflicts with function definitions.
945      ** Instead we need to snarf one first. (gack)
946      **
947      ** | completeTypeSpecifier { setProcessingVars ($1); } 
948      ** NotType 
949      ** namedInitializerList IsType TSEMI 
950      ** { unsetProcessingVars (); }
951      **;
952      **
953      ** the solution is pretty ugly:
954      */
955  | completeTypeSpecifier NotType namedDecl NotType 
956    {
957                setProcessingVars ($1); 
958      processNamedDecl ($3); }
959    IsType optDeclarators TSEMI IsType { unsetProcessingVars (); $$ = $7; }
960  | completeTypeSpecifier NotType namedDecl NotType TASSIGN 
961    { setProcessingVars ($1); processNamedDecl ($3); 
962         }
963    IsType init optDeclarators TSEMI IsType 
964    { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8)); 
965      unsetProcessingVars ();
966    }
967 namedInitializer
968  : namedDecl NotType { processNamedDecl ($1); $$ = exprNode_makeError (); }
969  | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
970    { $$ = exprNode_makeInitialization ($1, $6); }
971
972
973 typeDecl
974  : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); } 
975    NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); } 
976  | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
977  | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ } 
978
979 IsType
980  : { g_expectingTypeName = TRUE; }
981
982 PushType
983  : { g_expectingTypeName = TRUE; context_pushLoc (); }
984
985 namedInitializerList
986  :  namedInitializerListAux IsType { ; }
987
988 namedInitializerListAux
989  : namedInitializer { ; }
990  | namedInitializerList TCOMMA NotType namedInitializer { ; }
991
992 optDeclarators
993  : /* empty */      { $$ = exprNode_makeError (); }
994  | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
995
996 init
997  : assignExpr                      { $$ = $1; }
998  | TLBRACE initList TRBRACE        { $$ = exprNode_makeInitBlock ($1, $2); }
999  | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1000
1001
1002 initList
1003  : init 
1004    { $$ = exprNodeList_singleton ($1); }
1005  | initList TCOMMA init 
1006    { $$ = exprNodeList_push ($1, $3); }
1007
1008 /*
1009 ** need to do the storage class global hack so tags are
1010 ** declared with the right storage class.
1011 */
1012
1013 storageSpecifier
1014  : QEXTERN   { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1015  | QINLINE   { $$ = qual_createInline (); }
1016  | QSTATIC   { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1017  | QAUTO     { $$ = qual_createAuto (); }
1018  | QREGISTER { $$ = qual_createRegister (); }
1019
1020 typeQualifier
1021  : QCONST IsType       { $$ = qual_createConst (); }
1022  | QVOLATILE IsType    { $$ = qual_createVolatile (); }
1023  | QOUT IsType         { $$ = qual_createOut (); }
1024  | QIN IsType          { $$ = qual_createIn (); }
1025  | QPARTIAL IsType     { $$ = qual_createPartial (); }
1026  | QSPECIAL IsType     { $$ = qual_createSpecial (); }
1027  | QOWNED IsType       { $$ = qual_createOwned (); }
1028  | QDEPENDENT IsType   { $$ = qual_createDependent (); }
1029  | QYIELD IsType       { $$ = qual_createYield (); }
1030  | QTEMP IsType        { $$ = qual_createTemp (); }
1031  | QONLY IsType        { $$ = qual_createOnly (); }
1032  | QKEEP IsType        { $$ = qual_createKeep (); }
1033  | QKEPT IsType        { $$ = qual_createKept (); }
1034  | QSHARED IsType      { $$ = qual_createShared (); }
1035  | QUNIQUE IsType      { $$ = qual_createUnique (); }
1036  | QEXITS IsType       { $$ = qual_createExits (); }
1037  | QMAYEXIT IsType     { $$ = qual_createMayExit (); }
1038  | QTRUEEXIT IsType    { $$ = qual_createTrueExit (); }
1039  | QFALSEEXIT IsType   { $$ = qual_createFalseExit (); }
1040  | QNEVEREXIT IsType   { $$ = qual_createNeverExit (); }
1041  | QNULL IsType        { $$ = qual_createNull (); }
1042  | QRELNULL IsType     { $$ = qual_createRelNull (); }
1043  | QRETURNED IsType    { $$ = qual_createReturned (); }
1044  | QEXPOSED IsType     { $$ = qual_createExposed (); }
1045  | QOBSERVER IsType    { $$ = qual_createObserver (); }
1046  | QCHECKED IsType     { $$ = qual_createChecked (); }
1047  | QCHECKMOD IsType    { $$ = qual_createCheckMod (); }
1048  | QUNCHECKED IsType   { $$ = qual_createUnchecked (); }
1049  | QCHECKEDSTRICT IsType  { $$ = qual_createCheckedStrict (); }
1050  | QTRUENULL IsType    { $$ = qual_createTrueNull (); }
1051  | QFALSENULL IsType   { $$ = qual_createFalseNull (); }
1052  | QUNUSED IsType      { $$ = qual_createUnused (); }
1053  | QEXTERNAL IsType    { $$ = qual_createExternal (); }
1054  | QSEF IsType         { $$ = qual_createSef (); }
1055  | QABSTRACT IsType    { $$ = qual_createAbstract (); }
1056  | QCONCRETE IsType    { $$ = qual_createConcrete (); }
1057  | QMUTABLE IsType     { $$ = qual_createMutable (); }
1058  | QIMMUTABLE IsType   { $$ = qual_createImmutable (); }
1059  | QNOTNULL IsType     { $$ = qual_createNotNull (); }
1060  | QREFCOUNTED IsType  { $$ = qual_createRefCounted (); }
1061  | QREFS IsType        { $$ = qual_createRefs (); }
1062  | QKILLREF IsType     { $$ = qual_createKillRef (); }
1063  | QRELDEF IsType      { $$ = qual_createRelDef (); }
1064  | QNEWREF IsType      { $$ = qual_createNewRef (); }
1065  | QTEMPREF IsType     { $$ = qual_createTempRef (); }
1066  | QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1067
1068 /* | QSETBUFFERSIZE IsType { $$ = qual_createSetBufferSize (); } */
1069
1070
1071 typeModifier
1072  : QSHORT            { $$ = qual_createShort (); }
1073  | QLONG             { $$ = qual_createLong (); }
1074  | QSIGNED           { $$ = qual_createSigned (); }
1075  | QUNSIGNED         { $$ = qual_createUnsigned (); }
1076
1077 typeSpecifier
1078  : CGCHAR NotType 
1079  | CINT NotType 
1080  | CBOOL NotType
1081  | CGFLOAT NotType
1082  | CDOUBLE NotType
1083  | CVOID NotType 
1084  | QANYTYPE NotType              { $$ = ctype_unknown; }
1085  | QINTEGRALTYPE NotType         { $$ = ctype_anyintegral; }
1086  | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1087  | QSIGNEDINTEGRALTYPE NotType   { $$ = ctype_signedintegral; }
1088  | typeName NotType     
1089  | suSpc NotType 
1090  | enumSpc NotType
1091  | typeModifier NotType { $$ = ctype_fromQual ($1); }
1092
1093 completeType
1094  : IsType completeTypeSpecifier IsType
1095    { $$ = qtype_resolve ($2); }
1096
1097 completeTypeSpecifier
1098  : completeTypeSpecifierAux { $$ = $1; }
1099  | completeTypeSpecifierAux QALT altType QENDMACRO  
1100    { $$ = qtype_mergeAlt ($1, $3); }
1101
1102 altType
1103  : typeExpression
1104  | typeExpression TCOMMA altType
1105    { $$ = qtype_mergeAlt ($1, $3); } 
1106
1107 completeTypeSpecifierAux
1108  : storageSpecifier optCompleteType        { $$ = qtype_addQual ($2, $1); }
1109  | typeQualifier optCompleteType           { $$ = qtype_addQual ($2, $1); } 
1110  | typeSpecifier optCompleteType           { $$ = qtype_combine ($2, $1); }
1111
1112 optCompleteType
1113  : /* empty */                             { $$ = qtype_unknown (); }
1114  | completeTypeSpecifier                   { $$ = $1; }
1115
1116 suSpc
1117  : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); } 
1118    CreateStructInnerScope 
1119    structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1120    TRBRACE 
1121    { $$ = declareStruct ($3, $8); }
1122  | NotType CUNION  newId IsType TLBRACE { sRef_setGlobalScopeSafe (); } 
1123    CreateStructInnerScope 
1124    structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); } 
1125    TRBRACE
1126    { $$ = declareUnion ($3, $8); } 
1127  | NotType CSTRUCT newId IsType TLBRACE TRBRACE 
1128    { $$ = declareStruct ($3, uentryList_new ()); }
1129  | NotType CUNION  newId IsType TLBRACE TRBRACE 
1130    { $$ = declareUnion ($3, uentryList_new ()); }
1131  | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); } 
1132    CreateStructInnerScope 
1133    structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1134    TRBRACE 
1135    { $$ = declareUnnamedStruct ($7); }
1136  | NotType CUNION  IsType TLBRACE { sRef_setGlobalScopeSafe (); } 
1137    CreateStructInnerScope 
1138    structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1139    TRBRACE 
1140    { $$ = declareUnnamedUnion ($7); } 
1141  | NotType CSTRUCT IsType TLBRACE TRBRACE
1142    { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1143  | NotType CUNION  IsType TLBRACE TRBRACE 
1144    { $$ = ctype_createUnnamedUnion (uentryList_new ()); } 
1145  | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); } 
1146  | NotType CUNION  newId NotType { $$ = handleUnion ($3); }
1147
1148 NotType
1149  : { g_expectingTypeName = FALSE; }
1150
1151 structDeclList
1152  : structDecl 
1153  | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1154  | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1155
1156 structDecl
1157  : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI 
1158    { $$ = fixUentryList ($3, $1); }
1159  | completeTypeSpecifier IsType TSEMI 
1160    { $$ = fixUnnamedDecl ($1); }
1161
1162 structNamedDeclList 
1163  : structNamedDecl NotType                            
1164    { $$ = idDeclList_singleton ($1); }
1165  | structNamedDeclList TCOMMA structNamedDecl NotType
1166    { $$ = idDeclList_add ($1, $3); }
1167
1168 structNamedDecl  /* hack to get around namespace problems */ 
1169  : namedDecl                            { $$ = $1; }
1170  | TCOLON IsType constantExpr           { $$ = idDecl_undefined; }
1171  | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1172    /* Need the IsType in case there is a cast in the constant expression. */
1173
1174 enumSpc
1175  : NotType CENUM TLBRACE enumeratorList TRBRACE IsType 
1176    { $$ = declareUnnamedEnum ($4); }
1177  | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1178    { context_popLoc (); $$ = declareEnum ($3, $6); }
1179  | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1180
1181 enumeratorList
1182  : enumerator 
1183    { $$ = enumNameList_single ($1); }
1184  | enumeratorList TCOMMA enumerator 
1185    { $$ = enumNameList_push ($1, $3); }
1186  | enumeratorList TCOMMA
1187
1188 enumerator
1189  : newId 
1190    { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1191      usymtab_supGlobalEntry (ue);
1192      $$ = $1;
1193    }
1194  | newId TASSIGN IsType constantExpr 
1195    { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1196      usymtab_supGlobalEntry (ue);
1197      $$ = $1; 
1198    }
1199
1200 optNamedDecl
1201  : namedDeclBase
1202  | optAbstractDeclBase   { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1203  | pointers TYPE_NAME    
1204    { 
1205      qtype qt = qtype_unknown ();
1206
1207      qtype_adjustPointers ($1, qt);
1208      $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1209    }
1210  | pointers optNamedDecl 
1211    { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1212
1213 namedDecl
1214  : namedDeclBase
1215  | pointers namedDeclBase 
1216    { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1217
1218 genericParamList
1219  : paramTypeList       { $$ = handleParamTypeList ($1); }
1220  | NotType paramIdList { $$ = handleParamIdList ($2); }  
1221
1222 innerMods
1223  : QCONST    { /* ignored for now */; }
1224  | QVOLATILE { ; }
1225
1226 innerModsList
1227  : innerMods { ; }
1228  | innerModsList innerMods { ; }
1229
1230 pointers
1231  : TMULT { $$ = 1; }
1232  | TMULT innerModsList { $$ = 1; }
1233  | TMULT pointers { $$ = 1 + $2; }
1234  | TMULT innerModsList pointers { $$ = 1 + $3; }
1235
1236 paramIdList
1237  : idList 
1238  | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1239
1240 idList
1241  : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1242  | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1243
1244 paramTypeList
1245  : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1246  | paramList 
1247  | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1248
1249 paramList
1250  : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1251  | paramList TCOMMA { storeLoc (); } paramDecl 
1252    { $$ = uentryList_add ($1, $4); }
1253
1254 paramDecl
1255  : IsType completeTypeSpecifier optNamedDecl IsType
1256    { 
1257      if (isFlipOldStyle ()) 
1258        { 
1259          llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)")); 
1260        }
1261      else 
1262        { 
1263          setNewStyle (); 
1264        }
1265      $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2)); 
1266    }
1267  | newId /* its an old-style declaration */
1268    { 
1269      idDecl tparam = idDecl_create ($1, qtype_unknown ());
1270
1271      if (isNewStyle ()) 
1272        {
1273          llparseerror (message ("Inconsistent function parameter syntax: %q",
1274                                 idDecl_unparse (tparam))); 
1275        }
1276
1277      setFlipOldStyle ();
1278      $$ = makeCurrentParam (tparam);
1279      idDecl_free (tparam);
1280    } 
1281
1282 typeExpression
1283  : completeType
1284  | completeType abstractDecl  { $$ = qtype_newBase ($1, $2); }
1285
1286 abstractDecl
1287  : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1288  | abstractDeclBase
1289  | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1290
1291 optAbstractDeclBase
1292  : /* empty */ { $$ = ctype_unknown; }
1293  | abstractDeclBase 
1294
1295 abstractDeclBase
1296  : IsType TLPAREN NotType abstractDecl TRPAREN 
1297    { $$ = ctype_expectFunction ($4); }
1298  | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1299  | TLSQBR constantExpr TRSQBR 
1300    { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1301  | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1302  | abstractDeclBase TLSQBR constantExpr TRSQBR 
1303    { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1304  | IsType TLPAREN TRPAREN 
1305    { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1306  | IsType TLPAREN paramTypeList TRPAREN 
1307    { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1308  | abstractDeclBase IsType TLPAREN TRPAREN 
1309    { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }  
1310  | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN 
1311    { $$ = ctype_makeParamsFunction ($1, $4); }  
1312
1313 /* statement */
1314
1315 stmt
1316  : labeledStmt 
1317  | caseStmt 
1318  | defaultStmt
1319  | compoundStmt 
1320  | expressionStmt
1321  | selectionStmt 
1322  | iterationStmt 
1323  | iterStmt
1324  | jumpStmt 
1325 /*  | tst1 */
1326  | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }
1327
1328
1329 lclintassertion
1330  : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n");  uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1331   }
1332  | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n");  uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1333   }
1334  | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n");  uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1335   }
1336
1337 /* | QSETBUFFERSIZE id id  {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1338
1339 tst1
1340 : TCOLON newId { $$ = exprNode_labelMarker ($2); }
1341
1342
1343
1344 iterBody
1345  : iterDefStmtList { $$ = $1; }
1346
1347 endBody
1348  : iterBody
1349
1350 iterDefStmtList
1351  : iterDefStmt                 
1352  | iterDefStmtList iterDefStmt 
1353    { $$ = exprNode_concat ($1, $2); }
1354
1355 iterDefIterationStmt
1356  : iterWhilePred iterDefStmtList         
1357    { $$ = exprNode_while ($1, $2); }
1358  | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI 
1359    { $$ = exprNode_doWhile ($2, $5); }
1360  | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1361    { $$ = exprNode_doWhile ($2, $5); }
1362  | forPred iterDefStmt
1363    { $$ = exprNode_for ($1, $2); } 
1364
1365 forPred
1366  : CFOR TLPAREN optExpr TSEMI optExpr TSEMI 
1367    { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1368    TRPAREN 
1369    { $$ = exprNode_forPred ($3, $5, $8); 
1370      context_enterForClause ($5); }
1371
1372 partialIterStmt
1373  : ITER_NAME CreateInnerScope TLPAREN 
1374    { setProcessingIterVars ($1); } 
1375    iterArgList TRPAREN 
1376    { $$ = exprNode_iterStart ($1, $5); }
1377  | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1378
1379 iterDefStmt
1380  : labeledStmt 
1381  | caseStmt 
1382  | defaultStmt
1383  | openScope initializerList { $$ = $2; }
1384  | openScope
1385  | closeScope
1386  | expressionStmt
1387  | iterSelectionStmt 
1388  | iterDefIterationStmt 
1389  | partialIterStmt
1390  | jumpStmt 
1391  | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1392  | error { $$ = exprNode_makeError (); }
1393
1394 iterSelectionStmt
1395  : ifPred iterDefStmt 
1396    { /* don't: context_exitTrueClause ($1, $2); */
1397      $$ = exprNode_if ($1, $2); 
1398    }
1399
1400 openScope
1401  : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1402
1403 closeScope
1404  : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1405
1406 macroBody
1407  : stmtErr    
1408  | stmtListErr
1409  
1410 stmtErr
1411  : labeledStmt
1412  | caseStmt 
1413  | defaultStmt 
1414  | compoundStmtErr
1415  | expressionStmtErr
1416  | selectionStmt 
1417  | iterStmt
1418  | iterationStmtErr
1419  | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1420  | jumpStmt 
1421  | error { $$ = exprNode_makeError (); }
1422
1423 labeledStmt
1424  : newId TCOLON      { $$ = exprNode_labelMarker ($1); }
1425  | QNOTREACHED stmt  { $$ = exprNode_notReached ($2); }
1426
1427 /* Note that we can semantically check that the object to the case is
1428  indeed constant. In this case, we may not want to go through this effort */
1429
1430 caseStmt
1431  : CASE constantExpr { context_enterCaseClause ($2); } 
1432    TCOLON            { $$ = exprNode_caseMarker ($2, FALSE); }
1433  | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); } 
1434    TCOLON            { $$ = exprNode_caseMarker ($3, TRUE); }
1435
1436 defaultStmt
1437  : DEFAULT { context_enterCaseClause (exprNode_undefined); } 
1438    TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1439  | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); } 
1440    TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1441
1442 compoundStmt
1443  : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1444  | CreateInnerScope compoundStmtAux 
1445    { $$ = $2; context_exitInner ($2); }
1446
1447 compoundStmtErr
1448  : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1449
1450 CreateInnerScope
1451  : { context_enterInnerContext (); }
1452
1453 DeleteInnerScope
1454  : { context_exitInnerPlain (); }
1455
1456 CreateStructInnerScope
1457  : { context_enterStructInnerContext (); }
1458
1459 DeleteStructInnerScope
1460  : { context_exitStructInnerContext (); }
1461
1462 DeleteInnerScopeSafe
1463  : { context_exitInnerSafe (); }
1464
1465 compoundStmtRest
1466  : TRBRACE { $$ = exprNode_createTok ($1); }
1467  | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1468  | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1469  | stmtList QNOTREACHED TRBRACE 
1470    { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1471  | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1472  | initializerList QNOTREACHED TRBRACE 
1473    { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1474  | initializerList stmtList TRBRACE
1475    { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1476  | initializerList stmtList QNOTREACHED TRBRACE
1477    { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2), 
1478                                                         lltok_getLoc ($3))); 
1479    }
1480
1481
1482 compoundStmtAux
1483  : TLBRACE compoundStmtRest 
1484    { $$ = exprNode_makeBlock ($2); }
1485
1486 compoundStmtAuxErr
1487  : TLBRACE TRBRACE 
1488    { $$ = exprNode_createTok ($2); }
1489  | TLBRACE stmtListErr TRBRACE 
1490    { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1491  | TLBRACE initializerList TRBRACE 
1492    { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1493  | TLBRACE initializerList stmtList TRBRACE 
1494    { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1495
1496 stmtListErr
1497  : stmtErr 
1498  | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1499
1500 initializerList
1501  : initializer { $$ = $1; }
1502  | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1503
1504 stmtList
1505  : stmt { $$ = $1; }
1506  | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1507  
1508 expressionStmt 
1509  : TSEMI { $$ = exprNode_createTok ($1); }
1510  | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1511
1512 expressionStmtErr
1513  : TSEMI { $$ = exprNode_createTok ($1); }
1514  | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1515  | expr { $$ = exprNode_checkExpr ($1); } 
1516
1517 ifPred
1518  : CIF TLPAREN expr TRPAREN 
1519    { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1520  /*
1521  ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN 
1522  **             { $$ = $3; context_enterTrueClause (); } 
1523  */
1524
1525 selectionStmt
1526  : ifPred stmt 
1527    { 
1528      context_exitTrueClause ($1, $2);
1529      $$ = exprNode_if ($1, $2); 
1530    }
1531  | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt 
1532    {
1533      context_exitClause ($1, $2, $5);
1534      $$ = exprNode_ifelse ($1, $2, $5); 
1535    }
1536  | SWITCH TLPAREN expr { context_enterSwitch ($3); } 
1537    TRPAREN stmt        { $$ = exprNode_switch ($3, $6); }
1538  
1539 whilePred
1540  : WHILE TLPAREN expr TRPAREN 
1541    { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1542    /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1543
1544 iterWhilePred
1545  : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1546
1547 iterStmt
1548  : ITER_NAME { context_enterIterClause (); } 
1549    CreateInnerScope TLPAREN { setProcessingIterVars ($1); } 
1550    iterArgList TRPAREN 
1551    compoundStmt endIter DeleteInnerScope
1552    { 
1553      $$ = exprNode_iter ($1, $6, $8, $9); 
1554
1555    } 
1556  
1557 iterArgList 
1558  : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1559  | iterArgList { nextIterParam (); } TCOMMA iterArgExpr 
1560    { $$ = exprNodeList_push ($1, $4); }
1561
1562 iterArgExpr
1563   : assignIterExpr  { $$ = exprNode_iterExpr ($1); }
1564   | id              { $$ = exprNode_iterId ($1); }
1565   | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1566
1567                       if (uentry_isValid (ue)) 
1568                         {
1569                           $$ = exprNode_iterId (ue);
1570                         }
1571                       else
1572                         {
1573                           $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1574                         }
1575                     }
1576   | NEW_IDENTIFIER  { $$ = exprNode_iterNewId ($1); }
1577
1578 /*
1579 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER 
1580 */
1581
1582 primaryIterExpr
1583  : CCONSTANT 
1584  | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1585  
1586 postfixIterExpr
1587  : primaryIterExpr 
1588  | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1589  | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1590  | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1591  | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1592        { $$ = exprNode_vaArg ($1, $3, $5); }
1593  | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
1594  | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
1595  | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1596  | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1597  
1598 unaryIterExpr
1599  : postfixIterExpr 
1600  | INC_OP unaryExpr    { $$ = exprNode_preOp ($2, $1); }
1601  | DEC_OP unaryExpr    { $$ = exprNode_preOp ($2, $1); }
1602  | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1603  | TMULT castExpr      { $$ = exprNode_preOp ($2, $1); }
1604  | TPLUS castExpr      { $$ = exprNode_preOp ($2, $1); }
1605  | TMINUS castExpr     { $$ = exprNode_preOp ($2, $1); }
1606  | TTILDE castExpr     { $$ = exprNode_preOp ($2, $1); }
1607  | TEXCL castExpr      { $$ = exprNode_preOp ($2, $1); }
1608  | sizeofExpr          { $$ = $1; }
1609
1610 castIterExpr
1611  : unaryIterExpr 
1612  | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); } 
1613  
1614 timesIterExpr
1615  : castIterExpr 
1616  | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1617  | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1618  | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1619
1620 plusIterExpr
1621  : timesIterExpr 
1622  | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1623  | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1624
1625 shiftIterExpr
1626  : plusIterExpr 
1627  | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1628  | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1629
1630 relationalIterExpr
1631  : shiftIterExpr 
1632  | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1633  | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1634  | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1635  | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1636  
1637 equalityIterExpr 
1638  : relationalIterExpr 
1639  | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1640  | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1641
1642 bitandIterExpr
1643  : equalityIterExpr 
1644  | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1645
1646 xorIterExpr
1647  : bitandIterExpr 
1648  | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1649
1650
1651 bitorIterExpr
1652  : xorIterExpr 
1653  | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1654
1655 andIterExpr 
1656  : bitorIterExpr 
1657  | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1658
1659 orIterExpr
1660  : andIterExpr 
1661  | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1662
1663 conditionalIterExpr 
1664  : orIterExpr 
1665  | orExpr TQUEST { context_enterTrueClause ($1); } 
1666    expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1667    { $$ = exprNode_cond ($1, $4, $7); }
1668
1669 assignIterExpr
1670  : conditionalIterExpr 
1671  | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1672  | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1673  | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1674  | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1675  | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1676  | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1677  | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1678  | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1679  | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1680  | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1681  | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); } 
1682
1683 endIter
1684  : ITER_ENDNAME { $$ = $1; }
1685  | /* empty */  { $$ = uentry_undefined; } 
1686
1687 doHeader
1688  : DO { context_enterDoWhileClause (); $$ = $1; }
1689   
1690 iterationStmt 
1691  : whilePred stmt 
1692    { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1693  | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI 
1694    { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1695  | forPred stmt 
1696    { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1697
1698 iterationStmtErr 
1699  : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1700  | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1701    { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1702  | doHeader stmtErr WHILE TLPAREN expr TRPAREN 
1703    { $$ = exprNode_doWhile ($2, $5); }
1704  | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1705  
1706 jumpStmt
1707  : GOTO newId TSEMI         { $$ = exprNode_goto ($2); }
1708  | CONTINUE TSEMI           { $$ = exprNode_continue ($1, BADTOK); }
1709  | QINNERCONTINUE CONTINUE TSEMI    
1710                             { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1711  | BREAK TSEMI              { $$ = exprNode_break ($1, BADTOK); }
1712  | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1713  | QLOOPBREAK BREAK TSEMI   { $$ = exprNode_break ($2, QLOOPBREAK); }
1714  | QINNERBREAK BREAK TSEMI  { $$ = exprNode_break ($2, QINNERBREAK); }
1715  | QSAFEBREAK BREAK TSEMI   { $$ = exprNode_break ($2, QSAFEBREAK); }
1716  | RETURN TSEMI             { $$ = exprNode_nullReturn ($1); }
1717  | RETURN expr TSEMI        { $$ = exprNode_return ($2); }
1718  
1719 optSemi
1720  : 
1721  | TSEMI { ; } 
1722
1723 id
1724  : IDENTIFIER 
1725
1726 newId
1727  : NEW_IDENTIFIER 
1728  | ITER_NAME       { $$ = uentry_getName ($1); }
1729  | ITER_ENDNAME    { $$ = uentry_getName ($1); }
1730  | id              { $$ = uentry_getName ($1); }
1731  | TYPE_NAME_OR_ID { $$ = $1; } 
1732
1733 typeName
1734  : TYPE_NAME
1735  | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1736
1737 %%
1738
1739 /*@-redecl@*/
1740 extern char *yytext;
1741 /*@=redecl@*/
1742
1743 # include "bison.reset"
1744
1745 void yyerror (/*@unused@*/ char *s) 
1746 {
1747   static bool givehint = FALSE;
1748
1749   if (context_inIterDef ())
1750     {
1751       llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s", 
1752                                     context_inFunctionName ()));
1753     }
1754   else if (context_inIterEnd ())
1755     {
1756       llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s", 
1757                                     context_inFunctionName ()));
1758     }
1759   else if (context_inMacro ())
1760     {
1761       llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s", 
1762                                     context_inFunctionName ()));
1763       
1764       if (context_inMacroUnknown ())
1765         {
1766           if (!givehint)
1767             {
1768               llhint (cstring_makeLiteral 
1769                      ("Precede macro definition with /*@notfunction@*/ "
1770                       "to suppress checking and force expansion"));
1771               givehint = TRUE;
1772             }
1773         }
1774
1775       swallowMacro ();
1776     }
1777   else
1778     {
1779       llparseerror (cstring_undefined);
1780     }
1781 }
1782
1783 void printState (idDecl t) {
1784  cstring id = idDecl_getName (t);
1785  uentry ue = usymtab_lookupSafe (id);
1786
1787  sRef s = uentry_getSref (ue);
1788  
1789  printf("State = %d\n", s->bufinfo.bufstate);
1790 }
1791
1792
1793 /*take this out soon */
1794 /* void testassert1 (cstring id, icstring cons ) { */
1795  /*   uentry ue =usymtab_lookupSafe (id); */
1796 /*   sRef s = uentry_getSref (ue); */
1797 /*   printf ("Doing testassert1 with setbuffersize\n"); */
1798 /*   printf("State = %d\n", s->bufinfo.bufstate); */
1799 /* } */
1800 /* void testassert2 (cstring id) { */
1801 /*    uentry ue =usymtab_lookupSafe (id); */
1802 /*   sRef s = uentry_getSref (ue); */
1803 /*   printf ("Doing testassert2 with setbuffersize\n"); */
1804 /*   printf("State = %d\n", s->bufinfo.bufstate); */
1805 /* } */
1806   
1807
1808
1809
1810
1811
This page took 0.172972 seconds and 5 git commands to generate.