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"
34 # include "scanline.h"
35 # include "lclscanline.h"
36 # include "lcltokentable.h"
37 # include "lclsyntable.h"
44 # define TRACE(rule) printf ("Reducing: %s\n", rule)
50 static /*@dependent@*/ ltoken nextToken;
51 static void InitLines (void) /*@modifies nextToken@*/ ;
52 static void InitLine (void) /*@modifies nextToken@*/;
53 static void Classification (void) /*@modifies nextToken@*/;
54 static void CharClass (void) /*@modifies nextToken@*/;
56 static void EndCommentChars (void) /*@modifies nextToken@*/ ;
57 static void IdChars (void) /*@modifies nextToken@*/ ;
58 static void OpChars (void) /*@modifies nextToken@*/ ;
59 static void ExtensionChar (void) /*@modifies nextToken@*/ ;
60 static void SingChars (void) /*@modifies nextToken@*/ ;
61 static void WhiteChars (void) /*@modifies nextToken@*/ ;
62 static void EndCommentChar (void) /*@modifies nextToken@*/ ;
63 static void IdChar (void) /*@modifies nextToken@*/ ;
64 static void OpChar (void) /*@modifies nextToken@*/ ;
65 static void SingChar (void) /*@modifies nextToken@*/ ;
66 static void WhiteChar (void) /*@modifies nextToken@*/ ;
68 static void TokenClass (void) /*@modifies nextToken@*/ ;
69 static void QuantifierSymToks (void) /*@modifies nextToken@*/ ;
70 static void LogicalOpToks (void) /*@modifies nextToken@*/ ;
71 static void EqOpToks (void) /*@modifies nextToken@*/ ;
72 static void EquationSymToks (void) /*@modifies nextToken@*/ ;
73 static void EqSepSymToks (void) /*@modifies nextToken@*/ ;
74 static void SelectSymToks (void) /*@modifies nextToken@*/ ;
75 static void OpenSymToks (void) /*@modifies nextToken@*/ ;
76 static void SepSymToks (void) /*@modifies nextToken@*/ ;
77 static void CloseSymToks (void) /*@modifies nextToken@*/ ;
78 static void SimpleIdToks (void) /*@modifies nextToken@*/ ;
79 static void MapSymToks (void) /*@modifies nextToken@*/ ;
80 static void MarkerSymToks (void) /*@modifies nextToken@*/ ;
81 static void CommentSymToks (void) /*@modifies nextToken@*/ ;
82 static void QuantifierSymTok (void) /*@modifies nextToken@*/ ;
83 static void LogicalOpTok (void) /*@modifies nextToken@*/ ;
84 static void EqOpTok (void) /*@modifies nextToken@*/ ;
85 static void EquationSymTok (void) /*@modifies nextToken@*/ ;
86 static void EqSepSymTok (void) /*@modifies nextToken@*/ ;
87 static void SelectSymTok (void) /*@modifies nextToken@*/ ;
88 static void OpenSymTok (void) /*@modifies nextToken@*/ ;
89 static void SepSymTok (void) /*@modifies nextToken@*/ ;
90 static void CloseSymTok (void) /*@modifies nextToken@*/ ;
91 static void SimpleIdTok (void) /*@modifies nextToken@*/ ;
92 static void MapSymTok (void) /*@modifies nextToken@*/ ;
93 static void MarkerSymTok (void) /*@modifies nextToken@*/ ;
94 static void CommentSymTok (void) /*@modifies nextToken@*/ ;
95 static void SynClass (void) /*@modifies nextToken@*/ ;
96 static void OldToken (void) /*@modifies nextToken@*/ ;
97 static void NewToken (void) /*@modifies nextToken@*/ ;
98 static void Token (void) /*@modifies nextToken@*/ ;
100 static void InitReduce (LCLInitRuleCode p_rule) /*@modifies nextToken@*/ ;
101 static void UpdateXCharKeywords (charCode p_xChar) /*@modifies nextToken@*/ ;
102 static void ProcessExtensionChar (void) /*@modifies nextToken@*/ ;
103 static void ProcessEndCommentChar (void) /*@modifies nextToken@*/ ;
104 static void ProcessSingleChar (charCode p_code) /*@modifies nextToken@*/ ;
105 static void ProcessToken (ltokenCode p_code) /*@modifies nextToken@*/ ;
106 static void ProcessSynonym (void) /*@modifies nextToken@*/ ;
109 LocalUserError (/*@unused@*/ ltoken p_t, /*@temp@*/ char *p_msg)
110 /*@modifies *g_warningstream@*/ ;
112 /* If TRUE character has been redefined as a singleChar. */
113 static bool defineSingleChar[LASTCHAR + 1];
115 static charCode currentExtensionChar;
117 /* LSL init file keyword tokens. */
119 static /*@exposed@*/ ltoken endCommentCharToken;
120 static /*@exposed@*/ ltoken idCharToken;
121 static /*@exposed@*/ ltoken opCharToken;
122 static /*@exposed@*/ ltoken extensionCharToken;
123 static /*@exposed@*/ ltoken singleCharToken;
124 static /*@exposed@*/ ltoken whiteCharToken;
126 static /*@exposed@*/ ltoken quantifierSymToken;
127 static /*@exposed@*/ ltoken logicalOpToken;
128 static /*@exposed@*/ ltoken eqOpToken;
129 static /*@exposed@*/ ltoken equationSymToken;
130 static /*@exposed@*/ ltoken eqSepSymToken;
131 static /*@exposed@*/ ltoken selectSymToken;
132 static /*@exposed@*/ ltoken openSymToken;
133 static /*@exposed@*/ ltoken sepSymToken;
134 static /*@exposed@*/ ltoken closeSymToken;
135 static /*@exposed@*/ ltoken simpleIdToken;
136 static /*@exposed@*/ ltoken mapSymToken;
137 static /*@exposed@*/ ltoken markerSymToken;
138 static /*@exposed@*/ ltoken commentSymToken;
140 static /*@exposed@*/ ltoken synonymToken;
142 static /*@exposed@*/ ltoken
143 insertSimpleToken (char *s) /*@modifies internalState@*/
145 return (LCLInsertToken (simpleId, lsymbol_fromChars (s), 0, FALSE));
149 hasFirstChar (ltoken tok) /*@*/
151 return (ltoken_isChar (tok)
152 && ltoken_isSingleChar (cstring_firstChar (ltoken_unparse (tok))));
156 LCLProcessInitFile (void)
160 InitReduce (INITFILE1);
162 if (ltoken_getCode (nextToken) != LEOFTOKEN)
164 LocalUserError (nextToken, "unexpected tokens after end-of-file");
172 InitReduce (INITLINES1);
176 if (ltoken_getCode (nextToken) != LEOFTOKEN)
179 InitReduce (INITLINES2);
182 while (ltoken_getCode (nextToken) != LEOFTOKEN)
185 InitReduce (INITLINES3);
193 if (ltoken_getCode (nextToken) == LLT_EOL)
195 /* Nothing on line. */
196 InitReduce (INITLINE1);
201 InitReduce (INITLINE2);
204 if (ltoken_getCode (nextToken) != LLT_EOL)
206 LocalUserError (nextToken, "Unexpected tokens on line");
209 nextToken = LCLScanNextToken (); /* Discard EOL */
213 Classification (void)
215 lsymbol ntext = ltoken_getRawText (nextToken);
218 if (ntext == ltoken_getText (endCommentCharToken)
219 || ntext == ltoken_getText (idCharToken)
220 || ntext == ltoken_getText (opCharToken)
221 || ntext == ltoken_getText (extensionCharToken)
222 || ntext == ltoken_getText (singleCharToken)
223 || ntext == ltoken_getText (whiteCharToken))
226 InitReduce (CLASSIFICATION1);
228 else if (ntext == ltoken_getText (quantifierSymToken)
229 || ntext == ltoken_getText (logicalOpToken)
230 || ntext == ltoken_getText (eqOpToken)
231 || ntext == ltoken_getText (equationSymToken)
232 || ntext == ltoken_getText (eqSepSymToken)
233 || ntext == ltoken_getText (selectSymToken)
234 || ntext == ltoken_getText (openSymToken)
235 || ntext == ltoken_getText (sepSymToken)
236 || ntext == ltoken_getText (closeSymToken)
237 || ntext == ltoken_getText (simpleIdToken)
238 || ntext == ltoken_getText (mapSymToken)
239 || ntext == ltoken_getText (markerSymToken)
240 || ntext == ltoken_getText (commentSymToken))
243 InitReduce (CLASSIFICATION2);
245 else if (ntext == ltoken_getText (synonymToken))
248 InitReduce (CLASSIFICATION3);
252 llbug (message ("Expected character, token, or synonym classification: %s",
253 ltoken_getRawString (nextToken)));
254 /* pop off all tokens on this line */
261 ltoken charClassToken;
263 charClassToken = nextToken;
265 nextToken = LCLScanNextToken (); /* Discard char class keyword. */
267 if (ltoken_getRawText (charClassToken) == ltoken_getText (endCommentCharToken))
270 InitReduce (CHARCLASS1);
272 else if (ltoken_getRawText (charClassToken) == ltoken_getText (idCharToken))
275 InitReduce (CHARCLASS2);
277 else if (ltoken_getRawText (charClassToken) == ltoken_getText (opCharToken))
280 InitReduce (CHARCLASS3);
282 else if (ltoken_getRawText (charClassToken)
283 == ltoken_getText (extensionCharToken))
286 InitReduce (CHARCLASS4);
288 else if (ltoken_getRawText (charClassToken) == ltoken_getText (singleCharToken))
291 InitReduce (CHARCLASS5);
293 else if (ltoken_getRawText (charClassToken) == ltoken_getText (whiteCharToken))
296 InitReduce (CHARCLASS6);
300 LocalUserError (nextToken, "expected character classification");
305 EndCommentChars (void)
308 InitReduce (LRC_ENDCOMMENT1);
310 while (ltoken_getCode (nextToken) != LLT_EOL)
313 InitReduce (LRC_ENDCOMMENT2);
318 static void IdChars (void) /*@modifies nextToken@*/
321 InitReduce (IDCHARS1);
323 while (ltoken_getCode (nextToken) != LLT_EOL)
326 InitReduce (IDCHARS2);
330 static void OpChars (void) /*@modifies nextToken@*/
333 InitReduce (OPCHARS1);
335 while (ltoken_getCode (nextToken) != LLT_EOL)
338 InitReduce (OPCHARS2);
342 static void ExtensionChar (void) /*@modifies nextToken@*/
344 if (hasFirstChar (nextToken))
346 LSLGenShift (nextToken);
347 nextToken = LCLScanNextToken ();
348 InitReduce (LRC_EXTENSIONCHAR1);
352 LocalUserError (nextToken, "expected only one character");
356 static void SingChars (void) /*@modifies nextToken@*/
359 InitReduce (SINGCHARS1);
361 while (ltoken_getCode (nextToken) != LLT_EOL)
364 InitReduce (SINGCHARS2);
368 static void WhiteChars (void) /*@modifies nextToken@*/
371 InitReduce (WHITECHARS1);
373 while (ltoken_getCode (nextToken) != LLT_EOL)
376 InitReduce (WHITECHARS2);
380 static void EndCommentChar (void) /*@modifies nextToken@*/
382 if (ltoken_isChar (nextToken))
384 LSLGenShift (nextToken);
385 nextToken = LCLScanNextToken ();
386 InitReduce (LRC_ENDCOMMENTCHAR1);
390 LocalUserError (nextToken, "expected only one character");
394 static void IdChar (void) /*@modifies nextToken@*/
396 if (hasFirstChar (nextToken))
398 LSLGenShift (nextToken);
399 nextToken = LCLScanNextToken ();
400 InitReduce (IDCHAR1);
404 LocalUserError (nextToken,
405 "Character is already defined, cannot redefine");
409 static void OpChar (void) /*@modifies nextToken@*/
411 if (hasFirstChar (nextToken))
413 LSLGenShift (nextToken);
414 nextToken = LCLScanNextToken ();
415 InitReduce (OPCHAR1);
419 LocalUserError (nextToken,
420 "Character is already defined, cannot redefine");
424 static void SingChar (void) /*@modifies nextToken@*/
426 if (hasFirstChar (nextToken))
428 LSLGenShift (nextToken);
429 nextToken = LCLScanNextToken ();
430 InitReduce (SINGCHAR1);
434 LocalUserError (nextToken,
435 "Character is already defined, cannot redefine");
439 static void WhiteChar (void) /*@modifies nextToken@*/
441 if (hasFirstChar (nextToken))
443 LSLGenShift (nextToken);
444 nextToken = LCLScanNextToken ();
445 InitReduce (WHITECHAR1);
449 LocalUserError (nextToken, "Character is already defined, cannot redefine");
454 TokenClass (void) /*@modifies nextToken@*/
456 ltoken tokenClassToken;
457 lsymbol ttext = ltoken_getRawText (nextToken);
459 tokenClassToken = nextToken;
461 /* Discard token class keyword. */
462 nextToken = LCLScanNextToken ();
464 if (ttext == ltoken_getText (quantifierSymToken))
466 QuantifierSymToks ();
467 InitReduce (TOKENCLASS1);
469 else if (ttext == ltoken_getText (logicalOpToken))
472 InitReduce (TOKENCLASS2);
474 else if (ttext == ltoken_getText (eqOpToken))
477 InitReduce (TOKENCLASS3);
479 else if (ttext == ltoken_getText (equationSymToken))
482 InitReduce (TOKENCLASS4);
484 else if (ttext == ltoken_getText (eqSepSymToken))
487 InitReduce (TOKENCLASS5);
489 else if (ttext == ltoken_getText (selectSymToken))
492 InitReduce (TOKENCLASS6);
494 else if (ttext == ltoken_getText (openSymToken))
497 InitReduce (TOKENCLASS7);
499 else if (ttext == ltoken_getText (sepSymToken))
502 InitReduce (TOKENCLASS8);
504 else if (ttext == ltoken_getText (closeSymToken))
507 InitReduce (TOKENCLASS9);
509 else if (ttext == ltoken_getText (simpleIdToken))
512 InitReduce (TOKENCLASS10);
514 else if (ttext == ltoken_getText (mapSymToken))
517 InitReduce (TOKENCLASS11);
519 else if (ttext == ltoken_getText (markerSymToken))
522 InitReduce (TOKENCLASS12);
524 else if (ttext == ltoken_getText (commentSymToken))
527 InitReduce (TOKENCLASS13);
531 LocalUserError (nextToken, "expected token classification");
536 QuantifierSymToks (void) /*@modifies nextToken@*/
539 InitReduce (QUANTIFIERSYMTOKS1);
541 while (ltoken_getCode (nextToken) != LLT_EOL)
544 InitReduce (QUANTIFIERSYMTOKS2);
549 LogicalOpToks (void) /*@modifies nextToken@*/
552 InitReduce (LOGICALOPTOKS1);
554 while (ltoken_getCode (nextToken) != LLT_EOL)
557 InitReduce (LOGICALOPTOKS2);
562 EqOpToks (void) /*@modifies nextToken@*/
565 InitReduce (LRC_EQOPTOKS1);
567 while (ltoken_getCode (nextToken) != LLT_EOL)
570 InitReduce (LRC_EQOPTOKS2);
575 EquationSymToks (void) /*@modifies nextToken@*/
578 InitReduce (LRC_EQUATIONSYMTOKS1);
580 while (ltoken_getCode (nextToken) != LLT_EOL)
583 InitReduce (LRC_EQUATIONSYMTOKS2);
588 EqSepSymToks (void) /*@modifies nextToken@*/
591 InitReduce (LRC_EQSEPSYMTOKS1);
593 while (ltoken_getCode (nextToken) != LLT_EOL)
596 InitReduce (LRC_EQSEPSYMTOKS2);
601 SelectSymToks (void) /*@modifies nextToken@*/
604 InitReduce (SELECTSYMTOKS1);
606 while (ltoken_getCode (nextToken) != LLT_EOL)
609 InitReduce (SELECTSYMTOKS2);
614 OpenSymToks (void) /*@modifies nextToken@*/
617 InitReduce (OPENSYMTOKS1);
619 while (ltoken_getCode (nextToken) != LLT_EOL)
622 InitReduce (OPENSYMTOKS2);
627 SepSymToks (void) /*@modifies nextToken@*/
630 InitReduce (SEPSYMTOKS1);
632 while (ltoken_getCode (nextToken) != LLT_EOL)
635 InitReduce (SEPSYMTOKS2);
640 CloseSymToks (void) /*@modifies nextToken@*/
643 InitReduce (CLOSESYMTOKS1);
645 while (ltoken_getCode (nextToken) != LLT_EOL)
648 InitReduce (CLOSESYMTOKS2);
653 SimpleIdToks (void) /*@modifies nextToken@*/
656 InitReduce (SIMPLEIDTOKS1);
658 while (ltoken_getCode (nextToken) != LLT_EOL)
661 InitReduce (SIMPLEIDTOKS2);
666 MapSymToks (void) /*@modifies nextToken@*/
669 InitReduce (MAPSYMTOKS1);
671 while (ltoken_getCode (nextToken) != LLT_EOL)
674 InitReduce (MAPSYMTOKS2);
679 MarkerSymToks (void) /*@modifies nextToken@*/
682 InitReduce (MARKERSYMTOKS1);
684 while (ltoken_getCode (nextToken) != LLT_EOL)
687 InitReduce (MARKERSYMTOKS2);
692 CommentSymToks (void) /*@modifies nextToken@*/
695 InitReduce (COMMENTSYMTOKS1);
697 while (ltoken_getCode (nextToken) != LLT_EOL)
700 InitReduce (COMMENTSYMTOKS2);
705 QuantifierSymTok (void) /*@modifies nextToken@*/
708 InitReduce (QUANTIFIERSYMTOK1);
712 LogicalOpTok (void) /*@modifies nextToken@*/
715 InitReduce (LOGICALOPTOK1);
719 EqOpTok (void) /*@modifies nextToken@*/
722 InitReduce (LRC_EQOPTOK1);
725 static void EquationSymTok (void) /*@modifies nextToken@*/
728 InitReduce (LRC_EQUATIONSYMTOK1);
731 static void EqSepSymTok (void) /*@modifies nextToken@*/
734 InitReduce (LRC_EQSEPSYMTOK1);
738 static void SelectSymTok (void) /*@modifies nextToken@*/
741 InitReduce (SELECTSYMTOK1);
744 static void OpenSymTok (void) /*@modifies nextToken@*/
747 InitReduce (OPENSYMTOK1);
750 static void SepSymTok (void) /*@modifies nextToken@*/
753 InitReduce (SEPSYMTOK1);
756 static void CloseSymTok (void) /*@modifies nextToken@*/
759 InitReduce (CLOSESYMTOK1);
762 static void SimpleIdTok (void) /*@modifies nextToken@*/
765 InitReduce (SIMPLEIDTOK1);
769 MapSymTok (void) /*@modifies nextToken@*/
772 InitReduce (MAPSYMTOK1);
776 MarkerSymTok (void) /*@modifies nextToken@*/
779 InitReduce (MARKERSYMTOK1);
784 CommentSymTok (void) /*@modifies nextToken@*/
787 InitReduce (COMMENTSYMTOK1);
792 SynClass (void) /*@modifies nextToken@*/
794 if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
796 nextToken = LCLScanNextToken ();
801 InitReduce (SYNCLASS1);
805 LocalUserError (nextToken, "expected synonym classification");
811 OldToken (void) /*@modifies nextToken@*/
814 InitReduce (OLDTOKEN1);
819 NewToken (void) /*@modifies nextToken@*/
822 InitReduce (NEWTOKEN1);
827 Token (void) /*@modifies nextToken@*/
829 if (ltoken_getCode (nextToken) == LLT_EOL
830 || ltoken_getCode (nextToken) == LEOFTOKEN)
832 LocalUserError (nextToken, "unexpected end-of-line or end-of-file");
836 LSLGenShift (nextToken);
837 nextToken = LCLScanNextToken ();
842 ** Init File Processing Routines, these routines use the shift-reduce sequence
843 ** produced by the init file parser and update the necessary tables for the
846 ** The same shift stack is used that LSL parser uses. A different reduce
847 ** procedure is used because the init file grammar is different from the LSL
852 InitReduce (LCLInitRuleCode rule) /*@modifies nextToken@*/
861 TRACE ("INITLINES1");
865 TRACE ("INITLINES2");
869 TRACE ("INITLINES3");
880 case CLASSIFICATION1:
881 TRACE ("CLASSIFICATION1");
884 case CLASSIFICATION2:
885 TRACE ("CLASSIFICATION2");
888 case CLASSIFICATION3:
889 TRACE ("CLASSIFICATION3");
893 TRACE ("CHARCLASS1");
897 TRACE ("CHARCLASS2");
901 TRACE ("CHARCLASS3");
905 TRACE ("CHARCLASS4");
909 TRACE ("CHARCLASS5");
913 TRACE ("CHARCLASS6");
916 case LRC_ENDCOMMENT1:
917 TRACE ("LRC_ENDCOMMENT1");
920 case LRC_ENDCOMMENT2:
921 TRACE ("LRC_ENDCOMMENT2");
940 case LRC_EXTENSIONCHAR1:
941 TRACE ("LRC_EXTENSIONCHAR1");
942 ProcessExtensionChar ();
946 TRACE ("SINGCHARS1");
950 TRACE ("SINGCHARS2");
954 TRACE ("WHITECHARS1");
958 TRACE ("WHITECHARS2");
961 case LRC_ENDCOMMENTCHAR1:
962 TRACE ("LRC_ENDCOMMENTCHAR1");
963 ProcessEndCommentChar ();
968 ProcessSingleChar (IDCHAR);
973 ProcessSingleChar (OPCHAR);
978 ProcessSingleChar (SINGLECHAR);
983 ProcessSingleChar (WHITECHAR);
987 TRACE ("TOKENCLASS1");
991 TRACE ("TOKENCLASS2");
995 TRACE ("TOKENCLASS3");
999 TRACE ("TOKENCLASS4");
1003 TRACE ("TOKENCLASS5");
1007 TRACE ("TOKENCLASS6");
1011 TRACE ("TOKENCLASS7");
1015 TRACE ("TOKENCLASS8");
1019 TRACE ("TOKENCLASS9");
1023 TRACE ("TOKENCLASS10");
1027 TRACE ("TOKENCLASS11");
1031 TRACE ("TOKENCLASS12");
1035 TRACE ("TOKENCLASS13");
1038 case QUANTIFIERSYMTOKS1:
1039 TRACE ("QUALIFERSYMTOKS1");
1042 case QUANTIFIERSYMTOKS2:
1043 TRACE ("QUANTIFIERSYMTOKS2");
1046 case LOGICALOPTOKS1:
1047 TRACE ("LOGICALOPTOKS1");
1050 case LOGICALOPTOKS2:
1051 TRACE ("LOGICALOPTOKS2");
1055 TRACE ("LRC_EQOPTOKS1");
1059 TRACE ("LRC_EQOPTOKS2");
1062 case LRC_EQUATIONSYMTOKS1:
1063 TRACE ("LRC_EQUATIONSYMTOKS1");
1066 case LRC_EQUATIONSYMTOKS2:
1067 TRACE ("LRC_EQUATIONSYMTOKS2");
1070 case LRC_EQSEPSYMTOKS1:
1071 TRACE ("LRC_EQSEPSYMTOKS1");
1074 case LRC_EQSEPSYMTOKS2:
1075 TRACE ("LRC_EQSEPSYMTOKS2");
1078 case SELECTSYMTOKS1:
1079 TRACE ("SELECTSYMTOKS1");
1082 case SELECTSYMTOKS2:
1083 TRACE ("SELECTSYMTOKS2");
1087 TRACE ("OPENSYMTOKS1");
1091 TRACE ("OPENSYMTOKS2");
1095 TRACE ("SEPSYMTOKS1");
1099 TRACE ("SEPSYMTOKS2");
1103 TRACE ("CLOSESYMTOKS1");
1107 TRACE ("CLOSESYMTOKS2");
1111 TRACE ("SIMPLEIDTOKS1");
1115 TRACE ("SIMPLEIDTOKS2");
1119 TRACE ("MAPSYMTOKS1");
1123 TRACE ("MAPSYMTOKS2");
1126 case MARKERSYMTOKS1:
1127 TRACE ("MARKERSYMTOKS1");
1130 case MARKERSYMTOKS2:
1131 TRACE ("MARKERSYMTOKS2");
1134 case COMMENTSYMTOKS1:
1135 TRACE ("COMMENTSYMTOKS1");
1138 case COMMENTSYMTOKS2:
1139 TRACE ("COMMENTSYMTOKS2");
1142 case QUANTIFIERSYMTOK1:
1143 TRACE ("QUANTIFERSYMTOK1");
1144 ProcessToken (quantifierSym);
1148 TRACE ("LOGICALOPTOK1");
1149 ProcessToken (logicalOp);
1153 TRACE ("LRC_EQOPTOK1");
1154 ProcessToken (eqOp);
1157 case LRC_EQUATIONSYMTOK1:
1158 TRACE ("LRC_EQUATIONSYMTOK1");
1159 ProcessToken (equationSym);
1162 case LRC_EQSEPSYMTOK1:
1163 TRACE ("LRC_EQSEPSYMTOK1");
1164 ProcessToken (eqSepSym);
1168 TRACE ("SELECTSYMTOK1");
1169 ProcessToken (selectSym);
1173 TRACE ("OPENSYMTOK1");
1174 ProcessToken (openSym);
1178 TRACE ("SEPSYMTOK1");
1179 ProcessToken (sepSym);
1183 TRACE ("CLOSESYMTOK1");
1184 ProcessToken (closeSym);
1188 TRACE ("SIMPLEIDTOK1");
1189 ProcessToken (simpleId);
1193 TRACE ("MAPSYMTOK1");
1194 ProcessToken (mapSym);
1198 TRACE ("MARKERSYMTOK1");
1199 ProcessToken (markerSym);
1202 case COMMENTSYMTOK1:
1203 TRACE ("COMMENTSYMTOK1");
1204 ProcessToken (commentSym);
1208 TRACE ("SYNCLASS1");
1213 TRACE ("OLDTOKEN1");
1217 TRACE ("NEWTOKEN1");
1221 llcontbuglit ("InitReduce: bad case");
1227 ** Reset the first character of the predefined extensionChar keywords when
1228 ** the extensionChar changes. e.g. "extensionChar @" changes "\forall" to
1233 UpdateXCharKeywords (charCode xChar)
1236 char xchar = (char)xChar;
1238 str = ltoken_getTextChars (ltoken_forall);
1241 str = ltoken_getTextChars (ltoken_and);
1244 str = ltoken_getTextChars (ltoken_or);
1247 str = ltoken_getTextChars (ltoken_implies);
1250 str = ltoken_getTextChars (ltoken_eq);
1253 str = ltoken_getTextChars (ltoken_neq);
1256 str = ltoken_getTextChars (ltoken_equals);
1259 str = ltoken_getTextChars (ltoken_eqsep);
1262 str = ltoken_getTextChars (ltoken_select);
1265 str = ltoken_getTextChars (ltoken_open);
1268 str = ltoken_getTextChars (ltoken_sep);
1271 str = ltoken_getTextChars (ltoken_close);
1274 str = ltoken_getTextChars (ltoken_id);
1277 str = ltoken_getTextChars (ltoken_arrow);
1280 str = ltoken_getTextChars (ltoken_marker);
1283 str = ltoken_getTextChars (ltoken_comment);
1287 /* Different from ProcessCharClass because only allow one extension */
1288 /* character. Therefore, the present extension character must be set to a */
1292 ProcessExtensionChar (void)
1294 ltoken stackToken = LSLGenTopPopShiftStack ();
1295 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1297 if (!defineSingleChar[(int)firstChar]
1298 && ltoken_isSingleChar (firstChar))
1301 ** Is a single character that has not been defined before.
1302 ** Can only have one extension char. Release old one.
1305 LCLSetCharClass (firstChar, CHC_EXTENSION);
1306 LCLSetCharClass ((char) currentExtensionChar, SINGLECHAR);
1307 currentExtensionChar = (charCode) firstChar;
1308 UpdateXCharKeywords (currentExtensionChar);
1312 /* Already redefined. Don't allow to be redefined. */
1313 LocalUserError (stackToken, "Character is already defined, cannot redefine");
1316 ltoken_free (stackToken);
1319 /* Different from ProcessSingleChar because allow any characters to be */
1320 /* endCommentChar and also set a different part of the scanner structure. */
1323 ProcessEndCommentChar (void)
1325 ltoken stackToken = LSLGenTopPopShiftStack ();
1326 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1328 if (LCLIsEndComment (firstChar))
1330 LocalUserError (stackToken,
1331 "already defined as a endCommentChar, cannot redefine");
1335 LCLSetEndCommentChar (firstChar, TRUE);
1337 ltoken_free (stackToken);
1341 ProcessSingleChar (charCode code)
1343 ltoken stackToken = LSLGenTopPopShiftStack ();
1344 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1346 if (!defineSingleChar[(int)firstChar]
1347 && ltoken_isSingleChar (firstChar))
1349 /* Is a single character that has not been defined before. */
1350 /* It's OK to redefine once. */
1351 LCLSetCharClass (firstChar, code);
1352 /* OK to mark as a defined singleChar even if not. Only check */
1353 /* defineSingleChar[] if defining a singleChar. */
1354 defineSingleChar[(int)(firstChar)] = TRUE;
1358 LocalUserError (stackToken, "Character is already defined, cannot redefine");
1361 ltoken_free (stackToken);
1365 ProcessToken (ltokenCode code)
1367 ltoken stackToken, ptok;
1369 stackToken = LSLGenTopPopShiftStack ();
1372 if (LCLIsSyn (ltoken_getText (stackToken)))
1374 LocalUserError (stackToken, "already defined as a synonym, cannot redefine");
1378 ** Get the token from the token table, so can check if the token
1379 ** was updated by a previous token.
1382 ptok = LCLGetToken (ltoken_getText (stackToken));
1384 if (ltoken_isStateDefined (ptok))
1386 LocalUserError (stackToken, "already defined, cannot redefine");
1389 LCLUpdateToken (code, ltoken_getText (stackToken), TRUE);
1390 ltoken_free (stackToken);
1395 ProcessSynonym (void)
1401 newtok = LSLGenTopPopShiftStack ();
1402 oldtok = LSLGenTopPopShiftStack ();
1405 /* ignore synonyms: Bool -> bool
1406 and: bool -> Bool */
1408 if ((ltoken_getText (newtok) == lsymbol_Bool ||
1409 ltoken_getText (newtok) == lsymbol_bool) &&
1410 (ltoken_getText (oldtok) == lsymbol_Bool ||
1411 ltoken_getText (oldtok) == lsymbol_bool)) return;
1414 if (ltoken_wasSyn (newtok))
1417 ** The token has a synonym. This means that the synonym was in the
1418 ** init file, so complain about redefining as a synonym again
1421 LocalUserError (newtok, "already is a synonym, cannot redefine");
1424 if (ltoken_hasSyn (newtok))
1427 ** newtok already has a synonym defined for it. Do not allow
1428 ** synonyms to be chained.
1431 LocalUserError (newtok,
1432 "newtok already has a synonym, cannot chain synonyms");
1435 if (ltoken_isStateDefined (newtok))
1437 LocalUserError (newtok, "newtok already defined, cannot redefine");
1440 LCLAddSyn (ltoken_getText (newtok), ltoken_getText (oldtok));
1442 ltoken_free (newtok);
1443 ltoken_free (oldtok);
1448 ** Utilities, in alphabetical order
1452 LocalUserError (ltoken t, char *msg)
1454 lclplainerror (message ("%s %s in the LCL init file. Ignoring line.",
1455 ltoken_unparse (t), cstring_fromChars (msg)));
1457 /* discard the whole current line */
1459 nextToken = LCLScanNextToken (); /* Discard bad token */
1461 while (ltoken_getCode (nextToken) != LLT_EOL
1462 && ltoken_getCode (nextToken) != LEOFTOKEN)
1464 nextToken = LCLScanNextToken ();
1470 * Required initialization and cleanup routines
1474 LCLProcessInitFileInit (void)
1478 LSLGenInit (FALSE); /* parsing LCLinit, not LSLinit */
1481 ** Insert the init file keywords into the token table as undefined
1482 ** SIMPLEIDs. They are defined as simpleIds since they must be treated
1483 ** that way if they do not appear as the first token on a line, and
1484 ** they must be treated that way for the actual LSL parsing. Save the
1485 ** tokens so can recognize as init file keywords when necessary.
1488 endCommentCharToken = insertSimpleToken ("endCommentChar");
1489 idCharToken = insertSimpleToken ("idChar");
1490 opCharToken = insertSimpleToken ("opChar");
1491 extensionCharToken = insertSimpleToken ("extensionChar");
1492 singleCharToken = insertSimpleToken ("singleChar");
1493 whiteCharToken = insertSimpleToken ("whiteChar");
1495 quantifierSymToken = insertSimpleToken ("quantifierSym");
1496 logicalOpToken = insertSimpleToken ("logicalOp");
1497 eqOpToken = insertSimpleToken ("eqOp");
1498 equationSymToken = insertSimpleToken ("equationSym");
1499 eqSepSymToken = insertSimpleToken ("eqSepSym");
1500 selectSymToken = insertSimpleToken ("selectSym");
1501 openSymToken = insertSimpleToken ("openSym");
1502 sepSymToken = insertSimpleToken ("sepSym");
1503 closeSymToken = insertSimpleToken ("closeSym");
1504 simpleIdToken = insertSimpleToken ("simpleId");
1505 mapSymToken = insertSimpleToken ("mapSym");
1506 markerSymToken = insertSimpleToken ("markerSym");
1507 commentSymToken = insertSimpleToken ("commentSym");
1509 synonymToken = insertSimpleToken ("synonym");
1512 ** Initialize defineSingleChar array to all FALSE to signal that no
1513 ** characters have been redefined as singleChar.
1516 for (i = 0; i <= LASTCHAR; i++)
1518 defineSingleChar[i] = FALSE;
1522 ** Record the current extension character so can redefine back to
1523 ** singleChar if a new extension character is redefined.
1526 currentExtensionChar = (charCode) CHAREXTENDER;
1528 /* Init file processing needs to have EOL reported. */
1530 LCLReportEolTokens (TRUE);
1532 /* Not: context_getBoolName () */
1534 LCLAddSyn (lsymbol_fromChars ("Bool"),
1535 lsymbol_fromChars ("bool"));
1539 LCLProcessInitFileReset (void)
1541 nextToken = LCLScanNextToken ();
1545 LCLProcessInitFileCleanup (void)