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