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"
33 # include "lslscanline.h"
38 # include "lclscanline.h"
39 # include "lcltokentable.h"
40 # include "lclsyntable.h"
43 # include "llgrammar.h"
47 # define TRACE(rule) printf ("Reducing: %s\n", rule)
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@*/ ;
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
));
152 hasFirstChar (ltoken tok
) /*@*/
154 return (ltoken_isChar (tok
)
155 && ltoken_isSingleChar (cstring_firstChar (ltoken_unparse (tok
))));
159 lclinit_process (void)
163 InitReduce (INITFILE1
);
165 if (ltoken_getCode (nextToken
) != LEOFTOKEN
)
167 LocalUserError (nextToken
, "unexpected tokens after end-of-file");
175 InitReduce (INITLINES1
);
177 if (ltoken_getCode (nextToken
) != LEOFTOKEN
)
180 InitReduce (INITLINES2
);
183 while (ltoken_getCode (nextToken
) != LEOFTOKEN
)
186 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
);
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
))
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
))
242 InitReduce (CLASSIFICATION2
);
244 else if (ntext
== ltoken_getText (synonymToken
))
247 InitReduce (CLASSIFICATION3
);
251 llbug (message ("Expected character, token, or synonym classification: %s",
252 ltoken_getRawString (nextToken
)));
253 /* pop off all tokens on this line */
260 ltoken charClassToken
;
261 charClassToken
= nextToken
;
262 nextToken
= LCLScanNextToken (); /* Discard char class keyword. */
264 if (ltoken_getRawText (charClassToken
) == ltoken_getText (endCommentCharToken
))
267 InitReduce (CHARCLASS1
);
269 else if (ltoken_getRawText (charClassToken
) == ltoken_getText (idCharToken
))
272 InitReduce (CHARCLASS2
);
274 else if (ltoken_getRawText (charClassToken
) == ltoken_getText (opCharToken
))
277 InitReduce (CHARCLASS3
);
279 else if (ltoken_getRawText (charClassToken
)
280 == ltoken_getText (extensionCharToken
))
283 InitReduce (CHARCLASS4
);
285 else if (ltoken_getRawText (charClassToken
) == ltoken_getText (singleCharToken
))
288 InitReduce (CHARCLASS5
);
290 else if (ltoken_getRawText (charClassToken
) == ltoken_getText (whiteCharToken
))
293 InitReduce (CHARCLASS6
);
297 LocalUserError (nextToken
, "expected character classification");
302 EndCommentChars (void)
305 InitReduce (LRC_ENDCOMMENT1
);
307 while (ltoken_getCode (nextToken
) != LLT_EOL
)
310 InitReduce (LRC_ENDCOMMENT2
);
315 static void IdChars (void) /*@modifies nextToken@*/
318 InitReduce (IDCHARS1
);
320 while (ltoken_getCode (nextToken
) != LLT_EOL
)
323 InitReduce (IDCHARS2
);
327 static void OpChars (void) /*@modifies nextToken@*/
330 InitReduce (OPCHARS1
);
332 while (ltoken_getCode (nextToken
) != LLT_EOL
)
335 InitReduce (OPCHARS2
);
339 static void ExtensionChar (void) /*@modifies nextToken@*/
341 if (hasFirstChar (nextToken
))
343 LSLGenShift (nextToken
);
344 nextToken
= LCLScanNextToken ();
345 InitReduce (LRC_EXTENSIONCHAR1
);
349 LocalUserError (nextToken
, "expected only one character");
353 static void SingChars (void) /*@modifies nextToken@*/
356 InitReduce (SINGCHARS1
);
358 while (ltoken_getCode (nextToken
) != LLT_EOL
)
361 InitReduce (SINGCHARS2
);
365 static void WhiteChars (void) /*@modifies nextToken@*/
368 InitReduce (WHITECHARS1
);
370 while (ltoken_getCode (nextToken
) != LLT_EOL
)
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
);
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
);
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
);
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
);
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
);
446 LocalUserError (nextToken
, "Character is already defined, cannot redefine");
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
))
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)
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"));
1531 lclinit_reset (void)
1533 nextToken
= LCLScanNextToken ();
1537 lclinit_cleanup (void)