Less permissive syntax for notreached comment.
[splint-patched.git] / src / lclinit.c
blob5e696acca8427e7cdc42923157a5418d4281b849
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
5 **
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.
10 **
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.
15 **
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
25 ** lslinit.c
27 ** Processor for Larch Shared Language Init Files
30 # include "splintMacros.nf"
31 # include "basic.h"
33 # include "lslscanline.h"
34 # include "lslinit.h"
35 # include "shift.h"
37 # include "lclscan.h"
38 # include "lclscanline.h"
39 # include "lcltokentable.h"
40 # include "lclsyntable.h"
41 # include "lclinit.h"
43 # include "llgrammar.h"
45 # if 0
46 /*@notfunction@*/
47 # define TRACE(rule) printf ("Reducing: %s\n", rule)
48 # else
49 /*@notfunction@*/
50 # define TRACE(rule)
51 # endif
53 static /*@dependent@*/ ltoken nextToken;
54 static void InitLines (void) /*@modifies nextToken@*/ ;
55 static void InitLine (void) /*@modifies nextToken@*/;
56 static void Classification (void) /*@modifies nextToken@*/;
57 static void CharClass (void) /*@modifies nextToken@*/;
59 static void EndCommentChars (void) /*@modifies nextToken@*/ ;
60 static void IdChars (void) /*@modifies nextToken@*/ ;
61 static void OpChars (void) /*@modifies nextToken@*/ ;
62 static void ExtensionChar (void) /*@modifies nextToken@*/ ;
63 static void SingChars (void) /*@modifies nextToken@*/ ;
64 static void WhiteChars (void) /*@modifies nextToken@*/ ;
65 static void EndCommentChar (void) /*@modifies nextToken@*/ ;
66 static void IdChar (void) /*@modifies nextToken@*/ ;
67 static void OpChar (void) /*@modifies nextToken@*/ ;
68 static void SingChar (void) /*@modifies nextToken@*/ ;
69 static void WhiteChar (void) /*@modifies nextToken@*/ ;
71 static void TokenClass (void) /*@modifies nextToken@*/ ;
72 static void QuantifierSymToks (void) /*@modifies nextToken@*/ ;
73 static void LogicalOpToks (void) /*@modifies nextToken@*/ ;
74 static void EqOpToks (void) /*@modifies nextToken@*/ ;
75 static void EquationSymToks (void) /*@modifies nextToken@*/ ;
76 static void EqSepSymToks (void) /*@modifies nextToken@*/ ;
77 static void SelectSymToks (void) /*@modifies nextToken@*/ ;
78 static void OpenSymToks (void) /*@modifies nextToken@*/ ;
79 static void SepSymToks (void) /*@modifies nextToken@*/ ;
80 static void CloseSymToks (void) /*@modifies nextToken@*/ ;
81 static void SimpleIdToks (void) /*@modifies nextToken@*/ ;
82 static void MapSymToks (void) /*@modifies nextToken@*/ ;
83 static void MarkerSymToks (void) /*@modifies nextToken@*/ ;
84 static void CommentSymToks (void) /*@modifies nextToken@*/ ;
85 static void QuantifierSymTok (void) /*@modifies nextToken@*/ ;
86 static void LogicalOpTok (void) /*@modifies nextToken@*/ ;
87 static void EqOpTok (void) /*@modifies nextToken@*/ ;
88 static void EquationSymTok (void) /*@modifies nextToken@*/ ;
89 static void EqSepSymTok (void) /*@modifies nextToken@*/ ;
90 static void SelectSymTok (void) /*@modifies nextToken@*/ ;
91 static void OpenSymTok (void) /*@modifies nextToken@*/ ;
92 static void SepSymTok (void) /*@modifies nextToken@*/ ;
93 static void CloseSymTok (void) /*@modifies nextToken@*/ ;
94 static void SimpleIdTok (void) /*@modifies nextToken@*/ ;
95 static void MapSymTok (void) /*@modifies nextToken@*/ ;
96 static void MarkerSymTok (void) /*@modifies nextToken@*/ ;
97 static void CommentSymTok (void) /*@modifies nextToken@*/ ;
98 static void SynClass (void) /*@modifies nextToken@*/ ;
99 static void OldToken (void) /*@modifies nextToken@*/ ;
100 static void NewToken (void) /*@modifies nextToken@*/ ;
101 static void Token (void) /*@modifies nextToken@*/ ;
103 static void InitReduce (LCLInitRuleCode p_rule) /*@modifies nextToken@*/ ;
104 static void UpdateXCharKeywords (charCode p_xChar) /*@modifies nextToken@*/ ;
105 static void ProcessExtensionChar (void) /*@modifies nextToken@*/ ;
106 static void ProcessEndCommentChar (void) /*@modifies nextToken@*/ ;
107 static void ProcessSingleChar (charCode p_code) /*@modifies nextToken@*/ ;
108 static void ProcessToken (ltokenCode p_code) /*@modifies nextToken@*/ ;
109 static void ProcessSynonym (void) /*@modifies nextToken@*/ ;
111 static void
112 LocalUserError (/*@unused@*/ ltoken p_t, /*@temp@*/ char *p_msg)
113 /*@modifies *g_warningstream@*/ ;
115 /* If TRUE character has been redefined as a singleChar. */
116 static bool defineSingleChar[LASTCHAR + 1];
118 static charCode currentExtensionChar;
120 /* LSL init file keyword tokens. */
122 static /*@exposed@*/ ltoken endCommentCharToken;
123 static /*@exposed@*/ ltoken idCharToken;
124 static /*@exposed@*/ ltoken opCharToken;
125 static /*@exposed@*/ ltoken extensionCharToken;
126 static /*@exposed@*/ ltoken singleCharToken;
127 static /*@exposed@*/ ltoken whiteCharToken;
129 static /*@exposed@*/ ltoken quantifierSymToken;
130 static /*@exposed@*/ ltoken logicalOpToken;
131 static /*@exposed@*/ ltoken eqOpToken;
132 static /*@exposed@*/ ltoken equationSymToken;
133 static /*@exposed@*/ ltoken eqSepSymToken;
134 static /*@exposed@*/ ltoken selectSymToken;
135 static /*@exposed@*/ ltoken openSymToken;
136 static /*@exposed@*/ ltoken sepSymToken;
137 static /*@exposed@*/ ltoken closeSymToken;
138 static /*@exposed@*/ ltoken simpleIdToken;
139 static /*@exposed@*/ ltoken mapSymToken;
140 static /*@exposed@*/ ltoken markerSymToken;
141 static /*@exposed@*/ ltoken commentSymToken;
143 static /*@exposed@*/ ltoken synonymToken;
145 static /*@exposed@*/ ltoken
146 insertSimpleToken (char *s) /*@modifies internalState@*/
148 return (LCLInsertToken (simpleId, lsymbol_fromChars (s), 0, FALSE));
151 static bool
152 hasFirstChar (ltoken tok) /*@*/
154 return (ltoken_isChar (tok)
155 && ltoken_isSingleChar (cstring_firstChar (ltoken_unparse (tok))));
158 void
159 lclinit_process (void)
161 InitLines ();
163 InitReduce (INITFILE1);
165 if (ltoken_getCode (nextToken) != LEOFTOKEN)
167 LocalUserError (nextToken, "unexpected tokens after end-of-file");
171 static void
172 InitLines (void)
174 setCodePoint ();
175 InitReduce (INITLINES1);
177 if (ltoken_getCode (nextToken) != LEOFTOKEN)
179 InitLine ();
180 InitReduce (INITLINES2);
183 while (ltoken_getCode (nextToken) != LEOFTOKEN)
185 InitLine ();
186 InitReduce (INITLINES3);
190 static void
191 InitLine (void)
193 if (ltoken_getCode (nextToken) == LLT_EOL)
195 /* Nothing on line. */
196 InitReduce (INITLINE1);
198 else
200 Classification ();
201 InitReduce (INITLINE2);
204 if (ltoken_getCode (nextToken) != LLT_EOL)
206 LocalUserError (nextToken, "Unexpected tokens on line");
209 nextToken = LCLScanNextToken (); /* Discard EOL */
212 static void
213 Classification (void)
215 lsymbol ntext = ltoken_getRawText (nextToken);
217 if (ntext == ltoken_getText (endCommentCharToken)
218 || ntext == ltoken_getText (idCharToken)
219 || ntext == ltoken_getText (opCharToken)
220 || ntext == ltoken_getText (extensionCharToken)
221 || ntext == ltoken_getText (singleCharToken)
222 || ntext == ltoken_getText (whiteCharToken))
224 CharClass ();
225 InitReduce (CLASSIFICATION1);
227 else if (ntext == ltoken_getText (quantifierSymToken)
228 || ntext == ltoken_getText (logicalOpToken)
229 || ntext == ltoken_getText (eqOpToken)
230 || ntext == ltoken_getText (equationSymToken)
231 || ntext == ltoken_getText (eqSepSymToken)
232 || ntext == ltoken_getText (selectSymToken)
233 || ntext == ltoken_getText (openSymToken)
234 || ntext == ltoken_getText (sepSymToken)
235 || ntext == ltoken_getText (closeSymToken)
236 || ntext == ltoken_getText (simpleIdToken)
237 || ntext == ltoken_getText (mapSymToken)
238 || ntext == ltoken_getText (markerSymToken)
239 || ntext == ltoken_getText (commentSymToken))
241 TokenClass ();
242 InitReduce (CLASSIFICATION2);
244 else if (ntext == ltoken_getText (synonymToken))
246 SynClass ();
247 InitReduce (CLASSIFICATION3);
249 else
251 llbug (message ("Expected character, token, or synonym classification: %s",
252 ltoken_getRawString (nextToken)));
253 /* pop off all tokens on this line */
257 static void
258 CharClass (void)
260 ltoken charClassToken;
261 charClassToken = nextToken;
262 nextToken = LCLScanNextToken (); /* Discard char class keyword. */
264 if (ltoken_getRawText (charClassToken) == ltoken_getText (endCommentCharToken))
266 EndCommentChars ();
267 InitReduce (CHARCLASS1);
269 else if (ltoken_getRawText (charClassToken) == ltoken_getText (idCharToken))
271 IdChars ();
272 InitReduce (CHARCLASS2);
274 else if (ltoken_getRawText (charClassToken) == ltoken_getText (opCharToken))
276 OpChars ();
277 InitReduce (CHARCLASS3);
279 else if (ltoken_getRawText (charClassToken)
280 == ltoken_getText (extensionCharToken))
282 ExtensionChar ();
283 InitReduce (CHARCLASS4);
285 else if (ltoken_getRawText (charClassToken) == ltoken_getText (singleCharToken))
287 SingChars ();
288 InitReduce (CHARCLASS5);
290 else if (ltoken_getRawText (charClassToken) == ltoken_getText (whiteCharToken))
292 WhiteChars ();
293 InitReduce (CHARCLASS6);
295 else
297 LocalUserError (nextToken, "expected character classification");
301 static void
302 EndCommentChars (void)
304 EndCommentChar ();
305 InitReduce (LRC_ENDCOMMENT1);
307 while (ltoken_getCode (nextToken) != LLT_EOL)
309 EndCommentChar ();
310 InitReduce (LRC_ENDCOMMENT2);
315 static void IdChars (void) /*@modifies nextToken@*/
317 IdChar ();
318 InitReduce (IDCHARS1);
320 while (ltoken_getCode (nextToken) != LLT_EOL)
322 IdChar ();
323 InitReduce (IDCHARS2);
327 static void OpChars (void) /*@modifies nextToken@*/
329 OpChar ();
330 InitReduce (OPCHARS1);
332 while (ltoken_getCode (nextToken) != LLT_EOL)
334 OpChar ();
335 InitReduce (OPCHARS2);
339 static void ExtensionChar (void) /*@modifies nextToken@*/
341 if (hasFirstChar (nextToken))
343 LSLGenShift (nextToken);
344 nextToken = LCLScanNextToken ();
345 InitReduce (LRC_EXTENSIONCHAR1);
347 else
349 LocalUserError (nextToken, "expected only one character");
353 static void SingChars (void) /*@modifies nextToken@*/
355 SingChar ();
356 InitReduce (SINGCHARS1);
358 while (ltoken_getCode (nextToken) != LLT_EOL)
360 SingChar ();
361 InitReduce (SINGCHARS2);
365 static void WhiteChars (void) /*@modifies nextToken@*/
367 WhiteChar ();
368 InitReduce (WHITECHARS1);
370 while (ltoken_getCode (nextToken) != LLT_EOL)
372 WhiteChar ();
373 InitReduce (WHITECHARS2);
377 static void EndCommentChar (void) /*@modifies nextToken@*/
379 if (ltoken_isChar (nextToken))
381 LSLGenShift (nextToken);
382 nextToken = LCLScanNextToken ();
383 InitReduce (LRC_ENDCOMMENTCHAR1);
385 else
387 LocalUserError (nextToken, "expected only one character");
391 static void IdChar (void) /*@modifies nextToken@*/
393 if (hasFirstChar (nextToken))
395 LSLGenShift (nextToken);
396 nextToken = LCLScanNextToken ();
397 InitReduce (IDCHAR1);
399 else
401 LocalUserError (nextToken,
402 "Character is already defined, cannot redefine");
406 static void OpChar (void) /*@modifies nextToken@*/
408 if (hasFirstChar (nextToken))
410 LSLGenShift (nextToken);
411 nextToken = LCLScanNextToken ();
412 InitReduce (OPCHAR1);
414 else
416 LocalUserError (nextToken,
417 "Character is already defined, cannot redefine");
421 static void SingChar (void) /*@modifies nextToken@*/
423 if (hasFirstChar (nextToken))
425 LSLGenShift (nextToken);
426 nextToken = LCLScanNextToken ();
427 InitReduce (SINGCHAR1);
429 else
431 LocalUserError (nextToken,
432 "Character is already defined, cannot redefine");
436 static void WhiteChar (void) /*@modifies nextToken@*/
438 if (hasFirstChar (nextToken))
440 LSLGenShift (nextToken);
441 nextToken = LCLScanNextToken ();
442 InitReduce (WHITECHAR1);
444 else
446 LocalUserError (nextToken, "Character is already defined, cannot redefine");
450 static void
451 TokenClass (void) /*@modifies nextToken@*/
453 lsymbol ttext = ltoken_getRawText (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))
465 LogicalOpToks ();
466 InitReduce (TOKENCLASS2);
468 else if (ttext == ltoken_getText (eqOpToken))
470 EqOpToks ();
471 InitReduce (TOKENCLASS3);
473 else if (ttext == ltoken_getText (equationSymToken))
475 EquationSymToks ();
476 InitReduce (TOKENCLASS4);
478 else if (ttext == ltoken_getText (eqSepSymToken))
480 EqSepSymToks ();
481 InitReduce (TOKENCLASS5);
483 else if (ttext == ltoken_getText (selectSymToken))
485 SelectSymToks ();
486 InitReduce (TOKENCLASS6);
488 else if (ttext == ltoken_getText (openSymToken))
490 OpenSymToks ();
491 InitReduce (TOKENCLASS7);
493 else if (ttext == ltoken_getText (sepSymToken))
495 SepSymToks ();
496 InitReduce (TOKENCLASS8);
498 else if (ttext == ltoken_getText (closeSymToken))
500 CloseSymToks ();
501 InitReduce (TOKENCLASS9);
503 else if (ttext == ltoken_getText (simpleIdToken))
505 SimpleIdToks ();
506 InitReduce (TOKENCLASS10);
508 else if (ttext == ltoken_getText (mapSymToken))
510 MapSymToks ();
511 InitReduce (TOKENCLASS11);
513 else if (ttext == ltoken_getText (markerSymToken))
515 MarkerSymToks ();
516 InitReduce (TOKENCLASS12);
518 else if (ttext == ltoken_getText (commentSymToken))
520 CommentSymToks ();
521 InitReduce (TOKENCLASS13);
523 else
525 LocalUserError (nextToken, "expected token classification");
529 static void
530 QuantifierSymToks (void) /*@modifies nextToken@*/
532 QuantifierSymTok ();
533 InitReduce (QUANTIFIERSYMTOKS1);
535 while (ltoken_getCode (nextToken) != LLT_EOL)
537 QuantifierSymTok ();
538 InitReduce (QUANTIFIERSYMTOKS2);
542 static void
543 LogicalOpToks (void) /*@modifies nextToken@*/
545 LogicalOpTok ();
546 InitReduce (LOGICALOPTOKS1);
548 while (ltoken_getCode (nextToken) != LLT_EOL)
550 LogicalOpTok ();
551 InitReduce (LOGICALOPTOKS2);
555 static void
556 EqOpToks (void) /*@modifies nextToken@*/
558 EqOpTok ();
559 InitReduce (LRC_EQOPTOKS1);
561 while (ltoken_getCode (nextToken) != LLT_EOL)
563 EqOpTok ();
564 InitReduce (LRC_EQOPTOKS2);
568 static void
569 EquationSymToks (void) /*@modifies nextToken@*/
571 EquationSymTok ();
572 InitReduce (LRC_EQUATIONSYMTOKS1);
574 while (ltoken_getCode (nextToken) != LLT_EOL)
576 EquationSymTok ();
577 InitReduce (LRC_EQUATIONSYMTOKS2);
581 static void
582 EqSepSymToks (void) /*@modifies nextToken@*/
584 EqSepSymTok ();
585 InitReduce (LRC_EQSEPSYMTOKS1);
587 while (ltoken_getCode (nextToken) != LLT_EOL)
589 EqSepSymTok ();
590 InitReduce (LRC_EQSEPSYMTOKS2);
594 static void
595 SelectSymToks (void) /*@modifies nextToken@*/
597 SelectSymTok ();
598 InitReduce (SELECTSYMTOKS1);
600 while (ltoken_getCode (nextToken) != LLT_EOL)
602 SelectSymTok ();
603 InitReduce (SELECTSYMTOKS2);
607 static void
608 OpenSymToks (void) /*@modifies nextToken@*/
610 OpenSymTok ();
611 InitReduce (OPENSYMTOKS1);
613 while (ltoken_getCode (nextToken) != LLT_EOL)
615 OpenSymTok ();
616 InitReduce (OPENSYMTOKS2);
620 static void
621 SepSymToks (void) /*@modifies nextToken@*/
623 SepSymTok ();
624 InitReduce (SEPSYMTOKS1);
626 while (ltoken_getCode (nextToken) != LLT_EOL)
628 SepSymTok ();
629 InitReduce (SEPSYMTOKS2);
633 static void
634 CloseSymToks (void) /*@modifies nextToken@*/
636 CloseSymTok ();
637 InitReduce (CLOSESYMTOKS1);
639 while (ltoken_getCode (nextToken) != LLT_EOL)
641 CloseSymTok ();
642 InitReduce (CLOSESYMTOKS2);
646 static void
647 SimpleIdToks (void) /*@modifies nextToken@*/
649 SimpleIdTok ();
650 InitReduce (SIMPLEIDTOKS1);
652 while (ltoken_getCode (nextToken) != LLT_EOL)
654 SimpleIdTok ();
655 InitReduce (SIMPLEIDTOKS2);
659 static void
660 MapSymToks (void) /*@modifies nextToken@*/
662 MapSymTok ();
663 InitReduce (MAPSYMTOKS1);
665 while (ltoken_getCode (nextToken) != LLT_EOL)
667 MapSymTok ();
668 InitReduce (MAPSYMTOKS2);
672 static void
673 MarkerSymToks (void) /*@modifies nextToken@*/
675 MarkerSymTok ();
676 InitReduce (MARKERSYMTOKS1);
678 while (ltoken_getCode (nextToken) != LLT_EOL)
680 MarkerSymTok ();
681 InitReduce (MARKERSYMTOKS2);
685 static void
686 CommentSymToks (void) /*@modifies nextToken@*/
688 CommentSymTok ();
689 InitReduce (COMMENTSYMTOKS1);
691 while (ltoken_getCode (nextToken) != LLT_EOL)
693 CommentSymTok ();
694 InitReduce (COMMENTSYMTOKS2);
698 static void
699 QuantifierSymTok (void) /*@modifies nextToken@*/
701 Token ();
702 InitReduce (QUANTIFIERSYMTOK1);
705 static void
706 LogicalOpTok (void) /*@modifies nextToken@*/
708 Token ();
709 InitReduce (LOGICALOPTOK1);
712 static void
713 EqOpTok (void) /*@modifies nextToken@*/
715 Token ();
716 InitReduce (LRC_EQOPTOK1);
719 static void EquationSymTok (void) /*@modifies nextToken@*/
721 Token ();
722 InitReduce (LRC_EQUATIONSYMTOK1);
725 static void EqSepSymTok (void) /*@modifies nextToken@*/
727 Token ();
728 InitReduce (LRC_EQSEPSYMTOK1);
732 static void SelectSymTok (void) /*@modifies nextToken@*/
734 Token ();
735 InitReduce (SELECTSYMTOK1);
738 static void OpenSymTok (void) /*@modifies nextToken@*/
740 Token ();
741 InitReduce (OPENSYMTOK1);
744 static void SepSymTok (void) /*@modifies nextToken@*/
746 Token ();
747 InitReduce (SEPSYMTOK1);
750 static void CloseSymTok (void) /*@modifies nextToken@*/
752 Token ();
753 InitReduce (CLOSESYMTOK1);
756 static void SimpleIdTok (void) /*@modifies nextToken@*/
758 Token ();
759 InitReduce (SIMPLEIDTOK1);
762 static void
763 MapSymTok (void) /*@modifies nextToken@*/
765 Token ();
766 InitReduce (MAPSYMTOK1);
769 static void
770 MarkerSymTok (void) /*@modifies nextToken@*/
772 Token ();
773 InitReduce (MARKERSYMTOK1);
777 static void
778 CommentSymTok (void) /*@modifies nextToken@*/
780 Token ();
781 InitReduce (COMMENTSYMTOK1);
785 static void
786 SynClass (void) /*@modifies nextToken@*/
788 if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
790 nextToken = LCLScanNextToken ();
792 OldToken ();
793 NewToken ();
795 InitReduce (SYNCLASS1);
797 else
799 LocalUserError (nextToken, "expected synonym classification");
804 static void
805 OldToken (void) /*@modifies nextToken@*/
807 Token ();
808 InitReduce (OLDTOKEN1);
812 static void
813 NewToken (void) /*@modifies nextToken@*/
815 Token ();
816 InitReduce (NEWTOKEN1);
820 static void
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");
828 else
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
838 ** scanner.
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
842 ** grammar.
845 static void
846 InitReduce (LCLInitRuleCode rule) /*@modifies nextToken@*/
848 switch (rule)
850 case INITFILE1:
851 TRACE ("INITFILE1");
852 break;
854 case INITLINES1:
855 TRACE ("INITLINES1");
856 break;
858 case INITLINES2:
859 TRACE ("INITLINES2");
860 break;
862 case INITLINES3:
863 TRACE ("INITLINES3");
864 break;
866 case INITLINE1:
867 TRACE ("INITLINE1");
868 break;
870 case INITLINE2:
871 TRACE ("INITLINE2");
872 break;
874 case CLASSIFICATION1:
875 TRACE ("CLASSIFICATION1");
876 break;
878 case CLASSIFICATION2:
879 TRACE ("CLASSIFICATION2");
880 break;
882 case CLASSIFICATION3:
883 TRACE ("CLASSIFICATION3");
884 break;
886 case CHARCLASS1:
887 TRACE ("CHARCLASS1");
888 break;
890 case CHARCLASS2:
891 TRACE ("CHARCLASS2");
892 break;
894 case CHARCLASS3:
895 TRACE ("CHARCLASS3");
896 break;
898 case CHARCLASS4:
899 TRACE ("CHARCLASS4");
900 break;
902 case CHARCLASS5:
903 TRACE ("CHARCLASS5");
904 break;
906 case CHARCLASS6:
907 TRACE ("CHARCLASS6");
908 break;
910 case LRC_ENDCOMMENT1:
911 TRACE ("LRC_ENDCOMMENT1");
912 break;
914 case LRC_ENDCOMMENT2:
915 TRACE ("LRC_ENDCOMMENT2");
916 break;
918 case IDCHARS1:
919 TRACE ("IDCHARS1");
920 break;
922 case IDCHARS2:
923 TRACE ("IDCHARS2");
924 break;
926 case OPCHARS1:
927 TRACE ("OPCHARS1");
928 break;
930 case OPCHARS2:
931 TRACE ("OPCHARS2");
932 break;
934 case LRC_EXTENSIONCHAR1:
935 TRACE ("LRC_EXTENSIONCHAR1");
936 ProcessExtensionChar ();
937 break;
939 case SINGCHARS1:
940 TRACE ("SINGCHARS1");
941 break;
943 case SINGCHARS2:
944 TRACE ("SINGCHARS2");
945 break;
947 case WHITECHARS1:
948 TRACE ("WHITECHARS1");
949 break;
951 case WHITECHARS2:
952 TRACE ("WHITECHARS2");
953 break;
955 case LRC_ENDCOMMENTCHAR1:
956 TRACE ("LRC_ENDCOMMENTCHAR1");
957 ProcessEndCommentChar ();
958 break;
960 case IDCHAR1:
961 TRACE ("IDCHAR1");
962 ProcessSingleChar (IDCHAR);
963 break;
965 case OPCHAR1:
966 TRACE ("OPCHAR1");
967 ProcessSingleChar (OPCHAR);
968 break;
970 case SINGCHAR1:
971 TRACE ("SINGCHAR1");
972 ProcessSingleChar (SINGLECHAR);
973 break;
975 case WHITECHAR1:
976 TRACE ("CHAR1");
977 ProcessSingleChar (WHITECHAR);
978 break;
980 case TOKENCLASS1:
981 TRACE ("TOKENCLASS1");
982 break;
984 case TOKENCLASS2:
985 TRACE ("TOKENCLASS2");
986 break;
988 case TOKENCLASS3:
989 TRACE ("TOKENCLASS3");
990 break;
992 case TOKENCLASS4:
993 TRACE ("TOKENCLASS4");
994 break;
996 case TOKENCLASS5:
997 TRACE ("TOKENCLASS5");
998 break;
1000 case TOKENCLASS6:
1001 TRACE ("TOKENCLASS6");
1002 break;
1004 case TOKENCLASS7:
1005 TRACE ("TOKENCLASS7");
1006 break;
1008 case TOKENCLASS8:
1009 TRACE ("TOKENCLASS8");
1010 break;
1012 case TOKENCLASS9:
1013 TRACE ("TOKENCLASS9");
1014 break;
1016 case TOKENCLASS10:
1017 TRACE ("TOKENCLASS10");
1018 break;
1020 case TOKENCLASS11:
1021 TRACE ("TOKENCLASS11");
1022 break;
1024 case TOKENCLASS12:
1025 TRACE ("TOKENCLASS12");
1026 break;
1028 case TOKENCLASS13:
1029 TRACE ("TOKENCLASS13");
1030 break;
1032 case QUANTIFIERSYMTOKS1:
1033 TRACE ("QUALIFERSYMTOKS1");
1034 break;
1036 case QUANTIFIERSYMTOKS2:
1037 TRACE ("QUANTIFIERSYMTOKS2");
1038 break;
1040 case LOGICALOPTOKS1:
1041 TRACE ("LOGICALOPTOKS1");
1042 break;
1044 case LOGICALOPTOKS2:
1045 TRACE ("LOGICALOPTOKS2");
1046 break;
1048 case LRC_EQOPTOKS1:
1049 TRACE ("LRC_EQOPTOKS1");
1050 break;
1052 case LRC_EQOPTOKS2:
1053 TRACE ("LRC_EQOPTOKS2");
1054 break;
1056 case LRC_EQUATIONSYMTOKS1:
1057 TRACE ("LRC_EQUATIONSYMTOKS1");
1058 break;
1060 case LRC_EQUATIONSYMTOKS2:
1061 TRACE ("LRC_EQUATIONSYMTOKS2");
1062 break;
1064 case LRC_EQSEPSYMTOKS1:
1065 TRACE ("LRC_EQSEPSYMTOKS1");
1066 break;
1068 case LRC_EQSEPSYMTOKS2:
1069 TRACE ("LRC_EQSEPSYMTOKS2");
1070 break;
1072 case SELECTSYMTOKS1:
1073 TRACE ("SELECTSYMTOKS1");
1074 break;
1076 case SELECTSYMTOKS2:
1077 TRACE ("SELECTSYMTOKS2");
1078 break;
1080 case OPENSYMTOKS1:
1081 TRACE ("OPENSYMTOKS1");
1082 break;
1084 case OPENSYMTOKS2:
1085 TRACE ("OPENSYMTOKS2");
1086 break;
1088 case SEPSYMTOKS1:
1089 TRACE ("SEPSYMTOKS1");
1090 break;
1092 case SEPSYMTOKS2:
1093 TRACE ("SEPSYMTOKS2");
1094 break;
1096 case CLOSESYMTOKS1:
1097 TRACE ("CLOSESYMTOKS1");
1098 break;
1100 case CLOSESYMTOKS2:
1101 TRACE ("CLOSESYMTOKS2");
1102 break;
1104 case SIMPLEIDTOKS1:
1105 TRACE ("SIMPLEIDTOKS1");
1106 break;
1108 case SIMPLEIDTOKS2:
1109 TRACE ("SIMPLEIDTOKS2");
1110 break;
1112 case MAPSYMTOKS1:
1113 TRACE ("MAPSYMTOKS1");
1114 break;
1116 case MAPSYMTOKS2:
1117 TRACE ("MAPSYMTOKS2");
1118 break;
1120 case MARKERSYMTOKS1:
1121 TRACE ("MARKERSYMTOKS1");
1122 break;
1124 case MARKERSYMTOKS2:
1125 TRACE ("MARKERSYMTOKS2");
1126 break;
1128 case COMMENTSYMTOKS1:
1129 TRACE ("COMMENTSYMTOKS1");
1130 break;
1132 case COMMENTSYMTOKS2:
1133 TRACE ("COMMENTSYMTOKS2");
1134 break;
1136 case QUANTIFIERSYMTOK1:
1137 TRACE ("QUANTIFERSYMTOK1");
1138 ProcessToken (quantifierSym);
1139 break;
1141 case LOGICALOPTOK1:
1142 TRACE ("LOGICALOPTOK1");
1143 ProcessToken (logicalOp);
1144 break;
1146 case LRC_EQOPTOK1:
1147 TRACE ("LRC_EQOPTOK1");
1148 ProcessToken (eqOp);
1149 break;
1151 case LRC_EQUATIONSYMTOK1:
1152 TRACE ("LRC_EQUATIONSYMTOK1");
1153 ProcessToken (equationSym);
1154 break;
1156 case LRC_EQSEPSYMTOK1:
1157 TRACE ("LRC_EQSEPSYMTOK1");
1158 ProcessToken (eqSepSym);
1159 break;
1161 case SELECTSYMTOK1:
1162 TRACE ("SELECTSYMTOK1");
1163 ProcessToken (selectSym);
1164 break;
1166 case OPENSYMTOK1:
1167 TRACE ("OPENSYMTOK1");
1168 ProcessToken (openSym);
1169 break;
1171 case SEPSYMTOK1:
1172 TRACE ("SEPSYMTOK1");
1173 ProcessToken (sepSym);
1174 break;
1176 case CLOSESYMTOK1:
1177 TRACE ("CLOSESYMTOK1");
1178 ProcessToken (closeSym);
1179 break;
1181 case SIMPLEIDTOK1:
1182 TRACE ("SIMPLEIDTOK1");
1183 ProcessToken (simpleId);
1184 break;
1186 case MAPSYMTOK1:
1187 TRACE ("MAPSYMTOK1");
1188 ProcessToken (mapSym);
1189 break;
1191 case MARKERSYMTOK1:
1192 TRACE ("MARKERSYMTOK1");
1193 ProcessToken (markerSym);
1194 break;
1196 case COMMENTSYMTOK1:
1197 TRACE ("COMMENTSYMTOK1");
1198 ProcessToken (commentSym);
1199 break;
1201 case SYNCLASS1:
1202 TRACE ("SYNCLASS1");
1203 ProcessSynonym ();
1204 break;
1206 case OLDTOKEN1:
1207 TRACE ("OLDTOKEN1");
1208 break;
1210 case NEWTOKEN1:
1211 TRACE ("NEWTOKEN1");
1212 break;
1214 default:
1215 llcontbuglit ("InitReduce: bad case");
1216 break;
1221 ** Reset the first character of the predefined extensionChar keywords when
1222 ** the extensionChar changes. e.g. "extensionChar @" changes "\forall" to
1223 ** "@forall".
1226 static void
1227 UpdateXCharKeywords (charCode xChar)
1229 char *str;
1230 char xchar = (char)xChar;
1232 str = ltoken_getTextChars (ltoken_forall);
1233 *str = xchar;
1235 str = ltoken_getTextChars (ltoken_and);
1236 *str = xchar;
1238 str = ltoken_getTextChars (ltoken_or);
1239 *str = xchar;
1241 str = ltoken_getTextChars (ltoken_implies);
1242 *str = xchar;
1244 str = ltoken_getTextChars (ltoken_eq);
1245 *str = xchar;
1247 str = ltoken_getTextChars (ltoken_neq);
1248 *str = xchar;
1250 str = ltoken_getTextChars (ltoken_equals);
1251 *str = xchar;
1253 str = ltoken_getTextChars (ltoken_eqsep);
1254 *str = xchar;
1256 str = ltoken_getTextChars (ltoken_select);
1257 *str = xchar;
1259 str = ltoken_getTextChars (ltoken_open);
1260 *str = xchar;
1262 str = ltoken_getTextChars (ltoken_sep);
1263 *str = xchar;
1265 str = ltoken_getTextChars (ltoken_close);
1266 *str = xchar;
1268 str = ltoken_getTextChars (ltoken_id);
1269 *str = xchar;
1271 str = ltoken_getTextChars (ltoken_arrow);
1272 *str = xchar;
1274 str = ltoken_getTextChars (ltoken_marker);
1275 *str = xchar;
1277 str = ltoken_getTextChars (ltoken_comment);
1278 *str = xchar;
1281 /* Different from ProcessCharClass because only allow one extension */
1282 /* character. Therefore, the present extension character must be set to a */
1283 /* singleChar. */
1285 static void
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);
1304 else
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. */
1316 static void
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");
1327 else
1329 LCLSetEndCommentChar (firstChar, TRUE);
1331 ltoken_free (stackToken);
1334 static void
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;
1350 else
1352 LocalUserError (stackToken, "Character is already defined, cannot redefine");
1355 ltoken_free (stackToken);
1358 static void
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);
1388 static void
1389 ProcessSynonym (void)
1391 ltoken newtok;
1392 ltoken oldtok;
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
1445 static void
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
1467 void
1468 lclinit_initMod (void)
1470 int i;
1473 ** Insert the init file keywords into the token table as undefined
1474 ** SIMPLEIDs. They are defined as simpleIds since they must be treated
1475 ** that way if they do not appear as the first token on a line, and
1476 ** they must be treated that way for the actual LSL parsing. Save the
1477 ** tokens so can recognize as init file keywords when necessary.
1480 endCommentCharToken = insertSimpleToken ("endCommentChar");
1481 idCharToken = insertSimpleToken ("idChar");
1482 opCharToken = insertSimpleToken ("opChar");
1483 extensionCharToken = insertSimpleToken ("extensionChar");
1484 singleCharToken = insertSimpleToken ("singleChar");
1485 whiteCharToken = insertSimpleToken ("whiteChar");
1487 quantifierSymToken = insertSimpleToken ("quantifierSym");
1488 logicalOpToken = insertSimpleToken ("logicalOp");
1489 eqOpToken = insertSimpleToken ("eqOp");
1490 equationSymToken = insertSimpleToken ("equationSym");
1491 eqSepSymToken = insertSimpleToken ("eqSepSym");
1492 selectSymToken = insertSimpleToken ("selectSym");
1493 openSymToken = insertSimpleToken ("openSym");
1494 sepSymToken = insertSimpleToken ("sepSym");
1495 closeSymToken = insertSimpleToken ("closeSym");
1496 simpleIdToken = insertSimpleToken ("simpleId");
1497 mapSymToken = insertSimpleToken ("mapSym");
1498 markerSymToken = insertSimpleToken ("markerSym");
1499 commentSymToken = insertSimpleToken ("commentSym");
1501 synonymToken = insertSimpleToken ("synonym");
1504 ** Initialize defineSingleChar array to all FALSE to signal that no
1505 ** characters have been redefined as singleChar.
1508 for (i = 0; i <= LASTCHAR; i++)
1510 defineSingleChar[i] = FALSE;
1514 ** Record the current extension character so can redefine back to
1515 ** singleChar if a new extension character is redefined.
1518 currentExtensionChar = (charCode) CHAREXTENDER;
1520 /* Init file processing needs to have EOL reported. */
1522 LCLReportEolTokens (TRUE);
1524 /* Not: context_getBoolName () */
1526 LCLAddSyn (lsymbol_fromChars ("Bool"),
1527 lsymbol_fromChars ("bool"));
1530 void
1531 lclinit_reset (void)
1533 nextToken = LCLScanNextToken ();
1536 void
1537 lclinit_cleanup (void)