2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** Processor for Larch Shared Language Init Files
30 # include "splintMacros.nf"
32 # include "signature.h"
33 # include "signature2.h"
35 # include "scanline.h"
36 # include "tokentable.h"
37 # include "syntable.h"
40 /* needed to parse init files */
44 # define LTRACE(rule) printf ("Reducing: %s\n", rule)
50 static void LocalUserError (ltoken p_t, /*@temp@*/ char *p_msg)
51 /*@modifies *g_warningstream@*/;
53 static /*@only@*/ ltoken nextToken;
55 static void InitFile (void) /*@modifies nextToken@*/ ;
56 static void InitLines (void) /*@modifies nextToken@*/ ;
57 static void InitLine (void) /*@modifies nextToken@*/ ;
58 static void Classification (void) /*@modifies nextToken@*/ ;
59 static void CharClass (void) /*@modifies nextToken@*/ ;
61 static void EndCommentChars (void) /*@modifies nextToken@*/ ;
62 static void IdChars (void) /*@modifies nextToken@*/ ;
63 static void OpChars (void) /*@modifies nextToken@*/ ;
64 static void ExtensionChar (void) /*@modifies nextToken@*/ ;
65 static void SingChars (void) /*@modifies nextToken@*/ ;
66 static void WhiteChars (void) /*@modifies nextToken@*/ ;
67 static void EndCommentChar (void) /*@modifies nextToken@*/ ;
68 static void IdChar (void) /*@modifies nextToken@*/ ;
69 static void OpChar (void) /*@modifies nextToken@*/ ;
70 static void SingChar (void) /*@modifies nextToken@*/ ;
71 static void WhiteChar (void) /*@modifies nextToken@*/ ;
73 static void TokenClass (void) /*@modifies nextToken@*/ ;
74 static void QuantifierSymToks (void) /*@modifies nextToken@*/ ;
75 static void LogicalOpToks (void) /*@modifies nextToken@*/ ;
76 static void EqOpToks (void) /*@modifies nextToken@*/ ;
77 static void EquationSymToks (void) /*@modifies nextToken@*/ ;
78 static void EqSepSymToks (void) /*@modifies nextToken@*/ ;
79 static void SelectSymToks (void) /*@modifies nextToken@*/ ;
80 static void OpenSymToks (void) /*@modifies nextToken@*/ ;
81 static void SepSymToks (void) /*@modifies nextToken@*/ ;
82 static void CloseSymToks (void) /*@modifies nextToken@*/ ;
83 static void SimpleIdToks (void) /*@modifies nextToken@*/ ;
84 static void MapSymToks (void) /*@modifies nextToken@*/ ;
85 static void MarkerSymToks (void) /*@modifies nextToken@*/ ;
86 static void CommentSymToks (void) /*@modifies nextToken@*/ ;
87 static void QuantifierSymTok (void) /*@modifies nextToken@*/ ;
88 static void LogicalOpTok (void) /*@modifies nextToken@*/ ;
89 static void EqOpTok (void) /*@modifies nextToken@*/ ;
90 static void EquationSymTok (void) /*@modifies nextToken@*/ ;
91 static void EqSepSymTok (void) /*@modifies nextToken@*/ ;
92 static void SelectSymTok (void) /*@modifies nextToken@*/ ;
93 static void OpenSymTok (void) /*@modifies nextToken@*/ ;
94 static void SepSymTok (void) /*@modifies nextToken@*/ ;
95 static void CloseSymTok (void) /*@modifies nextToken@*/ ;
96 static void SimpleIdTok (void) /*@modifies nextToken@*/ ;
97 static void MapSymTok (void) /*@modifies nextToken@*/ ;
98 static void MarkerSymTok (void) /*@modifies nextToken@*/ ;
99 static void CommentSymTok (void) /*@modifies nextToken@*/ ;
100 static void SynClass (void) /*@modifies nextToken@*/ ;
101 static void OldToken (void) /*@modifies nextToken@*/ ;
102 static void NewToken (void) /*@modifies nextToken@*/ ;
103 static void Token (void) /*@modifies nextToken@*/ ;
105 static void InitReduce (LSLInitRuleCode p_rule) /*@modifies nextToken@*/ ;
106 static void UpdateXCharKeywords (charCode) /*@modifies nextToken@*/ ;
107 static void ProcessExtensionChar (void) /*@modifies nextToken@*/ ;
108 static void ProcessEndCommentChar (void) /*@modifies nextToken@*/ ;
109 static void ProcessSingleChar (charCode p_code) /*@modifies nextToken@*/ ;
110 static void ProcessToken (ltokenCode p_code) /*@modifies nextToken@*/ ;
111 static void ProcessSynonym (void) /*@modifies nextToken@*/ ;
113 /* If TRUE character has been redefined as a singleChar. */
114 static bool defineSingleChar[LASTCHAR + 1];
116 static charCode currentExtensionChar;
118 /* LSL init file keyword tokens. */
120 static /*@dependent@*/ ltoken endCommentCharToken;
121 static /*@dependent@*/ ltoken idCharToken;
122 static /*@dependent@*/ ltoken opCharToken;
123 static /*@dependent@*/ ltoken extensionCharToken;
124 static /*@dependent@*/ ltoken singleCharToken;
125 static /*@dependent@*/ ltoken whiteCharToken;
126 static /*@dependent@*/ ltoken quantifierSymToken;
127 static /*@dependent@*/ ltoken logicalOpToken;
128 static /*@dependent@*/ ltoken eqOpToken;
129 static /*@dependent@*/ ltoken equationSymToken;
130 static /*@dependent@*/ ltoken eqSepSymToken;
131 static /*@dependent@*/ ltoken selectSymToken;
132 static /*@dependent@*/ ltoken openSymToken;
133 static /*@dependent@*/ ltoken sepSymToken;
134 static /*@dependent@*/ ltoken closeSymToken;
135 static /*@dependent@*/ ltoken simpleIdToken;
136 static /*@dependent@*/ ltoken mapSymToken;
137 static /*@dependent@*/ ltoken markerSymToken;
138 static /*@dependent@*/ ltoken commentSymToken;
139 static /*@dependent@*/ ltoken synonymToken;
142 hasFirstChar (ltoken tok)
144 return (ltoken_isChar (tok)
145 && lscanCharClass (cstring_firstChar (ltoken_unparse (tok))) == SINGLECHAR);
149 LSLProcessInitFile (void)
156 ** Parsing functions for init file processing, in the same order as the
157 ** grammar file lslinit.cfg. This is top-down order, as much as possible.
165 InitReduce (INITFILE1);
167 if (ltoken_getCode (nextToken) != LEOFTOKEN)
169 LocalUserError (nextToken, "unexpected tokens after end-of-file");
176 InitReduce (INITLINES1);
178 if (ltoken_getCode (nextToken) != LEOFTOKEN)
181 InitReduce (INITLINES2);
184 while (ltoken_getCode (nextToken) != LEOFTOKEN)
187 InitReduce (INITLINES3);
195 if (ltoken_getCode (nextToken) == LST_EOL)
197 /* Nothing on line. */
198 InitReduce (INITLINE1);
203 InitReduce (INITLINE2);
206 if (ltoken_getCode (nextToken) != LST_EOL)
208 LocalUserError (nextToken, "Unexpected tokens on line");
211 ltoken_free (nextToken);
212 nextToken = LSLScanNextToken ();
216 Classification (void)
218 if (ltoken_getRawText (nextToken) == ltoken_getText (endCommentCharToken)
219 || ltoken_getRawText (nextToken) == ltoken_getText (idCharToken)
220 || ltoken_getRawText (nextToken) == ltoken_getText (opCharToken)
221 || ltoken_getRawText (nextToken) == ltoken_getText (extensionCharToken)
222 || ltoken_getRawText (nextToken) == ltoken_getText (singleCharToken)
223 || ltoken_getRawText (nextToken) == ltoken_getText (whiteCharToken))
226 InitReduce (CLASSIFICATION1);
228 else if (ltoken_getRawText (nextToken) == ltoken_getText (quantifierSymToken)
229 || ltoken_getRawText (nextToken) == ltoken_getText (logicalOpToken)
230 || ltoken_getRawText (nextToken) == ltoken_getText (eqOpToken)
231 || ltoken_getRawText (nextToken) == ltoken_getText (equationSymToken)
232 || ltoken_getRawText (nextToken) == ltoken_getText (eqSepSymToken)
233 || ltoken_getRawText (nextToken) == ltoken_getText (selectSymToken)
234 || ltoken_getRawText (nextToken) == ltoken_getText (openSymToken)
235 || ltoken_getRawText (nextToken) == ltoken_getText (sepSymToken)
236 || ltoken_getRawText (nextToken) == ltoken_getText (closeSymToken)
237 || ltoken_getRawText (nextToken) == ltoken_getText (simpleIdToken)
238 || ltoken_getRawText (nextToken) == ltoken_getText (mapSymToken)
239 || ltoken_getRawText (nextToken) == ltoken_getText (markerSymToken)
240 || ltoken_getRawText (nextToken) == ltoken_getText (commentSymToken))
243 InitReduce (CLASSIFICATION2);
245 else if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
248 InitReduce (CLASSIFICATION3);
252 LocalUserError (nextToken,
253 "expected character, token, or synonym classification");
260 ltoken charClassToken;
262 charClassToken = nextToken;
264 nextToken = LSLScanNextToken (); /* Discard char class keyword. */
266 if (ltoken_getRawText (charClassToken) == ltoken_getText (endCommentCharToken))
269 InitReduce (CHARCLASS1);
271 else if (ltoken_getRawText (charClassToken) == ltoken_getText (idCharToken))
274 InitReduce (CHARCLASS2);
276 else if (ltoken_getRawText (charClassToken) == ltoken_getText (opCharToken))
279 InitReduce (CHARCLASS3);
281 else if (ltoken_getRawText (charClassToken)
282 == ltoken_getText (extensionCharToken))
285 InitReduce (CHARCLASS4);
287 else if (ltoken_getRawText (charClassToken) == ltoken_getText (singleCharToken))
290 InitReduce (CHARCLASS5);
292 else if (ltoken_getRawText (charClassToken) == ltoken_getText (whiteCharToken))
295 InitReduce (CHARCLASS6);
299 LocalUserError (nextToken, "expected character classification");
302 ltoken_free (charClassToken);
306 EndCommentChars (void)
309 InitReduce (LRC_ENDCOMMENT1);
311 while (ltoken_getCode (nextToken) != LST_EOL)
314 InitReduce (LRC_ENDCOMMENT2);
323 InitReduce (IDCHARS1);
325 while (ltoken_getCode (nextToken) != LST_EOL)
328 InitReduce (IDCHARS2);
336 InitReduce (OPCHARS1);
338 while (ltoken_getCode (nextToken) != LST_EOL)
341 InitReduce (OPCHARS2);
348 if (ltoken_isChar (nextToken)
349 && lscanCharClass (cstring_firstChar (ltoken_unparse (nextToken))) == SINGLECHAR)
351 LSLGenShiftOnly (nextToken);
352 nextToken = LSLScanNextToken ();
353 InitReduce (LRC_EXTENSIONCHAR1);
357 LocalUserError (nextToken, "expected only one character");
365 InitReduce (SINGCHARS1);
367 while (ltoken_getCode (nextToken) != LST_EOL)
370 InitReduce (SINGCHARS2);
378 InitReduce (WHITECHARS1);
380 while (ltoken_getCode (nextToken) != LST_EOL)
383 InitReduce (WHITECHARS2);
388 EndCommentChar (void)
390 if (ltoken_isChar (nextToken))
392 LSLGenShiftOnly (nextToken);
393 nextToken = LSLScanNextToken ();
394 InitReduce (LRC_ENDCOMMENTCHAR1);
398 LocalUserError (nextToken, "expected only one character");
405 if (hasFirstChar (nextToken))
407 LSLGenShiftOnly (nextToken);
408 nextToken = LSLScanNextToken ();
409 InitReduce (IDCHAR1);
413 LocalUserError (nextToken, "character is already defined, cannot redefine");
420 if (hasFirstChar (nextToken))
422 LSLGenShiftOnly (nextToken);
423 nextToken = LSLScanNextToken ();
424 InitReduce (OPCHAR1);
428 LocalUserError (nextToken, "character is already defined, cannot redefine");
435 if (hasFirstChar (nextToken))
437 LSLGenShiftOnly (nextToken);
438 nextToken = LSLScanNextToken ();
439 InitReduce (SINGCHAR1);
443 LocalUserError (nextToken, "character is already defined, cannot redefine");
450 if (hasFirstChar (nextToken))
452 LSLGenShiftOnly (nextToken);
453 nextToken = LSLScanNextToken ();
454 InitReduce (WHITECHAR1);
458 LocalUserError (nextToken, "character is already defined, cannot redefine");
465 ltoken tokenClassToken;
467 tokenClassToken = nextToken;
469 nextToken = LSLScanNextToken ();
471 if (ltoken_getRawText (tokenClassToken) == ltoken_getText (quantifierSymToken))
473 QuantifierSymToks ();
474 InitReduce (TOKENCLASS1);
476 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (logicalOpToken))
479 InitReduce (TOKENCLASS2);
481 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (eqOpToken))
484 InitReduce (TOKENCLASS3);
486 else if (ltoken_getRawText (tokenClassToken)
487 == ltoken_getText (equationSymToken))
490 InitReduce (TOKENCLASS4);
492 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (eqSepSymToken))
495 InitReduce (TOKENCLASS5);
497 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (selectSymToken))
500 InitReduce (TOKENCLASS6);
502 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (openSymToken))
505 InitReduce (TOKENCLASS7);
507 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (sepSymToken))
510 InitReduce (TOKENCLASS8);
512 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (closeSymToken))
515 InitReduce (TOKENCLASS9);
517 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (simpleIdToken))
520 InitReduce (TOKENCLASS10);
522 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (mapSymToken))
525 InitReduce (TOKENCLASS11);
527 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (markerSymToken))
530 InitReduce (TOKENCLASS12);
532 else if (ltoken_getRawText (tokenClassToken)
533 == ltoken_getText (commentSymToken))
536 InitReduce (TOKENCLASS13);
540 LocalUserError (nextToken, "expected token classification");
543 ltoken_free (tokenClassToken);
547 QuantifierSymToks (void)
550 InitReduce (QUANTIFIERSYMTOKS1);
552 while (ltoken_getCode (nextToken) != LST_EOL)
555 InitReduce (QUANTIFIERSYMTOKS2);
563 InitReduce (LOGICALOPTOKS1);
565 while (ltoken_getCode (nextToken) != LST_EOL)
568 InitReduce (LOGICALOPTOKS2);
576 InitReduce (LRC_EQOPTOKS1);
578 while (ltoken_getCode (nextToken) != LST_EOL)
581 InitReduce (LRC_EQOPTOKS2);
586 EquationSymToks (void)
589 InitReduce (LRC_EQUATIONSYMTOKS1);
591 while (ltoken_getCode (nextToken) != LST_EOL)
594 InitReduce (LRC_EQUATIONSYMTOKS2);
602 InitReduce (LRC_EQSEPSYMTOKS1);
604 while (ltoken_getCode (nextToken) != LST_EOL)
607 InitReduce (LRC_EQSEPSYMTOKS2);
615 InitReduce (SELECTSYMTOKS1);
617 while (ltoken_getCode (nextToken) != LST_EOL)
620 InitReduce (SELECTSYMTOKS2);
628 InitReduce (OPENSYMTOKS1);
630 while (ltoken_getCode (nextToken) != LST_EOL)
633 InitReduce (OPENSYMTOKS2);
641 InitReduce (SEPSYMTOKS1);
643 while (ltoken_getCode (nextToken) != LST_EOL)
646 InitReduce (SEPSYMTOKS2);
654 InitReduce (CLOSESYMTOKS1);
656 while (ltoken_getCode (nextToken) != LST_EOL)
659 InitReduce (CLOSESYMTOKS2);
667 InitReduce (SIMPLEIDTOKS1);
669 while (ltoken_getCode (nextToken) != LST_EOL)
672 InitReduce (SIMPLEIDTOKS2);
680 InitReduce (MAPSYMTOKS1);
682 while (ltoken_getCode (nextToken) != LST_EOL)
685 InitReduce (MAPSYMTOKS2);
693 InitReduce (MARKERSYMTOKS1);
695 while (ltoken_getCode (nextToken) != LST_EOL)
698 InitReduce (MARKERSYMTOKS2);
703 CommentSymToks (void)
706 InitReduce (COMMENTSYMTOKS1);
708 while (ltoken_getCode (nextToken) != LST_EOL)
711 InitReduce (COMMENTSYMTOKS2);
716 QuantifierSymTok (void)
719 InitReduce (QUANTIFIERSYMTOK1);
726 InitReduce (LOGICALOPTOK1);
733 InitReduce (LRC_EQOPTOK1);
737 EquationSymTok (void)
739 /* ### EquationSymTok (); ### */
741 InitReduce (LRC_EQUATIONSYMTOK1);
748 InitReduce (LRC_EQSEPSYMTOK1);
756 InitReduce (SELECTSYMTOK1);
763 InitReduce (OPENSYMTOK1);
770 InitReduce (SEPSYMTOK1);
777 InitReduce (CLOSESYMTOK1);
784 InitReduce (SIMPLEIDTOK1);
791 InitReduce (MAPSYMTOK1);
798 InitReduce (MARKERSYMTOK1);
806 InitReduce (COMMENTSYMTOK1);
813 if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
815 ltoken_free (nextToken);
816 nextToken = LSLScanNextToken ();
821 InitReduce (SYNCLASS1);
825 LocalUserError (nextToken, "expected synonym classification");
834 InitReduce (OLDTOKEN1);
842 InitReduce (NEWTOKEN1);
849 if (ltoken_getCode (nextToken) == LST_EOL
850 || ltoken_getCode (nextToken) == LEOFTOKEN)
852 LocalUserError (nextToken, "unexpected end-of-line or end-of-file");
856 LSLGenShiftOnly (nextToken);
857 nextToken = LSLScanNextToken ();
862 ** Init File Processing Routines, these routines use the shift-reduce sequence
863 ** produced by the init file parser and update the necessary tables for the
866 ** The same shift stack is used that LSL parser uses. A different reduce
867 ** procedure is used because the init file grammar is different from the LSL
873 InitReduce (LSLInitRuleCode rule)
878 LTRACE ("INITFILE1");
882 LTRACE ("INITLINES1");
886 LTRACE ("INITLINES2");
890 LTRACE ("INITLINES3");
894 LTRACE ("INITLINE1");
898 LTRACE ("INITLINE2");
901 case CLASSIFICATION1:
902 LTRACE ("CLASSIFICATION1");
905 case CLASSIFICATION2:
906 LTRACE ("CLASSIFICATION2");
909 case CLASSIFICATION3:
910 LTRACE ("CLASSIFICATION3");
914 LTRACE ("CHARCLASS1");
918 LTRACE ("CHARCLASS2");
922 LTRACE ("CHARCLASS3");
926 LTRACE ("CHARCLASS4");
930 LTRACE ("CHARCLASS5");
934 LTRACE ("CHARCLASS6");
937 case LRC_ENDCOMMENT1:
938 LTRACE ("LRC_ENDCOMMENT1");
941 case LRC_ENDCOMMENT2:
942 LTRACE ("LRC_ENDCOMMENT2");
961 case LRC_EXTENSIONCHAR1:
962 LTRACE ("LRC_EXTENSIONCHAR1");
963 ProcessExtensionChar ();
967 LTRACE ("SINGCHARS1");
971 LTRACE ("SINGCHARS2");
975 LTRACE ("WHITECHARS1");
979 LTRACE ("WHITECHARS2");
982 case LRC_ENDCOMMENTCHAR1:
983 LTRACE ("LRC_ENDCOMMENTCHAR1");
984 ProcessEndCommentChar ();
989 ProcessSingleChar (IDCHAR);
994 ProcessSingleChar (OPCHAR);
998 LTRACE ("SINGCHAR1");
999 ProcessSingleChar (SINGLECHAR);
1004 ProcessSingleChar (WHITECHAR);
1008 LTRACE ("TOKENCLASS1");
1012 LTRACE ("TOKENCLASS2");
1016 LTRACE ("TOKENCLASS3");
1020 LTRACE ("TOKENCLASS4");
1024 LTRACE ("TOKENCLASS5");
1028 LTRACE ("TOKENCLASS6");
1032 LTRACE ("TOKENCLASS7");
1036 LTRACE ("TOKENCLASS8");
1040 LTRACE ("TOKENCLASS9");
1044 LTRACE ("TOKENCLASS10");
1048 LTRACE ("TOKENCLASS11");
1052 LTRACE ("TOKENCLASS12");
1056 LTRACE ("TOKENCLASS13");
1059 case QUANTIFIERSYMTOKS1:
1060 LTRACE ("QUALIFERSYMTOKS1");
1063 case QUANTIFIERSYMTOKS2:
1064 LTRACE ("QUANTIFIERSYMTOKS2");
1067 case LOGICALOPTOKS1:
1068 LTRACE ("LOGICALOPTOKS1");
1071 case LOGICALOPTOKS2:
1072 LTRACE ("LOGICALOPTOKS2");
1076 LTRACE ("LRC_EQOPTOKS1");
1080 LTRACE ("LRC_EQOPTOKS2");
1083 case LRC_EQUATIONSYMTOKS1:
1084 LTRACE ("LRC_EQUATIONSYMTOKS1");
1087 case LRC_EQUATIONSYMTOKS2:
1088 LTRACE ("LRC_EQUATIONSYMTOKS2");
1091 case LRC_EQSEPSYMTOKS1:
1092 LTRACE ("LRC_EQSEPSYMTOKS1");
1095 case LRC_EQSEPSYMTOKS2:
1096 LTRACE ("LRC_EQSEPSYMTOKS2");
1099 case SELECTSYMTOKS1:
1100 LTRACE ("SELECTSYMTOKS1");
1103 case SELECTSYMTOKS2:
1104 LTRACE ("SELECTSYMTOKS2");
1108 LTRACE ("OPENSYMTOKS1");
1112 LTRACE ("OPENSYMTOKS2");
1116 LTRACE ("SEPSYMTOKS1");
1120 LTRACE ("SEPSYMTOKS2");
1124 LTRACE ("CLOSESYMTOKS1");
1128 LTRACE ("CLOSESYMTOKS2");
1132 LTRACE ("SIMPLEIDTOKS1");
1136 LTRACE ("SIMPLEIDTOKS2");
1140 LTRACE ("MAPSYMTOKS1");
1144 LTRACE ("MAPSYMTOKS2");
1147 case MARKERSYMTOKS1:
1148 LTRACE ("MARKERSYMTOKS1");
1151 case MARKERSYMTOKS2:
1152 LTRACE ("MARKERSYMTOKS2");
1155 case COMMENTSYMTOKS1:
1156 LTRACE ("COMMENTSYMTOKS1");
1159 case COMMENTSYMTOKS2:
1160 LTRACE ("COMMENTSYMTOKS2");
1163 case QUANTIFIERSYMTOK1:
1164 LTRACE ("QUANTIFERSYMTOK1");
1165 ProcessToken (LST_QUANTIFIERSYM);
1169 LTRACE ("LOGICALOPTOK1");
1170 ProcessToken (LST_LOGICALOP);
1174 LTRACE ("LRC_EQOPTOK1");
1175 ProcessToken (LST_EQOP);
1178 case LRC_EQUATIONSYMTOK1:
1179 LTRACE ("LRC_EQUATIONSYMTOK1");
1180 ProcessToken (LST_EQUATIONSYM);
1183 case LRC_EQSEPSYMTOK1:
1184 LTRACE ("LRC_EQSEPSYMTOK1");
1185 ProcessToken (LST_EQSEPSYM);
1189 LTRACE ("SELECTSYMTOK1");
1190 ProcessToken (LST_SELECTSYM);
1194 LTRACE ("OPENSYMTOK1");
1195 ProcessToken (LST_OPENSYM);
1199 LTRACE ("SEPSYMTOK1");
1200 ProcessToken (LST_SEPSYM);
1204 LTRACE ("CLOSESYMTOK1");
1205 ProcessToken (LST_CLOSESYM);
1209 LTRACE ("SIMPLEIDTOK1");
1210 ProcessToken (LST_SIMPLEID);
1214 LTRACE ("MAPSYMTOK1");
1215 ProcessToken (LST_MAPSYM);
1219 LTRACE ("MARKERSYMTOK1");
1220 ProcessToken (LST_MARKERSYM);
1223 case COMMENTSYMTOK1:
1224 LTRACE ("COMMENTSYMTOK1");
1225 ProcessToken (LST_COMMENTSYM);
1229 LTRACE ("SYNCLASS1");
1234 LTRACE ("OLDTOKEN1");
1238 LTRACE ("NEWTOKEN1");
1242 llcontbuglit ("InitReduce: bad switch");
1246 } /* end InitReduce () */
1250 /* Reset the first character of the predefined extensionChar keywords when */
1251 /* the extensionChar changes. e.g. "extensionChar @" changes "forall" to */
1255 UpdateXCharKeywords (charCode xCharCode)
1257 char xChar = (char) xCharCode;
1260 str = ltoken_getTextChars (ltoken_forall);
1263 str = ltoken_getTextChars (ltoken_and);
1266 str = ltoken_getTextChars (ltoken_or);
1269 str = ltoken_getTextChars (ltoken_implies);
1272 str = ltoken_getTextChars (ltoken_eq);
1275 str = ltoken_getTextChars (ltoken_neq);
1278 str = ltoken_getTextChars (ltoken_equals);
1281 str = ltoken_getTextChars (ltoken_eqsep);
1284 str = ltoken_getTextChars (ltoken_select);
1287 str = ltoken_getTextChars (ltoken_open);
1290 str = ltoken_getTextChars (ltoken_sep);
1293 str = ltoken_getTextChars (ltoken_close);
1296 str = ltoken_getTextChars (ltoken_id);
1299 str = ltoken_getTextChars (ltoken_arrow);
1302 str = ltoken_getTextChars (ltoken_marker);
1305 str = ltoken_getTextChars (ltoken_comment);
1310 /* Different from ProcessCharClass because only allow one extension */
1311 /* character. Therefore, the present extension character must be set to a */
1315 ProcessExtensionChar (void)
1317 ltoken stackToken = LSLGenTopPopShiftStack ();
1318 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1320 if (!defineSingleChar[(int)firstChar]
1321 && lscanCharClass (firstChar) == SINGLECHAR)
1323 /* Is a single character that has not been defined before. */
1324 /* Can only have one extension char. Release old one. */
1325 lsetCharClass (firstChar, CHC_EXTENSION);
1327 /* this is a (bogus) type bug! caught by splint */
1328 /* lsetCharClass (currentExtensionChar, SINGLECHAR); */
1330 lsetCharClass ((char) currentExtensionChar, SINGLECHAR);
1332 currentExtensionChar = (charCode) firstChar;
1333 UpdateXCharKeywords (currentExtensionChar);
1337 /* Already redefined. Don't allow to be redefined. */
1338 LocalUserError (stackToken, "character is already defined, cannot redefine");
1340 ltoken_free (stackToken);
1343 /* Different from ProcessSingleChar because allow any characters to be */
1344 /* endCommentChar and also set a different part of the scanner structure. */
1347 ProcessEndCommentChar (void)
1349 ltoken stackToken = LSLGenTopPopShiftStack ();
1350 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1352 if (LSLIsEndComment (firstChar))
1354 LocalUserError (stackToken,
1355 "already defined as a endCommentChar, cannot redefine");
1359 lsetEndCommentChar (firstChar, TRUE);
1361 ltoken_free (stackToken);
1365 ProcessSingleChar (charCode code)
1367 ltoken stackToken = LSLGenTopPopShiftStack ();
1368 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1370 if (!defineSingleChar[(int)firstChar]
1371 && lscanCharClass (firstChar) == SINGLECHAR)
1373 /* Is a single character that has not been defined before. */
1374 /* It's OK to redefine once. */
1375 lsetCharClass (firstChar, code);
1376 /* OK to mark as a defined singleChar even if not. Only check */
1377 /* defineSingleChar[] if defining a singleChar. */
1378 defineSingleChar[(int)firstChar] = TRUE;
1382 LocalUserError (stackToken, "character is already defined, cannot redefine");
1384 ltoken_free (stackToken);
1388 ProcessToken (ltokenCode code)
1390 ltoken stackToken, temp;
1393 stackToken = LSLGenTopPopShiftStack ();
1394 sym = ltoken_getText (stackToken);
1398 LocalUserError (stackToken,
1399 "already defined as a synonym, cannot redefine");
1402 /* Get the token from the token table, so can check if the token */
1403 /* was updated by a previous token. */
1404 temp = LSLGetToken (sym);
1406 if (ltoken_isStateDefined (temp))
1408 if ((code == LST_OPENSYM && sym == lsymbol_fromChars ("[")) ||
1409 (code == LST_CLOSESYM && sym == lsymbol_fromChars ("]")))
1411 /* ignore "openSym [" and "closeSym ]" TokenClass */
1412 ltoken_free (stackToken);
1417 LocalUserError (stackToken, "already defined, cannot redefine");
1422 LSLUpdateToken (code, ltoken_getText (stackToken), TRUE);
1423 ltoken_free (stackToken);
1428 ProcessSynonym (void)
1433 newtok = LSLGenTopPopShiftStack ();
1434 oldtok = LSLGenTopPopShiftStack ();
1436 if (ltoken_wasSyn (newtok))
1438 /* The token has a synonym. This means that the synonym was in the */
1439 /* init file, so complain about redefining as a synonym again */
1440 LocalUserError (newtok, "newtok already is a synonym, cannot redefine");
1443 if (ltoken_hasSyn (newtok))
1446 ** newtok already has a synonym defined for it. Do not allow
1447 ** synonyms to be chained.
1450 LocalUserError (newtok,
1451 "newtok already has a synonym, cannot chain synonyms");
1454 if (ltoken_isStateDefined (newtok))
1456 LocalUserError (newtok, "newtok already defined, cannot redefine");
1459 LSLAddSyn (ltoken_getText (newtok), ltoken_getText (oldtok));
1460 ltoken_free (oldtok);
1461 ltoken_free (newtok);
1466 * Utilities, in alphabetical order
1470 LocalUserError (ltoken t, /*@temp@*/ char *msg)
1472 lldiagmsg (message ("%s %s in the LSL init file:",
1473 ltoken_unparse (t), cstring_fromChars (msg)));
1475 ltoken_free (nextToken);
1476 nextToken = LSLScanNextToken ();
1478 while (ltoken_getCode (nextToken) != LST_EOL)
1480 ltoken_free (nextToken);
1481 nextToken = LSLScanNextToken ();
1486 ** Required initialization and cleanup routines
1489 static /*@exposed@*/ ltoken insertSimpleToken (char *text)
1490 /*@modifies internalState@*/
1492 return (LSLInsertToken (LST_SIMPLEID, lsymbol_fromChars (text), 0, FALSE));
1496 LSLProcessInitFileInit (void)
1500 LSLGenInit (TRUE); /* parsing LSLinit not LCLinit */
1503 ** Insert the init file keywords into the token table as undefined
1504 ** SIMPLEIDs. They are defined as simpleIds since they must be treated
1505 ** that way if they do not appear as the first token on a line, and
1506 ** they must be treated that way for the actual LSL parsing. Save the
1507 ** tokens so can recognize as init file keywords when necessary.
1510 endCommentCharToken = insertSimpleToken ("endCommentChar");
1511 idCharToken = insertSimpleToken ("idChar");
1512 opCharToken = insertSimpleToken ("opChar");
1513 extensionCharToken = insertSimpleToken ("extensionChar");
1514 singleCharToken = insertSimpleToken ("singleChar");
1515 whiteCharToken = insertSimpleToken ("whiteChar");
1517 quantifierSymToken = insertSimpleToken ("quantifierSym");
1518 logicalOpToken = insertSimpleToken ("logicalOp");
1519 eqOpToken = insertSimpleToken ("eqOp");
1520 equationSymToken = insertSimpleToken ("equationSym");
1521 eqSepSymToken = insertSimpleToken ("eqSepSym");
1522 selectSymToken = insertSimpleToken ("selectSym");
1523 openSymToken = insertSimpleToken ("openSym");
1524 sepSymToken = insertSimpleToken ("sepSym");
1525 closeSymToken = insertSimpleToken ("closeSym");
1526 simpleIdToken = insertSimpleToken ("simpleId");
1527 mapSymToken = insertSimpleToken ("mapSym");
1528 markerSymToken = insertSimpleToken ("markerSym");
1529 commentSymToken = insertSimpleToken ("commentSym");
1530 synonymToken = insertSimpleToken ("synonym");
1532 for (i = 0; i <= LASTCHAR; i++)
1534 defineSingleChar[i] = FALSE;
1538 ** Record the current extension character so can redefine back to
1539 ** singleChar if a new extension character is redefined.
1542 currentExtensionChar = (charCode) CHAREXTENDER;
1544 LSLReportEolTokens (TRUE);
1545 ltoken_free (nextToken);
1546 nextToken = LSLScanNextToken ();