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