2 ** Copyright (c) Massachusetts Institute of Technology 1994-1998.
3 ** All Rights Reserved.
4 ** Unpublished rights reserved under the copyright laws of
7 ** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 ** OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 ** This code is distributed freely and may be used freely under the
11 ** following conditions:
13 ** 1. This notice may not be removed or altered.
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).
24 ** Yacc/Bison grammar for extended ANSI C used by LCLint.
26 ** original grammar by Nate Osgood ---
27 ** hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
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
35 ** production names are cryptic, so more productions fit on one line
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
45 extern void swallowMacro (void);
47 # include "lclintMacros.nf"
49 # include "cgrammar.h"
50 # include "exprChecks.h"
55 # define SHOWCSYM FALSE
56 void yyerror (char *s);
59 ** This is necessary, or else when the bison-generated code #include's malloc.h,
60 ** there will be a parse error.
62 ** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
63 ** in bison-generated files under Win32.
72 void checkandsetBufState(idDecl id, exprNode is);
79 specialClauseKind sck;
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;
99 /* standard C tokens */
101 %token <tok> BADTOK SKIPTOK
102 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
103 %token <tok> GOTO CONTINUE BREAK RETURN
104 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
105 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
106 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
107 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
108 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
109 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
110 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
111 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
112 %token <tok> CSTRUCT CUNION CENUM
113 %token <tok> VA_ARG VA_DCL
114 %token <tok> QGLOBALS
115 %token <tok> QMODIFIES
117 %token <tok> QCONSTANT
118 %token <tok> QFUNCTION
120 %token <tok> QDEFINES
122 %token <tok> QALLOCATES
124 %token <tok> QRELEASES
125 %token <tok> QPRECLAUSE
126 %token <tok> QPOSTCLAUSE
128 %token <tok> QUNDEF QKILLED
129 %token <tok> QENDMACRO
131 /* additional tokens introduced by lclint pre-processor. */
132 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
134 /* break comments: */
135 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
136 %token <tok> QINNERCONTINUE
138 /* case fall-through marker: */
139 %token <tok> QFALLTHROUGH
141 /* used in scanner only */
142 %token <tok> QLINTNOTREACHED
143 %token <tok> QLINTFALLTHROUGH
144 %token <tok> QLINTFALLTHRU
145 %token <tok> QARGSUSED
146 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
148 /* not-reached marker: (used like a label) */
149 %token <tok> QNOTREACHED
151 /* type qualifiers: */
152 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
153 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
154 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
155 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
156 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
157 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
158 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
159 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
160 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
161 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
162 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
163 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
164 %token <tok> QNULLTERMINATED
166 /* identifiers, literals */
167 %token <entry> IDENTIFIER
168 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
169 %token <expr> CCONSTANT
170 %token <entry> ITER_NAME ITER_ENDNAME
171 %type <entry> endIter
173 %token <ctyp> TYPE_NAME
174 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
175 %type <count> pointers /*@=varuse@*/
177 %type <tok> doHeader specialTag endSpecialTag stateSpecialClause endStateTag
178 %type <sck> specialClauseType
180 /* type construction */
181 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
182 %type <ctyp> suSpc enumSpc typeName typeSpecifier
184 %type <ntyp> namedDecl namedDeclBase optNamedDecl
185 %type <ntyp> plainNamedDecl plainNamedDeclBase
186 %type <ntyp> structNamedDecl
187 %type <ntyp> fcnDefHdrAux plainFcn
189 %type <oentry> paramDecl
192 %type <ntyplist> structNamedDeclList
194 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
195 %type <alist> argumentExprList iterArgList
196 %type <alist> initList
197 %type <flist> structDeclList structDecl
198 %type <srset> locModifies locPlainModifies modList specClauseList
199 %type <sr> mExpr modListExpr specClauseListExpr
200 %type <enumnamelist> enumeratorList
201 %type <cstringlist> fieldDesignator
203 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
204 %type <expr> openScope closeScope
205 %type <expr> instanceDecl namedInitializer optDeclarators
206 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
207 %type <expr> unaryExpr castExpr timesExpr plusExpr
208 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
209 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
210 %type <expr> xorExpr bitorExpr andExpr
211 %type <expr> orExpr conditionalExpr assignExpr
212 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
213 %type <expr> xorIterExpr bitorIterExpr andIterExpr
214 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
215 %type <expr> expr optExpr constantExpr
216 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
217 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
218 %type <expr> labeledStmt caseStmt defaultStmt
219 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
220 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
221 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
222 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
224 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
225 %type <tquallist> optGlobQuals
226 %type <qtyp> completeType completeTypeSpecifier optCompleteType
227 %type <qtyp> completeTypeSpecifierAux altType typeExpression
239 | externalDefs externalDef
242 : fcnDef optSemi { uentry_clearDecl (); }
243 | constantDecl { uentry_clearDecl (); }
244 | fcnDecl { uentry_clearDecl (); }
245 | iterDecl { uentry_clearDecl (); }
246 | macroDef { uentry_clearDecl (); }
247 | initializer { uentry_checkDecl (); exprNode_free ($1); }
248 | error { uentry_clearDecl (); }
251 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
252 { checkConstant ($2, $4); }
253 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
254 { checkValueConstant ($2, $4, $8) ; }
257 : QFUNCTION { context_enterFunctionDecl (); } plainFcn optSemi QENDMACRO
258 { declareStaticFunction ($3); context_quietExitFunction ();
259 context_exitFunctionDecl (); }
264 qtype qint = qtype_create (ctype_int);
265 $$ = idDecl_fixBase ($1, qint);
268 | completeTypeSpecifier NotType plainNamedDecl
269 { $$ = idDecl_fixBase ($3, $1); }
273 | pointers plainNamedDeclBase
274 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
277 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
278 | IsType TLPAREN NotType namedDecl IsType TRPAREN
279 { $$ = idDecl_expectFunction ($4); }
280 | namedDeclBase TLSQBR TRSQBR
281 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
282 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
286 if (exprNode_hasValue ($4)
287 && multiVal_isInt (exprNode_getValue ($4)))
289 value = (int) multiVal_forceInt (exprNode_getValue ($4));
296 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
298 | namedDeclBase PushType TLPAREN TRPAREN
299 { setCurrentParams (uentryList_missingParams);
302 { /* need to support globals and modifies here! */
303 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
304 uentryList_makeMissingParams ());
306 $$ = idDecl_replaceCtype ($1, ct);
309 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
310 { setCurrentParams ($4);
313 { clearCurrentParams ();
314 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
319 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
320 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
321 { $$ = idDecl_expectFunction ($4); }
322 | plainNamedDeclBase TLSQBR TRSQBR
323 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
324 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
328 if (exprNode_hasValue ($4)
329 && multiVal_isInt (exprNode_getValue ($4)))
331 value = (int) multiVal_forceInt (exprNode_getValue ($4));
338 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
340 | plainNamedDeclBase PushType TLPAREN TRPAREN
341 { setCurrentParams (uentryList_missingParams);
344 { /* need to support globals and modifies here! */
345 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
346 uentryList_makeMissingParams ());
348 $$ = idDecl_replaceCtype ($1, ct);
351 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
352 { setCurrentParams ($4);
355 { clearCurrentParams ();
356 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
361 : QITER newId TLPAREN genericParamList TRPAREN
362 { setCurrentParams ($4); } optPlainGlobMods
363 { clearCurrentParams (); } optSemi QENDMACRO
364 { declareCIter ($2, $4); }
367 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
368 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
369 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
370 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
373 : fcnDefHdrAux { declareFunction ($1); }
376 : { setProcessingGlobMods (); } optGlobModsRest
377 { clearProcessingGlobMods (); }
380 : { setProcessingGlobMods (); } optPlainGlobModsRest
381 { clearProcessingGlobMods (); }
385 | specialClauses optGlobModsAux
388 : optPlainGlobModsAux
389 | specialClauses optPlainGlobModsAux
393 | specialClause specialClauses
396 : globIdListExpr { ; }
397 | globIdList TCOMMA globIdListExpr { ; }
400 : optGlobQuals globId { globListAdd ($2, $1); }
403 : id { $$ = uentry_getSref ($1); }
404 | NEW_IDENTIFIER { $$ = globListUnrecognized ($1); }
407 : QUNDEF { $$ = qual_createUndef (); }
408 | QKILLED { $$ = qual_createKilled (); }
409 | QOUT { $$ = qual_createOut (); }
410 | QIN { $$ = qual_createIn (); }
411 | QPARTIAL { $$ = qual_createPartial (); }
414 : /* empty */ { $$ = qualList_undefined; }
415 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
418 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
420 { unsetProcessingGlobals (); }
421 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
423 { unsetProcessingGlobals (); }
425 { setFunctionNoGlobals ();
426 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
432 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
434 { unsetProcessingGlobals (); }
435 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
437 { unsetProcessingGlobals (); }
439 { setFunctionNoGlobals ();
440 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
452 context_setProtectVars (); enterParamsTemp ();
453 sRef_setGlobalScopeSafe ();
457 setFunctionModifies ($3); exitParamsTemp ();
458 sRef_clearGlobalScopeSafe ();
459 context_releaseVars ();
465 context_setProtectVars (); enterParamsTemp ();
466 sRef_setGlobalScopeSafe ();
470 setFunctionModifies ($3); exitParamsTemp ();
471 sRef_clearGlobalScopeSafe ();
472 context_releaseVars ();
493 : QONLY { $$ = SP_ISONLY; }
494 | QOBSERVER { $$ = SP_ISOBSERVER; }
495 | QEXPOSED { $$ = SP_ISEXPOSED; }
496 | QDEPENDENT { $$ = SP_ISDEPENDENT; }
497 | QOWNED { $$ = SP_ISOWNED; }
498 | QSHARED { $$ = SP_ISSHARED; }
499 | QISNULL { $$ = SP_ISNULL; }
500 | QNOTNULL { $$ = SP_ISNOTNULL; }
505 context_setProtectVars ();
507 sRef_setGlobalScopeSafe ();
509 specClauseList optSemi endSpecialTag IsType
511 setFunctionSpecialClause ($1, $4, $6);
513 sRef_clearGlobalScopeSafe ();
514 context_releaseVars ();
516 | stateSpecialClause NotType specialClauseType
518 context_setProtectVars ();
520 sRef_setGlobalScopeSafe ();
522 specClauseList optSemi endStateTag IsType
524 setFunctionStateSpecialClause ($1, $3, $5, $7);
526 sRef_clearGlobalScopeSafe ();
527 context_releaseVars ();
533 qtype qint = qtype_create (ctype_int);
534 $$ = idDecl_fixBase ($1, qint);
537 | completeTypeSpecifier NotType namedDecl
538 { $$ = idDecl_fixBase ($3, $1); }
541 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
544 exprNode_checkFunctionBody ($3); $$ = $3;
545 context_exitInner ($3);
548 { doneParams (); context_enterInnerContext (); }
551 context_exitInner ($3);
552 exprNode_checkFunctionBody ($3);
553 $$ = $3; /* old style */
559 context_setFunctionDefined (exprNode_loc ($2));
560 exprNode_checkFunction (context_getHeader (), $2);
561 context_exitFunction ();
565 : modList optSemi QENDMACRO { $$ = $1; }
566 | optSemi QENDMACRO { $$ = sRefSet_new (); }
569 : modList optSemi { $$ = $1; }
570 | optSemi { $$ = sRefSet_new (); }
573 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
574 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
575 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
576 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
577 | TMULT modListExpr { $$ = modListPointer ($2); }
578 | TLPAREN modListExpr TRPAREN { $$ = $2; }
579 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
580 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
584 : modListExpr { $$ = $1; }
585 | CCONSTANT { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
589 : modListExpr { $$ = sRefSet_single ($1); }
590 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
594 { $$ = checkSpecClausesId ($1); }
596 { $$ = fixSpecClausesId ($1); }
597 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
598 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
599 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
600 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
601 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
602 $$ = sRef_buildField ($1, $3); }
603 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
604 $$ = sRef_makeArrow ($1, $3); }
608 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
609 else { $$ = sRefSet_undefined; }
611 | specClauseList TCOMMA specClauseListExpr
612 { if (sRef_isValid ($3))
614 $$ = sRefSet_insert ($1, $3);
623 : id { $$ = exprNode_fromIdentifier ($1); }
624 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
625 | CCONSTANT { $$ = $1; }
626 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
627 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
628 | QEXTENSION { $$ = exprNode_makeError (); }
632 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
633 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
634 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
635 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
636 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
637 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
638 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
639 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
642 : assignExpr { $$ = exprNodeList_singleton ($1); }
643 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
647 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
648 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
649 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
650 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
651 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
652 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
653 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
654 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
655 | sizeofExpr { $$ = $1; }
656 | offsetofExpr { $$ = $1; }
659 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
660 | newId { $$ = cstringList_single ($1); }
663 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
664 { $$ = exprNode_offsetof ($4, $7); }
667 : IsType { context_setProtectVars (); }
668 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
671 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
672 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
673 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
674 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
678 | TLPAREN typeExpression TRPAREN castExpr
679 { $$ = exprNode_cast ($1, $4, $2); }
683 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
684 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
685 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
689 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
690 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
694 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
695 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
699 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
700 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
701 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
702 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
706 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
707 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
711 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
715 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
720 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
725 { exprNode_produceGuards ($1);
726 context_enterAndClause ($1);
730 $$ = exprNode_op ($1, $4, $2);
731 context_exitAndClause ($$, $4);
738 exprNode_produceGuards ($1);
739 context_enterOrClause ($1);
743 $$ = exprNode_op ($1, $4, $2);
744 context_exitOrClause ($$, $4);
749 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
750 { context_enterFalseClause ($1); } conditionalExpr
751 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
755 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
756 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
757 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
758 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
759 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
760 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
761 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
762 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
763 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
764 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
765 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
769 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
772 : /* empty */ { $$ = exprNode_undefined; }
778 /* instance_orTypeDecl_and_possible_initialization */
781 : instanceDecl { $$ = $1; }
782 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
783 | typeDecl { $$ = exprNode_makeError (); }
786 : completeTypeSpecifier IsType TSEMI { $$ = exprNode_makeError (); }
788 ** This causes r/r conflicts with function definitions.
789 ** Instead we need to snarf one first. (gack)
791 ** | completeTypeSpecifier { setProcessingVars ($1); }
793 ** namedInitializerList IsType TSEMI
794 ** { unsetProcessingVars (); }
797 ** the solution is pretty ugly:
799 | completeTypeSpecifier NotType namedDecl NotType
801 setProcessingVars ($1);
802 processNamedDecl ($3); }
803 IsType optDeclarators TSEMI IsType { unsetProcessingVars (); $$ = $7; }
804 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
805 { setProcessingVars ($1); processNamedDecl ($3);
807 IsType init optDeclarators TSEMI IsType
808 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
809 unsetProcessingVars ();
812 : namedDecl NotType { processNamedDecl ($1); $$ = exprNode_makeError (); }
813 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
814 { $$ = exprNode_makeInitialization ($1, $6); }
818 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
819 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
820 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
821 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
824 : { g_expectingTypeName = TRUE; }
827 : { g_expectingTypeName = TRUE; context_pushLoc (); }
830 : namedInitializerListAux IsType { ; }
832 namedInitializerListAux
833 : namedInitializer { ; }
834 | namedInitializerList TCOMMA NotType namedInitializer { ; }
837 : /* empty */ { $$ = exprNode_makeError (); }
838 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
841 : assignExpr { $$ = $1; }
842 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
843 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
848 { $$ = exprNodeList_singleton ($1); }
849 | initList TCOMMA init
850 { $$ = exprNodeList_push ($1, $3); }
853 ** need to do the storage class global hack so tags are
854 ** declared with the right storage class.
858 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
859 | QINLINE { $$ = qual_createInline (); }
860 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
861 | QAUTO { $$ = qual_createAuto (); }
862 | QREGISTER { $$ = qual_createRegister (); }
865 : QCONST IsType { $$ = qual_createConst (); }
866 | QVOLATILE IsType { $$ = qual_createVolatile (); }
867 | QOUT IsType { $$ = qual_createOut (); }
868 | QIN IsType { $$ = qual_createIn (); }
869 | QPARTIAL IsType { $$ = qual_createPartial (); }
870 | QSPECIAL IsType { $$ = qual_createSpecial (); }
871 | QOWNED IsType { $$ = qual_createOwned (); }
872 | QDEPENDENT IsType { $$ = qual_createDependent (); }
873 | QYIELD IsType { $$ = qual_createYield (); }
874 | QTEMP IsType { $$ = qual_createTemp (); }
875 | QONLY IsType { $$ = qual_createOnly (); }
876 | QKEEP IsType { $$ = qual_createKeep (); }
877 | QKEPT IsType { $$ = qual_createKept (); }
878 | QSHARED IsType { $$ = qual_createShared (); }
879 | QUNIQUE IsType { $$ = qual_createUnique (); }
880 | QEXITS IsType { $$ = qual_createExits (); }
881 | QMAYEXIT IsType { $$ = qual_createMayExit (); }
882 | QTRUEEXIT IsType { $$ = qual_createTrueExit (); }
883 | QFALSEEXIT IsType { $$ = qual_createFalseExit (); }
884 | QNEVEREXIT IsType { $$ = qual_createNeverExit (); }
885 | QNULL IsType { $$ = qual_createNull (); }
886 | QRELNULL IsType { $$ = qual_createRelNull (); }
887 | QRETURNED IsType { $$ = qual_createReturned (); }
888 | QEXPOSED IsType { $$ = qual_createExposed (); }
889 | QOBSERVER IsType { $$ = qual_createObserver (); }
890 | QCHECKED IsType { $$ = qual_createChecked (); }
891 | QCHECKMOD IsType { $$ = qual_createCheckMod (); }
892 | QUNCHECKED IsType { $$ = qual_createUnchecked (); }
893 | QCHECKEDSTRICT IsType { $$ = qual_createCheckedStrict (); }
894 | QTRUENULL IsType { $$ = qual_createTrueNull (); }
895 | QFALSENULL IsType { $$ = qual_createFalseNull (); }
896 | QUNUSED IsType { $$ = qual_createUnused (); }
897 | QEXTERNAL IsType { $$ = qual_createExternal (); }
898 | QSEF IsType { $$ = qual_createSef (); }
899 | QABSTRACT IsType { $$ = qual_createAbstract (); }
900 | QCONCRETE IsType { $$ = qual_createConcrete (); }
901 | QMUTABLE IsType { $$ = qual_createMutable (); }
902 | QIMMUTABLE IsType { $$ = qual_createImmutable (); }
903 | QNOTNULL IsType { $$ = qual_createNotNull (); }
904 | QREFCOUNTED IsType { $$ = qual_createRefCounted (); }
905 | QREFS IsType { $$ = qual_createRefs (); }
906 | QKILLREF IsType { $$ = qual_createKillRef (); }
907 | QRELDEF IsType { $$ = qual_createRelDef (); }
908 | QNEWREF IsType { $$ = qual_createNewRef (); }
909 | QTEMPREF IsType { $$ = qual_createTempRef (); }
910 | QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
913 : QSHORT { $$ = qual_createShort (); }
914 | QLONG { $$ = qual_createLong (); }
915 | QSIGNED { $$ = qual_createSigned (); }
916 | QUNSIGNED { $$ = qual_createUnsigned (); }
925 | QANYTYPE NotType { $$ = ctype_unknown; }
926 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
927 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
928 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
932 | typeModifier NotType { $$ = ctype_fromQual ($1); }
935 : IsType completeTypeSpecifier IsType
936 { $$ = qtype_resolve ($2); }
938 completeTypeSpecifier
939 : completeTypeSpecifierAux { $$ = $1; }
940 | completeTypeSpecifierAux QALT altType QENDMACRO
941 { $$ = qtype_mergeAlt ($1, $3); }
945 | typeExpression TCOMMA altType
946 { $$ = qtype_mergeAlt ($1, $3); }
948 completeTypeSpecifierAux
949 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
950 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
951 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
954 : /* empty */ { $$ = qtype_unknown (); }
955 | completeTypeSpecifier { $$ = $1; }
958 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
959 CreateStructInnerScope
960 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
962 { $$ = declareStruct ($3, $8); }
963 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
964 CreateStructInnerScope
965 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
967 { $$ = declareUnion ($3, $8); }
968 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
969 { $$ = declareStruct ($3, uentryList_new ()); }
970 | NotType CUNION newId IsType TLBRACE TRBRACE
971 { $$ = declareUnion ($3, uentryList_new ()); }
972 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
973 CreateStructInnerScope
974 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
976 { $$ = declareUnnamedStruct ($7); }
977 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
978 CreateStructInnerScope
979 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
981 { $$ = declareUnnamedUnion ($7); }
982 | NotType CSTRUCT IsType TLBRACE TRBRACE
983 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
984 | NotType CUNION IsType TLBRACE TRBRACE
985 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
986 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
987 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
990 : { g_expectingTypeName = FALSE; }
994 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
995 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
998 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
999 { $$ = fixUentryList ($3, $1); }
1000 | completeTypeSpecifier IsType TSEMI
1001 { $$ = fixUnnamedDecl ($1); }
1004 : structNamedDecl NotType
1005 { $$ = idDeclList_singleton ($1); }
1006 | structNamedDeclList TCOMMA structNamedDecl NotType
1007 { $$ = idDeclList_add ($1, $3); }
1009 structNamedDecl /* hack to get around namespace problems */
1010 : namedDecl { $$ = $1; }
1011 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1012 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1013 /* Need the IsType in case there is a cast in the constant expression. */
1016 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1017 { $$ = declareUnnamedEnum ($4); }
1018 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1019 { context_popLoc (); $$ = declareEnum ($3, $6); }
1020 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1024 { $$ = enumNameList_single ($1); }
1025 | enumeratorList TCOMMA enumerator
1026 { $$ = enumNameList_push ($1, $3); }
1027 | enumeratorList TCOMMA
1031 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1032 usymtab_supGlobalEntry (ue);
1035 | newId TASSIGN IsType constantExpr
1036 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1037 usymtab_supGlobalEntry (ue);
1043 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1044 | pointers TYPE_NAME
1046 qtype qt = qtype_unknown ();
1048 qtype_adjustPointers ($1, qt);
1049 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1051 | pointers optNamedDecl
1052 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1056 | pointers namedDeclBase
1057 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1060 : paramTypeList { $$ = handleParamTypeList ($1); }
1061 | NotType paramIdList { $$ = handleParamIdList ($2); }
1064 : QCONST { /* ignored for now */; }
1069 | innerModsList innerMods { ; }
1073 | TMULT innerModsList { $$ = 1; }
1074 | TMULT pointers { $$ = 1 + $2; }
1075 | TMULT innerModsList pointers { $$ = 1 + $3; }
1079 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1082 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1083 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1086 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1088 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1091 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1092 | paramList TCOMMA { storeLoc (); } paramDecl
1093 { $$ = uentryList_add ($1, $4); }
1096 : IsType completeTypeSpecifier optNamedDecl IsType
1098 if (isFlipOldStyle ())
1100 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1106 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1108 | newId /* its an old-style declaration */
1110 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1114 llparseerror (message ("Inconsistent function parameter syntax: %q",
1115 idDecl_unparse (tparam)));
1119 $$ = makeCurrentParam (tparam);
1120 idDecl_free (tparam);
1125 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1128 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1130 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1133 : /* empty */ { $$ = ctype_unknown; }
1137 : IsType TLPAREN NotType abstractDecl TRPAREN
1138 { $$ = ctype_expectFunction ($4); }
1139 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1140 | TLSQBR constantExpr TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1141 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1142 | abstractDeclBase TLSQBR constantExpr TRSQBR { $$ = ctype_makeArray ($1); }
1143 | IsType TLPAREN TRPAREN
1144 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1145 | IsType TLPAREN paramTypeList TRPAREN
1146 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1147 | abstractDeclBase IsType TLPAREN TRPAREN
1148 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1149 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1150 { $$ = ctype_makeParamsFunction ($1, $4); }
1166 : iterDefStmtList { $$ = $1; }
1173 | iterDefStmtList iterDefStmt
1174 { $$ = exprNode_concat ($1, $2); }
1176 iterDefIterationStmt
1177 : iterWhilePred iterDefStmtList
1178 { $$ = exprNode_while ($1, $2); }
1179 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1180 { $$ = exprNode_doWhile ($2, $5); }
1181 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1182 { $$ = exprNode_doWhile ($2, $5); }
1183 | forPred iterDefStmt
1184 { $$ = exprNode_for ($1, $2); }
1187 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1188 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1190 { $$ = exprNode_forPred ($3, $5, $8);
1191 context_enterForClause ($5); }
1194 : ITER_NAME CreateInnerScope TLPAREN
1195 { setProcessingIterVars ($1); }
1197 { $$ = exprNode_iterStart ($1, $5); }
1198 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1204 | openScope initializerList { $$ = $2; }
1209 | iterDefIterationStmt
1212 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1213 | error { $$ = exprNode_makeError (); }
1216 : ifPred iterDefStmt
1217 { /* don't: context_exitTrueClause ($1, $2); */
1218 $$ = exprNode_if ($1, $2);
1222 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1225 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1240 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1242 | error { $$ = exprNode_makeError (); }
1245 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1246 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1248 /* Note that we can semantically check that the object to the case is
1249 indeed constant. In this case, we may not want to go through this effort */
1252 : CASE constantExpr { context_enterCaseClause ($2); }
1253 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1254 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1255 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1258 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1259 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1260 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1261 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1264 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1265 | CreateInnerScope compoundStmtAux
1266 { $$ = $2; context_exitInner ($2); }
1269 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1272 : { context_enterInnerContext (); }
1275 : { context_exitInnerPlain (); }
1277 CreateStructInnerScope
1278 : { context_enterStructInnerContext (); }
1280 DeleteStructInnerScope
1281 : { context_exitStructInnerContext (); }
1283 DeleteInnerScopeSafe
1284 : { context_exitInnerSafe (); }
1287 : TRBRACE { $$ = exprNode_createTok ($1); }
1288 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1289 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1290 | stmtList QNOTREACHED TRBRACE
1291 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1292 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1293 | initializerList QNOTREACHED TRBRACE
1294 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1295 | initializerList stmtList TRBRACE
1296 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1297 | initializerList stmtList QNOTREACHED TRBRACE
1298 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1299 lltok_getLoc ($3)));
1304 : TLBRACE compoundStmtRest
1305 { $$ = exprNode_makeBlock ($2); }
1309 { $$ = exprNode_createTok ($2); }
1310 | TLBRACE stmtListErr TRBRACE
1311 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1312 | TLBRACE initializerList TRBRACE
1313 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1314 | TLBRACE initializerList stmtList TRBRACE
1315 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1319 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1322 : initializer { $$ = $1; }
1323 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1327 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1330 : TSEMI { $$ = exprNode_createTok ($1); }
1331 | expr TSEMI { $$ = exprNode_statement ($1); }
1334 : TSEMI { $$ = exprNode_createTok ($1); }
1335 | expr TSEMI { $$ = exprNode_statement ($1); }
1336 | expr { $$ = exprNode_checkExpr ($1); }
1339 : CIF TLPAREN expr TRPAREN
1340 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1342 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1343 ** { $$ = $3; context_enterTrueClause (); }
1349 context_exitTrueClause ($1, $2);
1350 $$ = exprNode_if ($1, $2);
1352 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1354 context_exitClause ($1, $2, $5);
1355 $$ = exprNode_ifelse ($1, $2, $5);
1357 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1358 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1361 : WHILE TLPAREN expr TRPAREN
1362 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1363 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1366 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1369 : ITER_NAME { context_enterIterClause (); }
1370 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1372 compoundStmt endIter DeleteInnerScope
1374 $$ = exprNode_iter ($1, $6, $8, $9);
1379 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1380 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1381 { $$ = exprNodeList_push ($1, $4); }
1384 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1385 | id { $$ = exprNode_iterId ($1); }
1386 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1388 if (uentry_isValid (ue))
1390 $$ = exprNode_iterId (ue);
1394 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1397 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1400 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1405 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1409 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1410 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1411 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1412 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1413 { $$ = exprNode_vaArg ($1, $3, $5); }
1414 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
1415 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
1416 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1417 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1421 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1422 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1423 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1424 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1425 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1426 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1427 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1428 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1429 | sizeofExpr { $$ = $1; }
1433 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1437 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1438 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1439 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1443 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1444 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1448 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1449 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1453 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1454 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1455 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1456 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1459 : relationalIterExpr
1460 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1461 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1465 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1469 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1474 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1478 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1482 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1486 | orExpr TQUEST { context_enterTrueClause ($1); }
1487 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1488 { $$ = exprNode_cond ($1, $4, $7); }
1491 : conditionalIterExpr
1492 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1493 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1494 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1495 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1496 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1497 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1498 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1499 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1500 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1501 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1502 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1505 : ITER_ENDNAME { $$ = $1; }
1506 | /* empty */ { $$ = uentry_undefined; }
1509 : DO { context_enterDoWhileClause (); $$ = $1; }
1513 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1514 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1515 { $$ = exprNode_statement (exprNode_doWhile ($2, $5)); }
1517 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1520 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1521 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1522 { $$ = exprNode_statement (exprNode_doWhile ($2, $5)); }
1523 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1524 { $$ = exprNode_doWhile ($2, $5); }
1525 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1528 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1529 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1530 | QINNERCONTINUE CONTINUE TSEMI
1531 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1532 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1533 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1534 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1535 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1536 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1537 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1538 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1549 | ITER_NAME { $$ = uentry_getName ($1); }
1550 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1551 | id { $$ = uentry_getName ($1); }
1552 | TYPE_NAME_OR_ID { $$ = $1; }
1556 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1561 extern char *yytext;
1564 # include "bison.reset"
1566 void yyerror (/*@unused@*/ char *s)
1568 static bool givehint = FALSE;
1570 if (context_inIterDef ())
1572 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1573 context_inFunctionName ()));
1575 else if (context_inIterEnd ())
1577 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1578 context_inFunctionName ()));
1580 else if (context_inMacro ())
1582 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1583 context_inFunctionName ()));
1585 if (context_inMacroUnknown ())
1589 llhint (cstring_makeLiteral
1590 ("Precede macro definition with /*@notfunction@*/ "
1591 "to suppress checking and force expansion"));
1600 llparseerror (cstring_undefined);
1604 void printState (idDecl t) {
1605 cstring id = idDecl_getName (t);
1606 uentry ue = usymtab_lookupSafe (id);
1608 sRef s = uentry_getSref (ue);
1610 printf("State = %d\n", s->bufinfo.bufstate);