2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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 lclinit_process (void)
160 InitReduce (INITFILE1);
162 if (ltoken_getCode (nextToken) != LEOFTOKEN)
164 LocalUserError (nextToken, "unexpected tokens after end-of-file");
172 InitReduce (INITLINES1);
174 if (ltoken_getCode (nextToken) != LEOFTOKEN)
177 InitReduce (INITLINES2);
180 while (ltoken_getCode (nextToken) != LEOFTOKEN)
183 InitReduce (INITLINES3);
190 if (ltoken_getCode (nextToken) == LLT_EOL)
192 /* Nothing on line. */
193 InitReduce (INITLINE1);
198 InitReduce (INITLINE2);
201 if (ltoken_getCode (nextToken) != LLT_EOL)
203 LocalUserError (nextToken, "Unexpected tokens on line");
206 nextToken = LCLScanNextToken (); /* Discard EOL */
210 Classification (void)
212 lsymbol ntext = ltoken_getRawText (nextToken);
214 if (ntext == ltoken_getText (endCommentCharToken)
215 || ntext == ltoken_getText (idCharToken)
216 || ntext == ltoken_getText (opCharToken)
217 || ntext == ltoken_getText (extensionCharToken)
218 || ntext == ltoken_getText (singleCharToken)
219 || ntext == ltoken_getText (whiteCharToken))
222 InitReduce (CLASSIFICATION1);
224 else if (ntext == ltoken_getText (quantifierSymToken)
225 || ntext == ltoken_getText (logicalOpToken)
226 || ntext == ltoken_getText (eqOpToken)
227 || ntext == ltoken_getText (equationSymToken)
228 || ntext == ltoken_getText (eqSepSymToken)
229 || ntext == ltoken_getText (selectSymToken)
230 || ntext == ltoken_getText (openSymToken)
231 || ntext == ltoken_getText (sepSymToken)
232 || ntext == ltoken_getText (closeSymToken)
233 || ntext == ltoken_getText (simpleIdToken)
234 || ntext == ltoken_getText (mapSymToken)
235 || ntext == ltoken_getText (markerSymToken)
236 || ntext == ltoken_getText (commentSymToken))
239 InitReduce (CLASSIFICATION2);
241 else if (ntext == ltoken_getText (synonymToken))
244 InitReduce (CLASSIFICATION3);
248 llbug (message ("Expected character, token, or synonym classification: %s",
249 ltoken_getRawString (nextToken)));
250 /* pop off all tokens on this line */
257 ltoken charClassToken;
258 charClassToken = nextToken;
259 nextToken = LCLScanNextToken (); /* Discard char class keyword. */
261 if (ltoken_getRawText (charClassToken) == ltoken_getText (endCommentCharToken))
264 InitReduce (CHARCLASS1);
266 else if (ltoken_getRawText (charClassToken) == ltoken_getText (idCharToken))
269 InitReduce (CHARCLASS2);
271 else if (ltoken_getRawText (charClassToken) == ltoken_getText (opCharToken))
274 InitReduce (CHARCLASS3);
276 else if (ltoken_getRawText (charClassToken)
277 == ltoken_getText (extensionCharToken))
280 InitReduce (CHARCLASS4);
282 else if (ltoken_getRawText (charClassToken) == ltoken_getText (singleCharToken))
285 InitReduce (CHARCLASS5);
287 else if (ltoken_getRawText (charClassToken) == ltoken_getText (whiteCharToken))
290 InitReduce (CHARCLASS6);
294 LocalUserError (nextToken, "expected character classification");
299 EndCommentChars (void)
302 InitReduce (LRC_ENDCOMMENT1);
304 while (ltoken_getCode (nextToken) != LLT_EOL)
307 InitReduce (LRC_ENDCOMMENT2);
312 static void IdChars (void) /*@modifies nextToken@*/
315 InitReduce (IDCHARS1);
317 while (ltoken_getCode (nextToken) != LLT_EOL)
320 InitReduce (IDCHARS2);
324 static void OpChars (void) /*@modifies nextToken@*/
327 InitReduce (OPCHARS1);
329 while (ltoken_getCode (nextToken) != LLT_EOL)
332 InitReduce (OPCHARS2);
336 static void ExtensionChar (void) /*@modifies nextToken@*/
338 if (hasFirstChar (nextToken))
340 LSLGenShift (nextToken);
341 nextToken = LCLScanNextToken ();
342 InitReduce (LRC_EXTENSIONCHAR1);
346 LocalUserError (nextToken, "expected only one character");
350 static void SingChars (void) /*@modifies nextToken@*/
353 InitReduce (SINGCHARS1);
355 while (ltoken_getCode (nextToken) != LLT_EOL)
358 InitReduce (SINGCHARS2);
362 static void WhiteChars (void) /*@modifies nextToken@*/
365 InitReduce (WHITECHARS1);
367 while (ltoken_getCode (nextToken) != LLT_EOL)
370 InitReduce (WHITECHARS2);
374 static void EndCommentChar (void) /*@modifies nextToken@*/
376 if (ltoken_isChar (nextToken))
378 LSLGenShift (nextToken);
379 nextToken = LCLScanNextToken ();
380 InitReduce (LRC_ENDCOMMENTCHAR1);
384 LocalUserError (nextToken, "expected only one character");
388 static void IdChar (void) /*@modifies nextToken@*/
390 if (hasFirstChar (nextToken))
392 LSLGenShift (nextToken);
393 nextToken = LCLScanNextToken ();
394 InitReduce (IDCHAR1);
398 LocalUserError (nextToken,
399 "Character is already defined, cannot redefine");
403 static void OpChar (void) /*@modifies nextToken@*/
405 if (hasFirstChar (nextToken))
407 LSLGenShift (nextToken);
408 nextToken = LCLScanNextToken ();
409 InitReduce (OPCHAR1);
413 LocalUserError (nextToken,
414 "Character is already defined, cannot redefine");
418 static void SingChar (void) /*@modifies nextToken@*/
420 if (hasFirstChar (nextToken))
422 LSLGenShift (nextToken);
423 nextToken = LCLScanNextToken ();
424 InitReduce (SINGCHAR1);
428 LocalUserError (nextToken,
429 "Character is already defined, cannot redefine");
433 static void WhiteChar (void) /*@modifies nextToken@*/
435 if (hasFirstChar (nextToken))
437 LSLGenShift (nextToken);
438 nextToken = LCLScanNextToken ();
439 InitReduce (WHITECHAR1);
443 LocalUserError (nextToken, "Character is already defined, cannot redefine");
448 TokenClass (void) /*@modifies nextToken@*/
450 ltoken tokenClassToken;
451 lsymbol ttext = ltoken_getRawText (nextToken);
453 tokenClassToken = nextToken;
455 /* Discard token class keyword. */
456 nextToken = LCLScanNextToken ();
458 if (ttext == ltoken_getText (quantifierSymToken))
460 QuantifierSymToks ();
461 InitReduce (TOKENCLASS1);
463 else if (ttext == ltoken_getText (logicalOpToken))
466 InitReduce (TOKENCLASS2);
468 else if (ttext == ltoken_getText (eqOpToken))
471 InitReduce (TOKENCLASS3);
473 else if (ttext == ltoken_getText (equationSymToken))
476 InitReduce (TOKENCLASS4);
478 else if (ttext == ltoken_getText (eqSepSymToken))
481 InitReduce (TOKENCLASS5);
483 else if (ttext == ltoken_getText (selectSymToken))
486 InitReduce (TOKENCLASS6);
488 else if (ttext == ltoken_getText (openSymToken))
491 InitReduce (TOKENCLASS7);
493 else if (ttext == ltoken_getText (sepSymToken))
496 InitReduce (TOKENCLASS8);
498 else if (ttext == ltoken_getText (closeSymToken))
501 InitReduce (TOKENCLASS9);
503 else if (ttext == ltoken_getText (simpleIdToken))
506 InitReduce (TOKENCLASS10);
508 else if (ttext == ltoken_getText (mapSymToken))
511 InitReduce (TOKENCLASS11);
513 else if (ttext == ltoken_getText (markerSymToken))
516 InitReduce (TOKENCLASS12);
518 else if (ttext == ltoken_getText (commentSymToken))
521 InitReduce (TOKENCLASS13);
525 LocalUserError (nextToken, "expected token classification");
530 QuantifierSymToks (void) /*@modifies nextToken@*/
533 InitReduce (QUANTIFIERSYMTOKS1);
535 while (ltoken_getCode (nextToken) != LLT_EOL)
538 InitReduce (QUANTIFIERSYMTOKS2);
543 LogicalOpToks (void) /*@modifies nextToken@*/
546 InitReduce (LOGICALOPTOKS1);
548 while (ltoken_getCode (nextToken) != LLT_EOL)
551 InitReduce (LOGICALOPTOKS2);
556 EqOpToks (void) /*@modifies nextToken@*/
559 InitReduce (LRC_EQOPTOKS1);
561 while (ltoken_getCode (nextToken) != LLT_EOL)
564 InitReduce (LRC_EQOPTOKS2);
569 EquationSymToks (void) /*@modifies nextToken@*/
572 InitReduce (LRC_EQUATIONSYMTOKS1);
574 while (ltoken_getCode (nextToken) != LLT_EOL)
577 InitReduce (LRC_EQUATIONSYMTOKS2);
582 EqSepSymToks (void) /*@modifies nextToken@*/
585 InitReduce (LRC_EQSEPSYMTOKS1);
587 while (ltoken_getCode (nextToken) != LLT_EOL)
590 InitReduce (LRC_EQSEPSYMTOKS2);
595 SelectSymToks (void) /*@modifies nextToken@*/
598 InitReduce (SELECTSYMTOKS1);
600 while (ltoken_getCode (nextToken) != LLT_EOL)
603 InitReduce (SELECTSYMTOKS2);
608 OpenSymToks (void) /*@modifies nextToken@*/
611 InitReduce (OPENSYMTOKS1);
613 while (ltoken_getCode (nextToken) != LLT_EOL)
616 InitReduce (OPENSYMTOKS2);
621 SepSymToks (void) /*@modifies nextToken@*/
624 InitReduce (SEPSYMTOKS1);
626 while (ltoken_getCode (nextToken) != LLT_EOL)
629 InitReduce (SEPSYMTOKS2);
634 CloseSymToks (void) /*@modifies nextToken@*/
637 InitReduce (CLOSESYMTOKS1);
639 while (ltoken_getCode (nextToken) != LLT_EOL)
642 InitReduce (CLOSESYMTOKS2);
647 SimpleIdToks (void) /*@modifies nextToken@*/
650 InitReduce (SIMPLEIDTOKS1);
652 while (ltoken_getCode (nextToken) != LLT_EOL)
655 InitReduce (SIMPLEIDTOKS2);
660 MapSymToks (void) /*@modifies nextToken@*/
663 InitReduce (MAPSYMTOKS1);
665 while (ltoken_getCode (nextToken) != LLT_EOL)
668 InitReduce (MAPSYMTOKS2);
673 MarkerSymToks (void) /*@modifies nextToken@*/
676 InitReduce (MARKERSYMTOKS1);
678 while (ltoken_getCode (nextToken) != LLT_EOL)
681 InitReduce (MARKERSYMTOKS2);
686 CommentSymToks (void) /*@modifies nextToken@*/
689 InitReduce (COMMENTSYMTOKS1);
691 while (ltoken_getCode (nextToken) != LLT_EOL)
694 InitReduce (COMMENTSYMTOKS2);
699 QuantifierSymTok (void) /*@modifies nextToken@*/
702 InitReduce (QUANTIFIERSYMTOK1);
706 LogicalOpTok (void) /*@modifies nextToken@*/
709 InitReduce (LOGICALOPTOK1);
713 EqOpTok (void) /*@modifies nextToken@*/
716 InitReduce (LRC_EQOPTOK1);
719 static void EquationSymTok (void) /*@modifies nextToken@*/
722 InitReduce (LRC_EQUATIONSYMTOK1);
725 static void EqSepSymTok (void) /*@modifies nextToken@*/
728 InitReduce (LRC_EQSEPSYMTOK1);
732 static void SelectSymTok (void) /*@modifies nextToken@*/
735 InitReduce (SELECTSYMTOK1);
738 static void OpenSymTok (void) /*@modifies nextToken@*/
741 InitReduce (OPENSYMTOK1);
744 static void SepSymTok (void) /*@modifies nextToken@*/
747 InitReduce (SEPSYMTOK1);
750 static void CloseSymTok (void) /*@modifies nextToken@*/
753 InitReduce (CLOSESYMTOK1);
756 static void SimpleIdTok (void) /*@modifies nextToken@*/
759 InitReduce (SIMPLEIDTOK1);
763 MapSymTok (void) /*@modifies nextToken@*/
766 InitReduce (MAPSYMTOK1);
770 MarkerSymTok (void) /*@modifies nextToken@*/
773 InitReduce (MARKERSYMTOK1);
778 CommentSymTok (void) /*@modifies nextToken@*/
781 InitReduce (COMMENTSYMTOK1);
786 SynClass (void) /*@modifies nextToken@*/
788 if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
790 nextToken = LCLScanNextToken ();
795 InitReduce (SYNCLASS1);
799 LocalUserError (nextToken, "expected synonym classification");
805 OldToken (void) /*@modifies nextToken@*/
808 InitReduce (OLDTOKEN1);
813 NewToken (void) /*@modifies nextToken@*/
816 InitReduce (NEWTOKEN1);
821 Token (void) /*@modifies nextToken@*/
823 if (ltoken_getCode (nextToken) == LLT_EOL
824 || ltoken_getCode (nextToken) == LEOFTOKEN)
826 LocalUserError (nextToken, "unexpected end-of-line or end-of-file");
830 LSLGenShift (nextToken);
831 nextToken = LCLScanNextToken ();
836 ** Init File Processing Routines, these routines use the shift-reduce sequence
837 ** produced by the init file parser and update the necessary tables for the
840 ** The same shift stack is used that LSL parser uses. A different reduce
841 ** procedure is used because the init file grammar is different from the LSL
846 InitReduce (LCLInitRuleCode rule) /*@modifies nextToken@*/
855 TRACE ("INITLINES1");
859 TRACE ("INITLINES2");
863 TRACE ("INITLINES3");
874 case CLASSIFICATION1:
875 TRACE ("CLASSIFICATION1");
878 case CLASSIFICATION2:
879 TRACE ("CLASSIFICATION2");
882 case CLASSIFICATION3:
883 TRACE ("CLASSIFICATION3");
887 TRACE ("CHARCLASS1");
891 TRACE ("CHARCLASS2");
895 TRACE ("CHARCLASS3");
899 TRACE ("CHARCLASS4");
903 TRACE ("CHARCLASS5");
907 TRACE ("CHARCLASS6");
910 case LRC_ENDCOMMENT1:
911 TRACE ("LRC_ENDCOMMENT1");
914 case LRC_ENDCOMMENT2:
915 TRACE ("LRC_ENDCOMMENT2");
934 case LRC_EXTENSIONCHAR1:
935 TRACE ("LRC_EXTENSIONCHAR1");
936 ProcessExtensionChar ();
940 TRACE ("SINGCHARS1");
944 TRACE ("SINGCHARS2");
948 TRACE ("WHITECHARS1");
952 TRACE ("WHITECHARS2");
955 case LRC_ENDCOMMENTCHAR1:
956 TRACE ("LRC_ENDCOMMENTCHAR1");
957 ProcessEndCommentChar ();
962 ProcessSingleChar (IDCHAR);
967 ProcessSingleChar (OPCHAR);
972 ProcessSingleChar (SINGLECHAR);
977 ProcessSingleChar (WHITECHAR);
981 TRACE ("TOKENCLASS1");
985 TRACE ("TOKENCLASS2");
989 TRACE ("TOKENCLASS3");
993 TRACE ("TOKENCLASS4");
997 TRACE ("TOKENCLASS5");
1001 TRACE ("TOKENCLASS6");
1005 TRACE ("TOKENCLASS7");
1009 TRACE ("TOKENCLASS8");
1013 TRACE ("TOKENCLASS9");
1017 TRACE ("TOKENCLASS10");
1021 TRACE ("TOKENCLASS11");
1025 TRACE ("TOKENCLASS12");
1029 TRACE ("TOKENCLASS13");
1032 case QUANTIFIERSYMTOKS1:
1033 TRACE ("QUALIFERSYMTOKS1");
1036 case QUANTIFIERSYMTOKS2:
1037 TRACE ("QUANTIFIERSYMTOKS2");
1040 case LOGICALOPTOKS1:
1041 TRACE ("LOGICALOPTOKS1");
1044 case LOGICALOPTOKS2:
1045 TRACE ("LOGICALOPTOKS2");
1049 TRACE ("LRC_EQOPTOKS1");
1053 TRACE ("LRC_EQOPTOKS2");
1056 case LRC_EQUATIONSYMTOKS1:
1057 TRACE ("LRC_EQUATIONSYMTOKS1");
1060 case LRC_EQUATIONSYMTOKS2:
1061 TRACE ("LRC_EQUATIONSYMTOKS2");
1064 case LRC_EQSEPSYMTOKS1:
1065 TRACE ("LRC_EQSEPSYMTOKS1");
1068 case LRC_EQSEPSYMTOKS2:
1069 TRACE ("LRC_EQSEPSYMTOKS2");
1072 case SELECTSYMTOKS1:
1073 TRACE ("SELECTSYMTOKS1");
1076 case SELECTSYMTOKS2:
1077 TRACE ("SELECTSYMTOKS2");
1081 TRACE ("OPENSYMTOKS1");
1085 TRACE ("OPENSYMTOKS2");
1089 TRACE ("SEPSYMTOKS1");
1093 TRACE ("SEPSYMTOKS2");
1097 TRACE ("CLOSESYMTOKS1");
1101 TRACE ("CLOSESYMTOKS2");
1105 TRACE ("SIMPLEIDTOKS1");
1109 TRACE ("SIMPLEIDTOKS2");
1113 TRACE ("MAPSYMTOKS1");
1117 TRACE ("MAPSYMTOKS2");
1120 case MARKERSYMTOKS1:
1121 TRACE ("MARKERSYMTOKS1");
1124 case MARKERSYMTOKS2:
1125 TRACE ("MARKERSYMTOKS2");
1128 case COMMENTSYMTOKS1:
1129 TRACE ("COMMENTSYMTOKS1");
1132 case COMMENTSYMTOKS2:
1133 TRACE ("COMMENTSYMTOKS2");
1136 case QUANTIFIERSYMTOK1:
1137 TRACE ("QUANTIFERSYMTOK1");
1138 ProcessToken (quantifierSym);
1142 TRACE ("LOGICALOPTOK1");
1143 ProcessToken (logicalOp);
1147 TRACE ("LRC_EQOPTOK1");
1148 ProcessToken (eqOp);
1151 case LRC_EQUATIONSYMTOK1:
1152 TRACE ("LRC_EQUATIONSYMTOK1");
1153 ProcessToken (equationSym);
1156 case LRC_EQSEPSYMTOK1:
1157 TRACE ("LRC_EQSEPSYMTOK1");
1158 ProcessToken (eqSepSym);
1162 TRACE ("SELECTSYMTOK1");
1163 ProcessToken (selectSym);
1167 TRACE ("OPENSYMTOK1");
1168 ProcessToken (openSym);
1172 TRACE ("SEPSYMTOK1");
1173 ProcessToken (sepSym);
1177 TRACE ("CLOSESYMTOK1");
1178 ProcessToken (closeSym);
1182 TRACE ("SIMPLEIDTOK1");
1183 ProcessToken (simpleId);
1187 TRACE ("MAPSYMTOK1");
1188 ProcessToken (mapSym);
1192 TRACE ("MARKERSYMTOK1");
1193 ProcessToken (markerSym);
1196 case COMMENTSYMTOK1:
1197 TRACE ("COMMENTSYMTOK1");
1198 ProcessToken (commentSym);
1202 TRACE ("SYNCLASS1");
1207 TRACE ("OLDTOKEN1");
1211 TRACE ("NEWTOKEN1");
1215 llcontbuglit ("InitReduce: bad case");
1221 ** Reset the first character of the predefined extensionChar keywords when
1222 ** the extensionChar changes. e.g. "extensionChar @" changes "\forall" to
1227 UpdateXCharKeywords (charCode xChar)
1230 char xchar = (char)xChar;
1232 str = ltoken_getTextChars (ltoken_forall);
1235 str = ltoken_getTextChars (ltoken_and);
1238 str = ltoken_getTextChars (ltoken_or);
1241 str = ltoken_getTextChars (ltoken_implies);
1244 str = ltoken_getTextChars (ltoken_eq);
1247 str = ltoken_getTextChars (ltoken_neq);
1250 str = ltoken_getTextChars (ltoken_equals);
1253 str = ltoken_getTextChars (ltoken_eqsep);
1256 str = ltoken_getTextChars (ltoken_select);
1259 str = ltoken_getTextChars (ltoken_open);
1262 str = ltoken_getTextChars (ltoken_sep);
1265 str = ltoken_getTextChars (ltoken_close);
1268 str = ltoken_getTextChars (ltoken_id);
1271 str = ltoken_getTextChars (ltoken_arrow);
1274 str = ltoken_getTextChars (ltoken_marker);
1277 str = ltoken_getTextChars (ltoken_comment);
1281 /* Different from ProcessCharClass because only allow one extension */
1282 /* character. Therefore, the present extension character must be set to a */
1286 ProcessExtensionChar (void)
1288 ltoken stackToken = LSLGenTopPopShiftStack ();
1289 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1291 if (!defineSingleChar[(int)firstChar]
1292 && ltoken_isSingleChar (firstChar))
1295 ** Is a single character that has not been defined before.
1296 ** Can only have one extension char. Release old one.
1299 LCLSetCharClass (firstChar, CHC_EXTENSION);
1300 LCLSetCharClass ((char) currentExtensionChar, SINGLECHAR);
1301 currentExtensionChar = (charCode) firstChar;
1302 UpdateXCharKeywords (currentExtensionChar);
1306 /* Already redefined. Don't allow to be redefined. */
1307 LocalUserError (stackToken, "Character is already defined, cannot redefine");
1310 ltoken_free (stackToken);
1313 /* Different from ProcessSingleChar because allow any characters to be */
1314 /* endCommentChar and also set a different part of the scanner structure. */
1317 ProcessEndCommentChar (void)
1319 ltoken stackToken = LSLGenTopPopShiftStack ();
1320 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1322 if (LCLIsEndComment (firstChar))
1324 LocalUserError (stackToken,
1325 "already defined as a endCommentChar, cannot redefine");
1329 LCLSetEndCommentChar (firstChar, TRUE);
1331 ltoken_free (stackToken);
1335 ProcessSingleChar (charCode code)
1337 ltoken stackToken = LSLGenTopPopShiftStack ();
1338 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1340 if (!defineSingleChar[(int)firstChar]
1341 && ltoken_isSingleChar (firstChar))
1343 /* Is a single character that has not been defined before. */
1344 /* It's OK to redefine once. */
1345 LCLSetCharClass (firstChar, code);
1346 /* OK to mark as a defined singleChar even if not. Only check */
1347 /* defineSingleChar[] if defining a singleChar. */
1348 defineSingleChar[(int)(firstChar)] = TRUE;
1352 LocalUserError (stackToken, "Character is already defined, cannot redefine");
1355 ltoken_free (stackToken);
1359 ProcessToken (ltokenCode code)
1361 ltoken stackToken, ptok;
1363 stackToken = LSLGenTopPopShiftStack ();
1366 if (LCLIsSyn (ltoken_getText (stackToken)))
1368 LocalUserError (stackToken, "already defined as a synonym, cannot redefine");
1372 ** Get the token from the token table, so can check if the token
1373 ** was updated by a previous token.
1376 ptok = LCLGetToken (ltoken_getText (stackToken));
1378 if (ltoken_isStateDefined (ptok))
1380 LocalUserError (stackToken, "already defined, cannot redefine");
1383 LCLUpdateToken (code, ltoken_getText (stackToken), TRUE);
1384 ltoken_free (stackToken);
1389 ProcessSynonym (void)
1395 newtok = LSLGenTopPopShiftStack ();
1396 oldtok = LSLGenTopPopShiftStack ();
1399 /* ignore synonyms: Bool -> bool
1400 and: bool -> Bool */
1402 if ((ltoken_getText (newtok) == lsymbol_Bool ||
1403 ltoken_getText (newtok) == lsymbol_bool) &&
1404 (ltoken_getText (oldtok) == lsymbol_Bool ||
1405 ltoken_getText (oldtok) == lsymbol_bool)) return;
1408 if (ltoken_wasSyn (newtok))
1411 ** The token has a synonym. This means that the synonym was in the
1412 ** init file, so complain about redefining as a synonym again
1415 LocalUserError (newtok, "already is a synonym, cannot redefine");
1418 if (ltoken_hasSyn (newtok))
1421 ** newtok already has a synonym defined for it. Do not allow
1422 ** synonyms to be chained.
1425 LocalUserError (newtok,
1426 "newtok already has a synonym, cannot chain synonyms");
1429 if (ltoken_isStateDefined (newtok))
1431 LocalUserError (newtok, "newtok already defined, cannot redefine");
1434 LCLAddSyn (ltoken_getText (newtok), ltoken_getText (oldtok));
1436 ltoken_free (newtok);
1437 ltoken_free (oldtok);
1442 ** Utilities, in alphabetical order
1446 LocalUserError (ltoken t, char *msg)
1448 lclplainerror (message ("%s %s in the LCL init file. Ignoring line.",
1449 ltoken_unparse (t), cstring_fromChars (msg)));
1451 /* discard the whole current line */
1453 nextToken = LCLScanNextToken (); /* Discard bad token */
1455 while (ltoken_getCode (nextToken) != LLT_EOL
1456 && ltoken_getCode (nextToken) != LEOFTOKEN)
1458 nextToken = LCLScanNextToken ();
1464 * Required initialization and cleanup routines
1468 lclinit_initMod (void)
1472 LSLGenInit (FALSE); /* parsing LCLinit, not LSLinit */
1475 ** Insert the init file keywords into the token table as undefined
1476 ** SIMPLEIDs. They are defined as simpleIds since they must be treated
1477 ** that way if they do not appear as the first token on a line, and
1478 ** they must be treated that way for the actual LSL parsing. Save the
1479 ** tokens so can recognize as init file keywords when necessary.
1482 endCommentCharToken = insertSimpleToken ("endCommentChar");
1483 idCharToken = insertSimpleToken ("idChar");
1484 opCharToken = insertSimpleToken ("opChar");
1485 extensionCharToken = insertSimpleToken ("extensionChar");
1486 singleCharToken = insertSimpleToken ("singleChar");
1487 whiteCharToken = insertSimpleToken ("whiteChar");
1489 quantifierSymToken = insertSimpleToken ("quantifierSym");
1490 logicalOpToken = insertSimpleToken ("logicalOp");
1491 eqOpToken = insertSimpleToken ("eqOp");
1492 equationSymToken = insertSimpleToken ("equationSym");
1493 eqSepSymToken = insertSimpleToken ("eqSepSym");
1494 selectSymToken = insertSimpleToken ("selectSym");
1495 openSymToken = insertSimpleToken ("openSym");
1496 sepSymToken = insertSimpleToken ("sepSym");
1497 closeSymToken = insertSimpleToken ("closeSym");
1498 simpleIdToken = insertSimpleToken ("simpleId");
1499 mapSymToken = insertSimpleToken ("mapSym");
1500 markerSymToken = insertSimpleToken ("markerSym");
1501 commentSymToken = insertSimpleToken ("commentSym");
1503 synonymToken = insertSimpleToken ("synonym");
1506 ** Initialize defineSingleChar array to all FALSE to signal that no
1507 ** characters have been redefined as singleChar.
1510 for (i = 0; i <= LASTCHAR; i++)
1512 defineSingleChar[i] = FALSE;
1516 ** Record the current extension character so can redefine back to
1517 ** singleChar if a new extension character is redefined.
1520 currentExtensionChar = (charCode) CHAREXTENDER;
1522 /* Init file processing needs to have EOL reported. */
1524 LCLReportEolTokens (TRUE);
1526 /* Not: context_getBoolName () */
1528 LCLAddSyn (lsymbol_fromChars ("Bool"),
1529 lsymbol_fromChars ("bool"));
1533 lclinit_reset (void)
1535 nextToken = LCLScanNextToken ();
1539 lclinit_cleanup (void)