]> andersk Git - splint.git/blame - src/lslinit.c
Added splint.spec file contributed by Heiko Abraham
[splint.git] / src / lslinit.c
CommitLineData
616915dd 1/*
11db3170 2** Splint - annotation-assisted static program checker
77d37419 3** Copyright (C) 1994-2002 University of Virginia,
616915dd 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.
19**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
616915dd 23*/
24/*
25** lslinit.c
26**
27** Processor for Larch Shared Language Init Files
28*/
29
1b8ae690 30# include "splintMacros.nf"
616915dd 31# include "llbasic.h"
32# include "signature.h"
33# include "signature2.h"
34# include "scan.h"
35# include "scanline.h"
36# include "tokentable.h"
37# include "syntable.h"
38# include "lslinit.h"
39
40/* needed to parse init files */
41# include "shift.h"
42#if TRACING == 1
43/*@notfunction@*/
44# define LTRACE(rule) printf ("Reducing: %s\n", rule)
45#else
46/*@notfunction@*/
47# define LTRACE(rule)
48#endif
49
50static void LocalUserError (ltoken p_t, /*@temp@*/ char *p_msg)
80489f0a 51 /*@modifies *g_warningstream@*/;
616915dd 52
53static /*@only@*/ ltoken nextToken;
54
55static void InitFile (void) /*@modifies nextToken@*/ ;
56static void InitLines (void) /*@modifies nextToken@*/ ;
57static void InitLine (void) /*@modifies nextToken@*/ ;
58static void Classification (void) /*@modifies nextToken@*/ ;
59static void CharClass (void) /*@modifies nextToken@*/ ;
60
61static void EndCommentChars (void) /*@modifies nextToken@*/ ;
62static void IdChars (void) /*@modifies nextToken@*/ ;
63static void OpChars (void) /*@modifies nextToken@*/ ;
64static void ExtensionChar (void) /*@modifies nextToken@*/ ;
65static void SingChars (void) /*@modifies nextToken@*/ ;
66static void WhiteChars (void) /*@modifies nextToken@*/ ;
67static void EndCommentChar (void) /*@modifies nextToken@*/ ;
68static void IdChar (void) /*@modifies nextToken@*/ ;
69static void OpChar (void) /*@modifies nextToken@*/ ;
70static void SingChar (void) /*@modifies nextToken@*/ ;
71static void WhiteChar (void) /*@modifies nextToken@*/ ;
72
73static void TokenClass (void) /*@modifies nextToken@*/ ;
74static void QuantifierSymToks (void) /*@modifies nextToken@*/ ;
75static void LogicalOpToks (void) /*@modifies nextToken@*/ ;
76static void EqOpToks (void) /*@modifies nextToken@*/ ;
77static void EquationSymToks (void) /*@modifies nextToken@*/ ;
78static void EqSepSymToks (void) /*@modifies nextToken@*/ ;
79static void SelectSymToks (void) /*@modifies nextToken@*/ ;
80static void OpenSymToks (void) /*@modifies nextToken@*/ ;
81static void SepSymToks (void) /*@modifies nextToken@*/ ;
82static void CloseSymToks (void) /*@modifies nextToken@*/ ;
83static void SimpleIdToks (void) /*@modifies nextToken@*/ ;
84static void MapSymToks (void) /*@modifies nextToken@*/ ;
85static void MarkerSymToks (void) /*@modifies nextToken@*/ ;
86static void CommentSymToks (void) /*@modifies nextToken@*/ ;
87static void QuantifierSymTok (void) /*@modifies nextToken@*/ ;
88static void LogicalOpTok (void) /*@modifies nextToken@*/ ;
89static void EqOpTok (void) /*@modifies nextToken@*/ ;
90static void EquationSymTok (void) /*@modifies nextToken@*/ ;
91static void EqSepSymTok (void) /*@modifies nextToken@*/ ;
92static void SelectSymTok (void) /*@modifies nextToken@*/ ;
93static void OpenSymTok (void) /*@modifies nextToken@*/ ;
94static void SepSymTok (void) /*@modifies nextToken@*/ ;
95static void CloseSymTok (void) /*@modifies nextToken@*/ ;
96static void SimpleIdTok (void) /*@modifies nextToken@*/ ;
97static void MapSymTok (void) /*@modifies nextToken@*/ ;
98static void MarkerSymTok (void) /*@modifies nextToken@*/ ;
99static void CommentSymTok (void) /*@modifies nextToken@*/ ;
100static void SynClass (void) /*@modifies nextToken@*/ ;
101static void OldToken (void) /*@modifies nextToken@*/ ;
102static void NewToken (void) /*@modifies nextToken@*/ ;
103static void Token (void) /*@modifies nextToken@*/ ;
104
105static void InitReduce (LSLInitRuleCode p_rule) /*@modifies nextToken@*/ ;
106static void UpdateXCharKeywords (charCode) /*@modifies nextToken@*/ ;
107static void ProcessExtensionChar (void) /*@modifies nextToken@*/ ;
108static void ProcessEndCommentChar (void) /*@modifies nextToken@*/ ;
109static void ProcessSingleChar (charCode p_code) /*@modifies nextToken@*/ ;
110static void ProcessToken (ltokenCode p_code) /*@modifies nextToken@*/ ;
111static void ProcessSynonym (void) /*@modifies nextToken@*/ ;
112
113/* If TRUE character has been redefined as a singleChar. */
114static bool defineSingleChar[LASTCHAR + 1];
115
116static charCode currentExtensionChar;
117
118/* LSL init file keyword tokens. */
119
120static /*@dependent@*/ ltoken endCommentCharToken;
121static /*@dependent@*/ ltoken idCharToken;
122static /*@dependent@*/ ltoken opCharToken;
123static /*@dependent@*/ ltoken extensionCharToken;
124static /*@dependent@*/ ltoken singleCharToken;
125static /*@dependent@*/ ltoken whiteCharToken;
126static /*@dependent@*/ ltoken quantifierSymToken;
127static /*@dependent@*/ ltoken logicalOpToken;
128static /*@dependent@*/ ltoken eqOpToken;
129static /*@dependent@*/ ltoken equationSymToken;
130static /*@dependent@*/ ltoken eqSepSymToken;
131static /*@dependent@*/ ltoken selectSymToken;
132static /*@dependent@*/ ltoken openSymToken;
133static /*@dependent@*/ ltoken sepSymToken;
134static /*@dependent@*/ ltoken closeSymToken;
135static /*@dependent@*/ ltoken simpleIdToken;
136static /*@dependent@*/ ltoken mapSymToken;
137static /*@dependent@*/ ltoken markerSymToken;
138static /*@dependent@*/ ltoken commentSymToken;
139static /*@dependent@*/ ltoken synonymToken;
140
141static bool
142hasFirstChar (ltoken tok)
143{
144 return (ltoken_isChar (tok)
145 && lscanCharClass (cstring_firstChar (ltoken_unparse (tok))) == SINGLECHAR);
146}
147
148void
149LSLProcessInitFile (void)
150{
151 InitFile ();
152}
153
154/*
155**
156** Parsing functions for init file processing, in the same order as the
157** grammar file lslinit.cfg. This is top-down order, as much as possible.
158**
159*/
160
161static void
162InitFile (void)
163{
164 InitLines ();
165 InitReduce (INITFILE1);
166
167 if (ltoken_getCode (nextToken) != LEOFTOKEN)
168 {
169 LocalUserError (nextToken, "unexpected tokens after end-of-file");
170 }
171}
172
173static void
174InitLines (void)
175{
176 InitReduce (INITLINES1);
177
178 if (ltoken_getCode (nextToken) != LEOFTOKEN)
179 {
180 InitLine ();
181 InitReduce (INITLINES2);
182 }
183
184 while (ltoken_getCode (nextToken) != LEOFTOKEN)
185 {
186 InitLine ();
187 InitReduce (INITLINES3);
188 }
189
190}
191
192static void
193InitLine (void)
194{
195 if (ltoken_getCode (nextToken) == LST_EOL)
196 {
197 /* Nothing on line. */
198 InitReduce (INITLINE1);
199 }
200 else
201 {
202 Classification ();
203 InitReduce (INITLINE2);
204 }
205
206 if (ltoken_getCode (nextToken) != LST_EOL)
207 {
208 LocalUserError (nextToken, "Unexpected tokens on line");
209 }
210
211 ltoken_free (nextToken);
212 nextToken = LSLScanNextToken ();
213}
214
215static void
216Classification (void)
217{
218 if (ltoken_getRawText (nextToken) == ltoken_getText (endCommentCharToken)
219 || ltoken_getRawText (nextToken) == ltoken_getText (idCharToken)
220 || ltoken_getRawText (nextToken) == ltoken_getText (opCharToken)
221 || ltoken_getRawText (nextToken) == ltoken_getText (extensionCharToken)
222 || ltoken_getRawText (nextToken) == ltoken_getText (singleCharToken)
223 || ltoken_getRawText (nextToken) == ltoken_getText (whiteCharToken))
224 {
225 CharClass ();
226 InitReduce (CLASSIFICATION1);
227 }
228 else if (ltoken_getRawText (nextToken) == ltoken_getText (quantifierSymToken)
229 || ltoken_getRawText (nextToken) == ltoken_getText (logicalOpToken)
230 || ltoken_getRawText (nextToken) == ltoken_getText (eqOpToken)
231 || ltoken_getRawText (nextToken) == ltoken_getText (equationSymToken)
232 || ltoken_getRawText (nextToken) == ltoken_getText (eqSepSymToken)
233 || ltoken_getRawText (nextToken) == ltoken_getText (selectSymToken)
234 || ltoken_getRawText (nextToken) == ltoken_getText (openSymToken)
235 || ltoken_getRawText (nextToken) == ltoken_getText (sepSymToken)
236 || ltoken_getRawText (nextToken) == ltoken_getText (closeSymToken)
237 || ltoken_getRawText (nextToken) == ltoken_getText (simpleIdToken)
238 || ltoken_getRawText (nextToken) == ltoken_getText (mapSymToken)
239 || ltoken_getRawText (nextToken) == ltoken_getText (markerSymToken)
240 || ltoken_getRawText (nextToken) == ltoken_getText (commentSymToken))
241 {
242 TokenClass ();
243 InitReduce (CLASSIFICATION2);
244 }
245 else if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
246 {
247 SynClass ();
248 InitReduce (CLASSIFICATION3);
249 }
250 else
251 {
252 LocalUserError (nextToken,
253 "expected character, token, or synonym classification");
254 }
255}
256
257static void
258CharClass (void)
259{
260 ltoken charClassToken;
261
262 charClassToken = nextToken;
263
264 nextToken = LSLScanNextToken (); /* Discard char class keyword. */
265
266 if (ltoken_getRawText (charClassToken) == ltoken_getText (endCommentCharToken))
267 {
268 EndCommentChars ();
269 InitReduce (CHARCLASS1);
270 }
271 else if (ltoken_getRawText (charClassToken) == ltoken_getText (idCharToken))
272 {
273 IdChars ();
274 InitReduce (CHARCLASS2);
275 }
276 else if (ltoken_getRawText (charClassToken) == ltoken_getText (opCharToken))
277 {
278 OpChars ();
279 InitReduce (CHARCLASS3);
280 }
281 else if (ltoken_getRawText (charClassToken)
282 == ltoken_getText (extensionCharToken))
283 {
284 ExtensionChar ();
285 InitReduce (CHARCLASS4);
286 }
287 else if (ltoken_getRawText (charClassToken) == ltoken_getText (singleCharToken))
288 {
289 SingChars ();
290 InitReduce (CHARCLASS5);
291 }
292 else if (ltoken_getRawText (charClassToken) == ltoken_getText (whiteCharToken))
293 {
294 WhiteChars ();
295 InitReduce (CHARCLASS6);
296 }
297 else
298 {
299 LocalUserError (nextToken, "expected character classification");
300 }
301
302 ltoken_free (charClassToken);
303}
304
305static void
306EndCommentChars (void)
307{
308 EndCommentChar ();
309 InitReduce (LRC_ENDCOMMENT1);
310
311 while (ltoken_getCode (nextToken) != LST_EOL)
312 {
313 EndCommentChar ();
314 InitReduce (LRC_ENDCOMMENT2);
315 }
316
317}
318
319static void
320IdChars (void)
321{
322 IdChar ();
323 InitReduce (IDCHARS1);
324
325 while (ltoken_getCode (nextToken) != LST_EOL)
326 {
327 IdChar ();
328 InitReduce (IDCHARS2);
329 }
330}
331
332static void
333OpChars (void)
334{
335 OpChar ();
336 InitReduce (OPCHARS1);
337
338 while (ltoken_getCode (nextToken) != LST_EOL)
339 {
340 OpChar ();
341 InitReduce (OPCHARS2);
342 }
343}
344
345static void
346ExtensionChar (void)
347{
348 if (ltoken_isChar (nextToken)
349 && lscanCharClass (cstring_firstChar (ltoken_unparse (nextToken))) == SINGLECHAR)
350 {
351 LSLGenShiftOnly (nextToken);
352 nextToken = LSLScanNextToken ();
353 InitReduce (LRC_EXTENSIONCHAR1);
354 }
355 else
356 {
357 LocalUserError (nextToken, "expected only one character");
358 }
359}
360
361static void
362SingChars (void)
363{
364 SingChar ();
365 InitReduce (SINGCHARS1);
366
367 while (ltoken_getCode (nextToken) != LST_EOL)
368 {
369 SingChar ();
370 InitReduce (SINGCHARS2);
371 }
372}
373
374static void
375WhiteChars (void)
376{
377 WhiteChar ();
378 InitReduce (WHITECHARS1);
379
380 while (ltoken_getCode (nextToken) != LST_EOL)
381 {
382 WhiteChar ();
383 InitReduce (WHITECHARS2);
384 }
385}
386
387static void
388EndCommentChar (void)
389{
390 if (ltoken_isChar (nextToken))
391 {
392 LSLGenShiftOnly (nextToken);
393 nextToken = LSLScanNextToken ();
394 InitReduce (LRC_ENDCOMMENTCHAR1);
395 }
396 else
397 {
398 LocalUserError (nextToken, "expected only one character");
399 }
400}
401
402static void
403IdChar (void)
404{
405 if (hasFirstChar (nextToken))
406 {
407 LSLGenShiftOnly (nextToken);
408 nextToken = LSLScanNextToken ();
409 InitReduce (IDCHAR1);
410 }
411 else
412 {
413 LocalUserError (nextToken, "character is already defined, cannot redefine");
414 }
415}
416
417static void
418OpChar (void)
419{
420 if (hasFirstChar (nextToken))
421 {
422 LSLGenShiftOnly (nextToken);
423 nextToken = LSLScanNextToken ();
424 InitReduce (OPCHAR1);
425 }
426 else
427 {
428 LocalUserError (nextToken, "character is already defined, cannot redefine");
429 }
430}
431
432static void
433SingChar (void)
434{
435 if (hasFirstChar (nextToken))
436 {
437 LSLGenShiftOnly (nextToken);
438 nextToken = LSLScanNextToken ();
439 InitReduce (SINGCHAR1);
440 }
441 else
442 {
443 LocalUserError (nextToken, "character is already defined, cannot redefine");
444 }
445}
446
447static void
448WhiteChar (void)
449{
450 if (hasFirstChar (nextToken))
451 {
452 LSLGenShiftOnly (nextToken);
453 nextToken = LSLScanNextToken ();
454 InitReduce (WHITECHAR1);
455 }
456 else
457 {
458 LocalUserError (nextToken, "character is already defined, cannot redefine");
459 }
460}
461
462static void
463TokenClass (void)
464{
465 ltoken tokenClassToken;
466
467 tokenClassToken = nextToken;
468
469 nextToken = LSLScanNextToken ();
470
471 if (ltoken_getRawText (tokenClassToken) == ltoken_getText (quantifierSymToken))
472 {
473 QuantifierSymToks ();
474 InitReduce (TOKENCLASS1);
475 }
476 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (logicalOpToken))
477 {
478 LogicalOpToks ();
479 InitReduce (TOKENCLASS2);
480 }
481 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (eqOpToken))
482 {
483 EqOpToks ();
484 InitReduce (TOKENCLASS3);
485 }
486 else if (ltoken_getRawText (tokenClassToken)
487 == ltoken_getText (equationSymToken))
488 {
489 EquationSymToks ();
490 InitReduce (TOKENCLASS4);
491 }
492 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (eqSepSymToken))
493 {
494 EqSepSymToks ();
495 InitReduce (TOKENCLASS5);
496 }
497 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (selectSymToken))
498 {
499 SelectSymToks ();
500 InitReduce (TOKENCLASS6);
501 }
502 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (openSymToken))
503 {
504 OpenSymToks ();
505 InitReduce (TOKENCLASS7);
506 }
507 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (sepSymToken))
508 {
509 SepSymToks ();
510 InitReduce (TOKENCLASS8);
511 }
512 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (closeSymToken))
513 {
514 CloseSymToks ();
515 InitReduce (TOKENCLASS9);
516 }
517 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (simpleIdToken))
518 {
519 SimpleIdToks ();
520 InitReduce (TOKENCLASS10);
521 }
522 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (mapSymToken))
523 {
524 MapSymToks ();
525 InitReduce (TOKENCLASS11);
526 }
527 else if (ltoken_getRawText (tokenClassToken) == ltoken_getText (markerSymToken))
528 {
529 MarkerSymToks ();
530 InitReduce (TOKENCLASS12);
531 }
532 else if (ltoken_getRawText (tokenClassToken)
533 == ltoken_getText (commentSymToken))
534 {
535 CommentSymToks ();
536 InitReduce (TOKENCLASS13);
537 }
538 else
539 {
540 LocalUserError (nextToken, "expected token classification");
541 }
542
543 ltoken_free (tokenClassToken);
544}
545
546static void
547QuantifierSymToks (void)
548{
549 QuantifierSymTok ();
550 InitReduce (QUANTIFIERSYMTOKS1);
551
552 while (ltoken_getCode (nextToken) != LST_EOL)
553 {
554 QuantifierSymTok ();
555 InitReduce (QUANTIFIERSYMTOKS2);
556 }
557}
558
559static void
560LogicalOpToks (void)
561{
562 LogicalOpTok ();
563 InitReduce (LOGICALOPTOKS1);
564
565 while (ltoken_getCode (nextToken) != LST_EOL)
566 {
567 LogicalOpTok ();
568 InitReduce (LOGICALOPTOKS2);
569 }
570}
571
572static void
573EqOpToks (void)
574{
575 EqOpTok ();
576 InitReduce (LRC_EQOPTOKS1);
577
578 while (ltoken_getCode (nextToken) != LST_EOL)
579 {
580 EqOpTok ();
581 InitReduce (LRC_EQOPTOKS2);
582 }
583}
584
585static void
586EquationSymToks (void)
587{
588 EquationSymTok ();
589 InitReduce (LRC_EQUATIONSYMTOKS1);
590
591 while (ltoken_getCode (nextToken) != LST_EOL)
592 {
593 EquationSymTok ();
594 InitReduce (LRC_EQUATIONSYMTOKS2);
595 }
596}
597
598static void
599EqSepSymToks (void)
600{
601 EqSepSymTok ();
602 InitReduce (LRC_EQSEPSYMTOKS1);
603
604 while (ltoken_getCode (nextToken) != LST_EOL)
605 {
606 EqSepSymTok ();
607 InitReduce (LRC_EQSEPSYMTOKS2);
608 }
609}
610
611static void
612SelectSymToks (void)
613{
614 SelectSymTok ();
615 InitReduce (SELECTSYMTOKS1);
616
617 while (ltoken_getCode (nextToken) != LST_EOL)
618 {
619 SelectSymTok ();
620 InitReduce (SELECTSYMTOKS2);
621 }
622}
623
624static void
625OpenSymToks (void)
626{
627 OpenSymTok ();
628 InitReduce (OPENSYMTOKS1);
629
630 while (ltoken_getCode (nextToken) != LST_EOL)
631 {
632 OpenSymTok ();
633 InitReduce (OPENSYMTOKS2);
634 }
635}
636
637static void
638SepSymToks (void)
639{
640 SepSymTok ();
641 InitReduce (SEPSYMTOKS1);
642
643 while (ltoken_getCode (nextToken) != LST_EOL)
644 {
645 SepSymTok ();
646 InitReduce (SEPSYMTOKS2);
647 }
648}
649
650static void
651CloseSymToks (void)
652{
653 CloseSymTok ();
654 InitReduce (CLOSESYMTOKS1);
655
656 while (ltoken_getCode (nextToken) != LST_EOL)
657 {
658 CloseSymTok ();
659 InitReduce (CLOSESYMTOKS2);
660 }
661}
662
663static void
664SimpleIdToks (void)
665{
666 SimpleIdTok ();
667 InitReduce (SIMPLEIDTOKS1);
668
669 while (ltoken_getCode (nextToken) != LST_EOL)
670 {
671 SimpleIdTok ();
672 InitReduce (SIMPLEIDTOKS2);
673 }
674}
675
676static void
677MapSymToks (void)
678{
679 MapSymTok ();
680 InitReduce (MAPSYMTOKS1);
681
682 while (ltoken_getCode (nextToken) != LST_EOL)
683 {
684 MapSymTok ();
685 InitReduce (MAPSYMTOKS2);
686 }
687}
688
689static void
690MarkerSymToks (void)
691{
692 MarkerSymTok ();
693 InitReduce (MARKERSYMTOKS1);
694
695 while (ltoken_getCode (nextToken) != LST_EOL)
696 {
697 MarkerSymTok ();
698 InitReduce (MARKERSYMTOKS2);
699 }
700}
701
702static void
703CommentSymToks (void)
704{
705 CommentSymTok ();
706 InitReduce (COMMENTSYMTOKS1);
707
708 while (ltoken_getCode (nextToken) != LST_EOL)
709 {
710 CommentSymTok ();
711 InitReduce (COMMENTSYMTOKS2);
712 }
713}
714
715static void
716QuantifierSymTok (void)
717{
718 Token ();
719 InitReduce (QUANTIFIERSYMTOK1);
720}
721
722static void
723LogicalOpTok (void)
724{
725 Token ();
726 InitReduce (LOGICALOPTOK1);
727}
728
729static void
730EqOpTok (void)
731{
732 Token ();
733 InitReduce (LRC_EQOPTOK1);
734}
735
736static void
737EquationSymTok (void)
738{
739 /* ### EquationSymTok (); ### */
740 Token ();
741 InitReduce (LRC_EQUATIONSYMTOK1);
742}
743
744static void
745EqSepSymTok (void)
746{
747 Token ();
748 InitReduce (LRC_EQSEPSYMTOK1);
749
750}
751
752static void
753SelectSymTok (void)
754{
755 Token ();
756 InitReduce (SELECTSYMTOK1);
757}
758
759static void
760OpenSymTok (void)
761{
762 Token ();
763 InitReduce (OPENSYMTOK1);
764}
765
766static void
767SepSymTok (void)
768{
769 Token ();
770 InitReduce (SEPSYMTOK1);
771}
772
773static void
774CloseSymTok (void)
775{
776 Token ();
777 InitReduce (CLOSESYMTOK1);
778}
779
780static void
781SimpleIdTok (void)
782{
783 Token ();
784 InitReduce (SIMPLEIDTOK1);
785}
786
787static void
788MapSymTok (void)
789{
790 Token ();
791 InitReduce (MAPSYMTOK1);
792}
793
794static void
795MarkerSymTok (void)
796{
797 Token ();
798 InitReduce (MARKERSYMTOK1);
799
800}
801
802static void
803CommentSymTok (void)
804{
805 Token ();
806 InitReduce (COMMENTSYMTOK1);
807}
808
809
810static void
811SynClass (void)
812{
813 if (ltoken_getRawText (nextToken) == ltoken_getText (synonymToken))
814 {
815 ltoken_free (nextToken);
816 nextToken = LSLScanNextToken ();
817
818 OldToken ();
819 NewToken ();
820
821 InitReduce (SYNCLASS1);
822 }
823 else
824 {
825 LocalUserError (nextToken, "expected synonym classification");
826 }
827
828}
829
830static void
831OldToken (void)
832{
833 Token ();
834 InitReduce (OLDTOKEN1);
835
836}
837
838static void
839NewToken (void)
840{
841 Token ();
842 InitReduce (NEWTOKEN1);
843
844}
845
846static void
847Token (void)
848{
849 if (ltoken_getCode (nextToken) == LST_EOL
850 || ltoken_getCode (nextToken) == LEOFTOKEN)
851 {
852 LocalUserError (nextToken, "unexpected end-of-line or end-of-file");
853 }
854 else
855 {
856 LSLGenShiftOnly (nextToken);
857 nextToken = LSLScanNextToken ();
858 }
859}
860
861/*
862** Init File Processing Routines, these routines use the shift-reduce sequence
863** produced by the init file parser and update the necessary tables for the
864** scanner.
865**
866** The same shift stack is used that LSL parser uses. A different reduce
867** procedure is used because the init file grammar is different from the LSL
868** grammar.
869**
870*/
871
872static void
873InitReduce (LSLInitRuleCode rule)
874{
875 switch (rule)
876 {
877 case INITFILE1:
878 LTRACE ("INITFILE1");
879 break;
880
881 case INITLINES1:
882 LTRACE ("INITLINES1");
883 break;
884
885 case INITLINES2:
886 LTRACE ("INITLINES2");
887 break;
888
889 case INITLINES3:
890 LTRACE ("INITLINES3");
891 break;
892
893 case INITLINE1:
894 LTRACE ("INITLINE1");
895 break;
896
897 case INITLINE2:
898 LTRACE ("INITLINE2");
899 break;
900
901 case CLASSIFICATION1:
902 LTRACE ("CLASSIFICATION1");
903 break;
904
905 case CLASSIFICATION2:
906 LTRACE ("CLASSIFICATION2");
907 break;
908
909 case CLASSIFICATION3:
910 LTRACE ("CLASSIFICATION3");
911 break;
912
913 case CHARCLASS1:
914 LTRACE ("CHARCLASS1");
915 break;
916
917 case CHARCLASS2:
918 LTRACE ("CHARCLASS2");
919 break;
920
921 case CHARCLASS3:
922 LTRACE ("CHARCLASS3");
923 break;
924
925 case CHARCLASS4:
926 LTRACE ("CHARCLASS4");
927 break;
928
929 case CHARCLASS5:
930 LTRACE ("CHARCLASS5");
931 break;
932
933 case CHARCLASS6:
934 LTRACE ("CHARCLASS6");
935 break;
936
937 case LRC_ENDCOMMENT1:
938 LTRACE ("LRC_ENDCOMMENT1");
939 break;
940
941 case LRC_ENDCOMMENT2:
942 LTRACE ("LRC_ENDCOMMENT2");
943 break;
944
945 case IDCHARS1:
946 LTRACE ("IDCHARS1");
947 break;
948
949 case IDCHARS2:
950 LTRACE ("IDCHARS2");
951 break;
952
953 case OPCHARS1:
954 LTRACE ("OPCHARS1");
955 break;
956
957 case OPCHARS2:
958 LTRACE ("OPCHARS2");
959 break;
960
961 case LRC_EXTENSIONCHAR1:
962 LTRACE ("LRC_EXTENSIONCHAR1");
963 ProcessExtensionChar ();
964 break;
965
966 case SINGCHARS1:
967 LTRACE ("SINGCHARS1");
968 break;
969
970 case SINGCHARS2:
971 LTRACE ("SINGCHARS2");
972 break;
973
974 case WHITECHARS1:
975 LTRACE ("WHITECHARS1");
976 break;
977
978 case WHITECHARS2:
979 LTRACE ("WHITECHARS2");
980 break;
981
982 case LRC_ENDCOMMENTCHAR1:
983 LTRACE ("LRC_ENDCOMMENTCHAR1");
984 ProcessEndCommentChar ();
985 break;
986
987 case IDCHAR1:
988 LTRACE ("IDCHAR1");
989 ProcessSingleChar (IDCHAR);
990 break;
991
992 case OPCHAR1:
993 LTRACE ("OPCHAR1");
994 ProcessSingleChar (OPCHAR);
995 break;
996
997 case SINGCHAR1:
998 LTRACE ("SINGCHAR1");
999 ProcessSingleChar (SINGLECHAR);
1000 break;
1001
1002 case WHITECHAR1:
1003 LTRACE ("CHAR1");
1004 ProcessSingleChar (WHITECHAR);
1005 break;
1006
1007 case TOKENCLASS1:
1008 LTRACE ("TOKENCLASS1");
1009 break;
1010
1011 case TOKENCLASS2:
1012 LTRACE ("TOKENCLASS2");
1013 break;
1014
1015 case TOKENCLASS3:
1016 LTRACE ("TOKENCLASS3");
1017 break;
1018
1019 case TOKENCLASS4:
1020 LTRACE ("TOKENCLASS4");
1021 break;
1022
1023 case TOKENCLASS5:
1024 LTRACE ("TOKENCLASS5");
1025 break;
1026
1027 case TOKENCLASS6:
1028 LTRACE ("TOKENCLASS6");
1029 break;
1030
1031 case TOKENCLASS7:
1032 LTRACE ("TOKENCLASS7");
1033 break;
1034
1035 case TOKENCLASS8:
1036 LTRACE ("TOKENCLASS8");
1037 break;
1038
1039 case TOKENCLASS9:
1040 LTRACE ("TOKENCLASS9");
1041 break;
1042
1043 case TOKENCLASS10:
1044 LTRACE ("TOKENCLASS10");
1045 break;
1046
1047 case TOKENCLASS11:
1048 LTRACE ("TOKENCLASS11");
1049 break;
1050
1051 case TOKENCLASS12:
1052 LTRACE ("TOKENCLASS12");
1053 break;
1054
1055 case TOKENCLASS13:
1056 LTRACE ("TOKENCLASS13");
1057 break;
1058
1059 case QUANTIFIERSYMTOKS1:
1060 LTRACE ("QUALIFERSYMTOKS1");
1061 break;
1062
1063 case QUANTIFIERSYMTOKS2:
1064 LTRACE ("QUANTIFIERSYMTOKS2");
1065 break;
1066
1067 case LOGICALOPTOKS1:
1068 LTRACE ("LOGICALOPTOKS1");
1069 break;
1070
1071 case LOGICALOPTOKS2:
1072 LTRACE ("LOGICALOPTOKS2");
1073 break;
1074
1075 case LRC_EQOPTOKS1:
1076 LTRACE ("LRC_EQOPTOKS1");
1077 break;
1078
1079 case LRC_EQOPTOKS2:
1080 LTRACE ("LRC_EQOPTOKS2");
1081 break;
1082
1083 case LRC_EQUATIONSYMTOKS1:
1084 LTRACE ("LRC_EQUATIONSYMTOKS1");
1085 break;
1086
1087 case LRC_EQUATIONSYMTOKS2:
1088 LTRACE ("LRC_EQUATIONSYMTOKS2");
1089 break;
1090
1091 case LRC_EQSEPSYMTOKS1:
1092 LTRACE ("LRC_EQSEPSYMTOKS1");
1093 break;
1094
1095 case LRC_EQSEPSYMTOKS2:
1096 LTRACE ("LRC_EQSEPSYMTOKS2");
1097 break;
1098
1099 case SELECTSYMTOKS1:
1100 LTRACE ("SELECTSYMTOKS1");
1101 break;
1102
1103 case SELECTSYMTOKS2:
1104 LTRACE ("SELECTSYMTOKS2");
1105 break;
1106
1107 case OPENSYMTOKS1:
1108 LTRACE ("OPENSYMTOKS1");
1109 break;
1110
1111 case OPENSYMTOKS2:
1112 LTRACE ("OPENSYMTOKS2");
1113 break;
1114
1115 case SEPSYMTOKS1:
1116 LTRACE ("SEPSYMTOKS1");
1117 break;
1118
1119 case SEPSYMTOKS2:
1120 LTRACE ("SEPSYMTOKS2");
1121 break;
1122
1123 case CLOSESYMTOKS1:
1124 LTRACE ("CLOSESYMTOKS1");
1125 break;
1126
1127 case CLOSESYMTOKS2:
1128 LTRACE ("CLOSESYMTOKS2");
1129 break;
1130
1131 case SIMPLEIDTOKS1:
1132 LTRACE ("SIMPLEIDTOKS1");
1133 break;
1134
1135 case SIMPLEIDTOKS2:
1136 LTRACE ("SIMPLEIDTOKS2");
1137 break;
1138
1139 case MAPSYMTOKS1:
1140 LTRACE ("MAPSYMTOKS1");
1141 break;
1142
1143 case MAPSYMTOKS2:
1144 LTRACE ("MAPSYMTOKS2");
1145 break;
1146
1147 case MARKERSYMTOKS1:
1148 LTRACE ("MARKERSYMTOKS1");
1149 break;
1150
1151 case MARKERSYMTOKS2:
1152 LTRACE ("MARKERSYMTOKS2");
1153 break;
1154
1155 case COMMENTSYMTOKS1:
1156 LTRACE ("COMMENTSYMTOKS1");
1157 break;
1158
1159 case COMMENTSYMTOKS2:
1160 LTRACE ("COMMENTSYMTOKS2");
1161 break;
1162
1163 case QUANTIFIERSYMTOK1:
1164 LTRACE ("QUANTIFERSYMTOK1");
1165 ProcessToken (LST_QUANTIFIERSYM);
1166 break;
1167
1168 case LOGICALOPTOK1:
1169 LTRACE ("LOGICALOPTOK1");
1170 ProcessToken (LST_LOGICALOP);
1171 break;
1172
1173 case LRC_EQOPTOK1:
1174 LTRACE ("LRC_EQOPTOK1");
1175 ProcessToken (LST_EQOP);
1176 break;
1177
1178 case LRC_EQUATIONSYMTOK1:
1179 LTRACE ("LRC_EQUATIONSYMTOK1");
1180 ProcessToken (LST_EQUATIONSYM);
1181 break;
1182
1183 case LRC_EQSEPSYMTOK1:
1184 LTRACE ("LRC_EQSEPSYMTOK1");
1185 ProcessToken (LST_EQSEPSYM);
1186 break;
1187
1188 case SELECTSYMTOK1:
1189 LTRACE ("SELECTSYMTOK1");
1190 ProcessToken (LST_SELECTSYM);
1191 break;
1192
1193 case OPENSYMTOK1:
1194 LTRACE ("OPENSYMTOK1");
1195 ProcessToken (LST_OPENSYM);
1196 break;
1197
1198 case SEPSYMTOK1:
1199 LTRACE ("SEPSYMTOK1");
1200 ProcessToken (LST_SEPSYM);
1201 break;
1202
1203 case CLOSESYMTOK1:
1204 LTRACE ("CLOSESYMTOK1");
1205 ProcessToken (LST_CLOSESYM);
1206 break;
1207
1208 case SIMPLEIDTOK1:
1209 LTRACE ("SIMPLEIDTOK1");
1210 ProcessToken (LST_SIMPLEID);
1211 break;
1212
1213 case MAPSYMTOK1:
1214 LTRACE ("MAPSYMTOK1");
1215 ProcessToken (LST_MAPSYM);
1216 break;
1217
1218 case MARKERSYMTOK1:
1219 LTRACE ("MARKERSYMTOK1");
1220 ProcessToken (LST_MARKERSYM);
1221 break;
1222
1223 case COMMENTSYMTOK1:
1224 LTRACE ("COMMENTSYMTOK1");
1225 ProcessToken (LST_COMMENTSYM);
1226 break;
1227
1228 case SYNCLASS1:
1229 LTRACE ("SYNCLASS1");
1230 ProcessSynonym ();
1231 break;
1232
1233 case OLDTOKEN1:
1234 LTRACE ("OLDTOKEN1");
1235 break;
1236
1237 case NEWTOKEN1:
1238 LTRACE ("NEWTOKEN1");
1239 break;
1240
1241 default:
1242 llcontbuglit ("InitReduce: bad switch");
1243 break;
1244
1245 } /* end switch */
1246} /* end InitReduce () */
1247
1248
1249
1250/* Reset the first character of the predefined extensionChar keywords when */
1251/* the extensionChar changes. e.g. "extensionChar @" changes "forall" to */
1252/* "@forall". */
1253
1254static void
1255UpdateXCharKeywords (charCode xCharCode)
1256{
1257 char xChar = (char) xCharCode;
1258 char *str;
1259
1260 str = ltoken_getTextChars (ltoken_forall);
1261 *str = xChar;
1262
1263 str = ltoken_getTextChars (ltoken_and);
1264 *str = xChar;
1265
1266 str = ltoken_getTextChars (ltoken_or);
1267 *str = xChar;
1268
1269 str = ltoken_getTextChars (ltoken_implies);
1270 *str = xChar;
1271
1272 str = ltoken_getTextChars (ltoken_eq);
1273 *str = xChar;
1274
1275 str = ltoken_getTextChars (ltoken_neq);
1276 *str = xChar;
1277
1278 str = ltoken_getTextChars (ltoken_equals);
1279 *str = xChar;
1280
1281 str = ltoken_getTextChars (ltoken_eqsep);
1282 *str = xChar;
1283
1284 str = ltoken_getTextChars (ltoken_select);
1285 *str = xChar;
1286
1287 str = ltoken_getTextChars (ltoken_open);
1288 *str = xChar;
1289
1290 str = ltoken_getTextChars (ltoken_sep);
1291 *str = xChar;
1292
1293 str = ltoken_getTextChars (ltoken_close);
1294 *str = xChar;
1295
1296 str = ltoken_getTextChars (ltoken_id);
1297 *str = xChar;
1298
1299 str = ltoken_getTextChars (ltoken_arrow);
1300 *str = xChar;
1301
1302 str = ltoken_getTextChars (ltoken_marker);
1303 *str = xChar;
1304
1305 str = ltoken_getTextChars (ltoken_comment);
1306 *str = xChar;
1307
1308}
1309
1310/* Different from ProcessCharClass because only allow one extension */
1311/* character. Therefore, the present extension character must be set to a */
1312/* singleChar. */
1313
1314static void
1315ProcessExtensionChar (void)
1316{
1317 ltoken stackToken = LSLGenTopPopShiftStack ();
1318 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1319
1320 if (!defineSingleChar[(int)firstChar]
1321 && lscanCharClass (firstChar) == SINGLECHAR)
1322 {
1323 /* Is a single character that has not been defined before. */
1324 /* Can only have one extension char. Release old one. */
1325 lsetCharClass (firstChar, CHC_EXTENSION);
1326
1b8ae690 1327 /* this is a (bogus) type bug! caught by splint */
616915dd 1328 /* lsetCharClass (currentExtensionChar, SINGLECHAR); */
1329
1330 lsetCharClass ((char) currentExtensionChar, SINGLECHAR);
1331
1332 currentExtensionChar = (charCode) firstChar;
1333 UpdateXCharKeywords (currentExtensionChar);
1334 }
1335 else
1336 {
1337 /* Already redefined. Don't allow to be redefined. */
1338 LocalUserError (stackToken, "character is already defined, cannot redefine");
1339 }
1340 ltoken_free (stackToken);
1341}
1342
1343/* Different from ProcessSingleChar because allow any characters to be */
1344/* endCommentChar and also set a different part of the scanner structure. */
1345
1346static void
1347ProcessEndCommentChar (void)
1348{
1349 ltoken stackToken = LSLGenTopPopShiftStack ();
1350 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1351
1352 if (LSLIsEndComment (firstChar))
1353 {
1354 LocalUserError (stackToken,
1355 "already defined as a endCommentChar, cannot redefine");
1356 }
1357 else
1358 {
1359 lsetEndCommentChar (firstChar, TRUE);
1360 }
1361 ltoken_free (stackToken);
1362}
1363
1364static void
1365ProcessSingleChar (charCode code)
1366{
1367 ltoken stackToken = LSLGenTopPopShiftStack ();
1368 char firstChar = cstring_firstChar (ltoken_unparse (stackToken));
1369
1370 if (!defineSingleChar[(int)firstChar]
1371 && lscanCharClass (firstChar) == SINGLECHAR)
1372 {
1373 /* Is a single character that has not been defined before. */
1374 /* It's OK to redefine once. */
1375 lsetCharClass (firstChar, code);
1376 /* OK to mark as a defined singleChar even if not. Only check */
1377 /* defineSingleChar[] if defining a singleChar. */
1378 defineSingleChar[(int)firstChar] = TRUE;
1379 }
1380 else
1381 {
1382 LocalUserError (stackToken, "character is already defined, cannot redefine");
1383 }
1384 ltoken_free (stackToken);
1385}
1386
1387static void
1388ProcessToken (ltokenCode code)
1389{
1390 ltoken stackToken, temp;
1391 lsymbol sym;
1392
1393 stackToken = LSLGenTopPopShiftStack ();
1394 sym = ltoken_getText (stackToken);
1395
1396 if (LSLIsSyn (sym))
1397 {
1398 LocalUserError (stackToken,
1399 "already defined as a synonym, cannot redefine");
1400 }
1401
1402 /* Get the token from the token table, so can check if the token */
1403 /* was updated by a previous token. */
1404 temp = LSLGetToken (sym);
1405
1406 if (ltoken_isStateDefined (temp))
1407 {
1408 if ((code == LST_OPENSYM && sym == lsymbol_fromChars ("[")) ||
1409 (code == LST_CLOSESYM && sym == lsymbol_fromChars ("]")))
1410 {
1411 /* ignore "openSym [" and "closeSym ]" TokenClass */
1412 ltoken_free (stackToken);
1413 return;
1414 }
1415 else
1416 {
1417 LocalUserError (stackToken, "already defined, cannot redefine");
1418 PrintToken (temp);
1419 }
1420 }
1421
1422 LSLUpdateToken (code, ltoken_getText (stackToken), TRUE);
1423 ltoken_free (stackToken);
1424}
1425
1426
1427static void
1428ProcessSynonym (void)
1429{
1430 ltoken newtok;
1431 ltoken oldtok;
1432
1433 newtok = LSLGenTopPopShiftStack ();
1434 oldtok = LSLGenTopPopShiftStack ();
1435
1436 if (ltoken_wasSyn (newtok))
1437 {
1438 /* The token has a synonym. This means that the synonym was in the */
1439 /* init file, so complain about redefining as a synonym again */
1440 LocalUserError (newtok, "newtok already is a synonym, cannot redefine");
1441 }
1442
1443 if (ltoken_hasSyn (newtok))
1444 {
1445 /*
1446 ** newtok already has a synonym defined for it. Do not allow
1447 ** synonyms to be chained.
1448 */
1449
1450 LocalUserError (newtok,
1451 "newtok already has a synonym, cannot chain synonyms");
1452 }
1453
1454 if (ltoken_isStateDefined (newtok))
1455 {
1456 LocalUserError (newtok, "newtok already defined, cannot redefine");
1457 }
1458
1459 LSLAddSyn (ltoken_getText (newtok), ltoken_getText (oldtok));
1460 ltoken_free (oldtok);
1461 ltoken_free (newtok);
1462}
1463
1464
1465/*
1466 * Utilities, in alphabetical order
1467 */
1468
1469static void
1470LocalUserError (ltoken t, /*@temp@*/ char *msg)
1471{
1472 lldiagmsg (message ("%s %s in the LSL init file:",
1473 ltoken_unparse (t), cstring_fromChars (msg)));
1474
1475 ltoken_free (nextToken);
1476 nextToken = LSLScanNextToken ();
1477
1478 while (ltoken_getCode (nextToken) != LST_EOL)
1479 {
1480 ltoken_free (nextToken);
1481 nextToken = LSLScanNextToken ();
1482 }
1483}
1484
1485/*
1486** Required initialization and cleanup routines
1487*/
1488
1489static /*@exposed@*/ ltoken insertSimpleToken (char *text)
1490 /*@modifies internalState@*/
1491{
1492 return (LSLInsertToken (LST_SIMPLEID, lsymbol_fromChars (text), 0, FALSE));
1493}
1494
1495void
1496LSLProcessInitFileInit (void)
1497{
1498 int i;
1499
1500 LSLGenInit (TRUE); /* parsing LSLinit not LCLinit */
1501
1502 /*
1503 ** Insert the init file keywords into the token table as undefined
1504 ** SIMPLEIDs. They are defined as simpleIds since they must be treated
1505 ** that way if they do not appear as the first token on a line, and
1506 ** they must be treated that way for the actual LSL parsing. Save the
1507 ** tokens so can recognize as init file keywords when necessary.
1508 */
1509
1510 endCommentCharToken = insertSimpleToken ("endCommentChar");
1511 idCharToken = insertSimpleToken ("idChar");
1512 opCharToken = insertSimpleToken ("opChar");
1513 extensionCharToken = insertSimpleToken ("extensionChar");
1514 singleCharToken = insertSimpleToken ("singleChar");
1515 whiteCharToken = insertSimpleToken ("whiteChar");
1516
1517 quantifierSymToken = insertSimpleToken ("quantifierSym");
1518 logicalOpToken = insertSimpleToken ("logicalOp");
1519 eqOpToken = insertSimpleToken ("eqOp");
1520 equationSymToken = insertSimpleToken ("equationSym");
1521 eqSepSymToken = insertSimpleToken ("eqSepSym");
1522 selectSymToken = insertSimpleToken ("selectSym");
1523 openSymToken = insertSimpleToken ("openSym");
1524 sepSymToken = insertSimpleToken ("sepSym");
1525 closeSymToken = insertSimpleToken ("closeSym");
1526 simpleIdToken = insertSimpleToken ("simpleId");
1527 mapSymToken = insertSimpleToken ("mapSym");
1528 markerSymToken = insertSimpleToken ("markerSym");
1529 commentSymToken = insertSimpleToken ("commentSym");
1530 synonymToken = insertSimpleToken ("synonym");
1531
1532 for (i = 0; i <= LASTCHAR; i++)
1533 {
1534 defineSingleChar[i] = FALSE;
1535 }
1536
1537 /*
1538 ** Record the current extension character so can redefine back to
1539 ** singleChar if a new extension character is redefined.
1540 */
1541
1542 currentExtensionChar = (charCode) CHAREXTENDER;
1543
1544 LSLReportEolTokens (TRUE);
1545 ltoken_free (nextToken);
1546 nextToken = LSLScanNextToken ();
1547}
1548
1549
1550
1551
1552
1553
1554
1555
This page took 0.694519 seconds and 5 git commands to generate.