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).
20 ** Copyright (c) Massachusetts Institute of Technology, 1993
21 ** All Rights Reserved. Unpublished rights reserved
22 ** under the copyright laws of the United States.
26 ** MODULE DESCRIPTION:
28 ** FILENAME: signature.y
30 ** PURPOSE: bison grammar for LSL signatures.
33 ** Yang Meng Tan, Massachusetts Institute of Technology
39 # include "lclintMacros.nf"
41 # include "lslparse.h"
42 # include "signature.h"
44 void lslerror (char *);
45 /*@dependent@*/ /*@null@*/ lslOp importedlslOp;
47 /*@-noparams@*/ /* Can't list params since YYSTYPE isn't defined yet. */
48 static void yyprint (/*FILE *p_file, int p_type, YYSTYPE p_value */);
51 # define YYPRINT(file, type, value) yyprint (file, type, value)
63 /* CONVENTIONS: Reserved words are in ALL CAPS (plus markerSym)
64 Characters appearing in the grammar are reserved:
68 - added LBRACKET stuff in OpForm (missing in LSL)
69 - dif from LCL: open vs openSym, close vs closeSym
70 - yylval vs yylval.tok
74 ltoken ltok; /* a leaf is also an ltoken */
76 /*@only@*/ ltokenList ltokenList;
77 /*@only@*/ opFormNode opform;
78 /*@owned@*/ sigNode signature;
79 /*@only@*/ nameNode name;
80 /*@owned@*/ lslOp operator;
81 /*@only@*/ lslOpList operators;
82 /*@-redef@*/ /*@-matchfields@*/
84 /*@=redef@*/ /*@=matchfields@*/
86 %token <ltok> LST_SIMPLEID
87 %token <ltok> LST_LOGICALOP /* \implies, \and, \not, \or */
88 %token <ltok> LST_EQOP /* \eq, \neq, ==, != */
89 %token <ltok> LST_SIMPLEOP /* opSym - reserved */
90 %token <ltok> LST_MAPSYM /* LSL's -> */
91 /* FIELDMAPSYM = "\\field_arrow", only for LCL symtable import */
92 %token <ltok> LST_FIELDMAPSYM /* LCL's struct field operator -> */
93 %token <ltok> LST_MARKERSYM /* \marker, __ */
94 %token <ltok> LST_ifTOKEN LST_thenTOKEN LST_elseTOKEN
95 /* different from LSL: separate LBRACKET from openSym and
96 RBRACKET from closeSym */
97 %token <ltok> LST_LBRACKET LST_RBRACKET
98 %token <ltok> LST_SELECTSYM /* \select or . */
99 %token <ltok> LST_SEPSYM LST_OPENSYM LST_CLOSESYM
100 %token <ltok> LST_COLON /* : */
101 %token <ltok> LST_COMMA /* , */
102 %token <ltok> LST_EOL LST_COMMENTSYM LST_WHITESPACE
104 %token LST_WHITESPACE
105 %token LST_QUANTIFIERSYM
106 %token LST_EQUATIONSYM
108 %token LST_COMPOSESYM
111 %token LST_assertsTOKEN
112 %token LST_assumesTOKEN
114 %token LST_convertsTOKEN
115 %token LST_enumerationTOKEN
116 %token LST_equationsTOKEN
117 %token LST_exemptingTOKEN
119 %token LST_generatedTOKEN
120 %token LST_impliesTOKEN
121 %token LST_includesTOKEN
122 %token LST_introducesTOKEN
124 %token LST_partitionedTOKEN
125 %token LST_traitTOKEN
126 %token LST_tupleTOKEN
127 %token LST_unionTOKEN
130 %type <ltok> anyOp separator sortId opId
131 %type <count> middle placeList
132 %type <ltokenList> domain sortList
133 %type <opform> opForm
134 %type <signature> signature
136 %type <operator> operator
137 %type <operators> operatorList top
141 top: operatorList { lslOpList_free ($1); }
143 operatorList: operator
144 { lslOpList x = lslOpList_new ();
145 g_importedlslOp = $1;
146 lslOpList_add (x, $1);
148 | operatorList operator
149 { lslOpList_add ($1, $2);
152 operator: name LST_COLON signature
153 { $$ = makelslOpNode ($1, $3); }
154 /* The next production is never used in the output of lsl -syms
156 { $$ = makelslOpNode ($1, (sigNode)0); } */
158 name: opId /* check for the case of if_then_else */
159 { $$ = makeNameNodeId ($1); }
161 { $$ = makeNameNodeForm ($1); }
164 : LST_ifTOKEN LST_MARKERSYM LST_thenTOKEN LST_MARKERSYM LST_elseTOKEN LST_MARKERSYM
165 { $$ = makeOpFormNode ($1, OPF_IF, opFormUnion_createMiddle (0), ltoken_undefined); }
167 { $$ = makeOpFormNode ($1, OPF_ANYOP, opFormUnion_createAnyOp ($1), ltoken_undefined); }
168 | LST_MARKERSYM anyOp
169 { $$ = makeOpFormNode ($1, OPF_MANYOP, opFormUnion_createAnyOp ($2), ltoken_undefined); }
170 | anyOp LST_MARKERSYM
171 { $$ = makeOpFormNode ($1, OPF_ANYOPM, opFormUnion_createAnyOp ($1), ltoken_undefined); }
172 | LST_MARKERSYM anyOp LST_MARKERSYM
173 { $$ = makeOpFormNode ($1, OPF_MANYOPM, opFormUnion_createAnyOp ($2), ltoken_undefined); }
174 | LST_OPENSYM middle LST_CLOSESYM
175 { $$ = makeOpFormNode ($1, OPF_MIDDLE, opFormUnion_createMiddle ($2), $3); }
176 | LST_MARKERSYM LST_OPENSYM middle LST_CLOSESYM
177 { $$ = makeOpFormNode ($2, OPF_MMIDDLE, opFormUnion_createMiddle ($3), $4); }
178 | LST_OPENSYM middle LST_CLOSESYM LST_MARKERSYM
179 { $$ = makeOpFormNode ($1, OPF_MIDDLEM, opFormUnion_createMiddle ($2), $3); }
180 | LST_MARKERSYM LST_OPENSYM middle LST_CLOSESYM LST_MARKERSYM
181 { $$ = makeOpFormNode ($2, OPF_MMIDDLEM,
182 opFormUnion_createMiddle ($3), $4); }
183 | LST_LBRACKET middle LST_RBRACKET
184 { $$ = makeOpFormNode ($1, OPF_BMIDDLE,
185 opFormUnion_createMiddle ($2), $3); }
186 | LST_MARKERSYM LST_LBRACKET middle LST_RBRACKET
187 { $$ = makeOpFormNode ($2, OPF_BMMIDDLE,
188 opFormUnion_createMiddle ($3), $4); }
189 | LST_LBRACKET middle LST_RBRACKET LST_MARKERSYM
190 { $$ = makeOpFormNode ($1, OPF_BMIDDLEM,
191 opFormUnion_createMiddle ($2), $3); }
192 | LST_MARKERSYM LST_LBRACKET middle LST_RBRACKET LST_MARKERSYM
193 { $$ = makeOpFormNode ($2, OPF_BMMIDDLEM,
194 opFormUnion_createMiddle ($3), $4); }
195 | LST_SELECTSYM LST_SIMPLEID
196 { $$ = makeOpFormNode ($1, OPF_SELECT,
197 opFormUnion_createAnyOp ($2), ltoken_undefined); }
198 | LST_MARKERSYM LST_SELECTSYM LST_SIMPLEID
199 { $$ = makeOpFormNode ($1, OPF_MSELECT,
200 opFormUnion_createAnyOp ($3), ltoken_undefined); }
201 /* not in LSL, need FILEDMAPSYM to distinguish it from MAPSYM */
202 /* LST_FIELDMAPSYM = "\\field_arrow", only for LCL symtable import */
203 | LST_MARKERSYM LST_FIELDMAPSYM LST_SIMPLEID
204 { $$ = makeOpFormNode ($1, OPF_MMAP,
205 opFormUnion_createAnyOp ($3), ltoken_undefined); }
220 placeList: LST_MARKERSYM
222 | placeList separator LST_MARKERSYM
230 signature: domain LST_MAPSYM sortId
231 { $$ = makesigNode ($2, $1, $3); }
234 { $$ = ltokenList_new (); }
239 { $$ = ltokenList_singleton ($1); }
240 | sortList LST_COMMA sortId
241 { $$ = ltokenList_push ($1, $3); }
246 ltoken_setText ($$, processTraitSortId (ltoken_getText ($1)));
253 # include "bison.reset"
257 void lslerror (char *s)
261 ("There has been a problem in the parser with LSL signatures. This is believed to result "
262 "from a problem with bison v. 1.25. Please try rebuidling LCLint "
263 "using the pre-compiled grammar files by commenting out the "
264 "BISON= line in the top-level Makefile."));
267 static void yyprint (FILE *file, int type, YYSTYPE value)
269 fprintf (file, " (%u:%u type: %d; text: %s) ",
270 ltoken_getLine (value.ltok),
271 ltoken_getCol (value.ltok),
273 ltoken_getRawTextChars (value.ltok));
276 extern void PrintToken (ltoken tok) {
279 switch (ltoken_getCode (tok))
281 case NOTTOKEN: codStr = "*** NOTTOKEN ***"; break;
282 case LST_QUANTIFIERSYM: codStr = "QUANTIFIERSYM"; break;
283 case LST_LOGICALOP: codStr = "LOGICALOP: "; break;
284 case LST_SELECTSYM: codStr = "LST_SELECTSYM"; break;
285 case LST_OPENSYM: codStr = "LST_OPENSYM"; break;
286 case LST_SEPSYM: codStr = "SEPSYM"; break;
287 case LST_CLOSESYM: codStr = "LST_CLOSESYM"; break;
288 case LST_SIMPLEID: codStr = "LST_SIMPLEID"; break;
289 case LST_MAPSYM: codStr = "MAPSYM"; break;
290 case LST_MARKERSYM: codStr = "LST_MARKERSYM"; break;
291 case LST_COMMENTSYM: codStr = "COMMENTSYM"; break;
292 case LST_SIMPLEOP: codStr = "SIMPLEOP"; break;
293 case LST_COLON: codStr = "LST_COLON"; break;
294 case LST_COMMA: codStr = "COMMA"; break;
295 case LST_LBRACKET: codStr = "LST_LBRACKET"; break;
296 case LST_LPAR: codStr = "LST_LPAR"; break;
297 case LST_RBRACKET: codStr = "LST_RBRACKET"; break;
298 case LST_RPAR: codStr = "LST_RPAR"; break;
299 case LST_EQOP: codStr = "LST_EQOP"; break;
300 case LST_WHITESPACE: codStr = "WHITESPACE,"; break;
301 case LST_EOL: codStr = "LST_EOL"; break;
302 case LST_elseTOKEN: codStr = "elseTOKEN"; break;
303 case LST_ifTOKEN: codStr = "ifTOKEN"; break;
304 case LST_thenTOKEN: codStr = "thenTOKEN"; break;
305 case LST_BADTOKEN: codStr = "*** BADTOKEN ***"; break;
306 case LEOFTOKEN: /* can't reach LEOFTOKEN easily */
307 codStr = "LEOFTOKEN"; break;
309 codStr = "*** invalid token code ***";
313 /* only used for debugging */
314 printf ("%u:%u: Token Code (%u): %s",
315 ltoken_getLine (tok), ltoken_getCol (tok),
316 ltoken_getCode (tok), codStr);
317 if (ltoken_getRawText (tok) != 0)
319 printf (", Token String (%lu): %s\n",
320 ltoken_getRawText (tok), ltoken_getRawTextChars (tok));