Debian Codegraph @

gcc/m2/mc/mcp1.bnf

raw
1 --
2 -- mc-1.bnf grammar and associated actions for mcp1.
3 --
4 -- Copyright (C) 2015-2025 Free Software Foundation, Inc.
5 -- Contributed by Gaius Mulley <[email protected]>.
6 --
7 -- This file is part of GNU Modula-2.
8 --
9 -- GNU Modula-2 is free software; you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as published by
11 -- the Free Software Foundation; either version 3, or (at your option)
12 -- any later version.
13 --
14 -- GNU Modula-2 is distributed in the hope that it will be useful, but
15 -- WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 -- General Public License for more details.
18 --
19 -- You should have received a copy of the GNU General Public License
20 -- along with GNU Modula-2; see the file COPYING3. If not see
21 -- <http://www.gnu.org/licenses/>.
22 % module mcp1 begin
23 (* output from mc-1.bnf, automatically generated do not edit.
24
25 Copyright (C) 2015-2025 Free Software Foundation, Inc.
26 Contributed by Gaius Mulley <[email protected]>.
27
28 This file is part of GNU Modula-2.
29
30 GNU Modula-2 is free software; you can redistribute it and/or modify
31 it under the terms of the GNU General Public License as published by
32 the Free Software Foundation; either version 3, or (at your option)
33 any later version.
34
35 GNU Modula-2 is distributed in the hope that it will be useful, but
36 WITHOUT ANY WARRANTY; without even the implied warranty of
37 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 General Public License for more details.
39
40 You should have received a copy of the GNU General Public License
41 along with GNU Modula-2; see the file COPYING. If not,
42 see <https://www.gnu.org/licenses/>. *)
43
44 IMPLEMENTATION MODULE mcp1 ;
45
46 FROM DynamicStrings IMPORT String, InitString, KillString, Mark,
47 ConCat, ConCatChar ;
48
49 FROM mcError IMPORT errorStringAt ;
50 FROM nameKey IMPORT NulName, Name, makekey ;
51 FROM mcPrintf IMPORT printf0, printf1 ;
52 FROM mcDebug IMPORT assert ;
53 FROM mcReserved IMPORT toktype ;
54 FROM mcComment IMPORT setProcedureComment ;
55
56 FROM mcLexBuf IMPORT currentstring, currenttoken, getToken, insertToken,
57 insertTokenAndRewind, getTokenNo, lastcomment ;
58
59 FROM decl IMPORT node, lookupDef, lookupImp, lookupModule, getSymName,
60 lookupSym, putDefForC, putDefUnqualified,
61 makeProcedure, makeType, makeTypeImp, makeVar, makeConst,
62 enterScope, leaveScope, putTypeHidden, putTypeOpaque,
63 addImportedModule, getCurrentModule,
64 putCommentDefProcedure, putCommentModProcedure ;
65
66
67 CONST
68 Pass1 = TRUE ;
69 Debugging = FALSE ;
70
71 VAR
72 WasNoError: BOOLEAN ;
73 curident : Name ;
74 curproc,
75 curmodule : node ;
76
77
78 PROCEDURE ErrorString (s: String) ;
79 BEGIN
80 errorStringAt (s, getTokenNo ()) ;
81 WasNoError := FALSE
82 END ErrorString ;
83
84
85 PROCEDURE ErrorArray (a: ARRAY OF CHAR) ;
86 BEGIN
87 ErrorString (InitString (a))
88 END ErrorArray ;
89
90
91 (*
92 checkEndName - if module does not have, name, then issue an error containing, desc.
93 *)
94
95 PROCEDURE checkEndName (module: node; name: Name; desc: ARRAY OF CHAR) ;
96 VAR
97 s: String ;
98 BEGIN
99 IF getSymName (module)#name
100 THEN
101 s := InitString ('inconsistent module name found with this ') ;
102 s := ConCat (s, Mark (InitString (desc))) ;
103 ErrorString (s)
104 END
105 END checkEndName ;
106
107 % declaration mcp1 begin
108
109
110 (*
111 SyntaxError - after a syntax error we skip all tokens up until we reach
112 a stop symbol.
113 *)
114
115 PROCEDURE SyntaxError (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
116 BEGIN
117 DescribeError ;
118 IF Debugging
119 THEN
120 printf0('\nskipping token *** ')
121 END ;
122 (*
123 yes the ORD(currenttoken) looks ugly, but it is *much* safer than
124 using currenttoken<sometok as a change to the ordering of the
125 token declarations below would cause this to break. Using ORD() we are
126 immune from such changes
127 *)
128 WHILE NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR
129 ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR
130 ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2)))
131 DO
132 getToken
133 END ;
134 IF Debugging
135 THEN
136 printf0(' ***\n')
137 END
138 END SyntaxError ;
139
140
141 (*
142 SyntaxCheck -
143 *)
144
145 PROCEDURE SyntaxCheck (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
146 BEGIN
147 (* and again (see above re: ORD)
148 *)
149 IF NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR
150 ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR
151 ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2)))
152 THEN
153 SyntaxError (stopset0, stopset1, stopset2)
154 END
155 END SyntaxCheck ;
156
157
158 (*
159 WarnMissingToken - generates a warning message about a missing token, t.
160 *)
161
162 PROCEDURE WarnMissingToken (t: toktype) ;
163 VAR
164 s0 : SetOfStop0 ;
165 s1 : SetOfStop1 ;
166 s2 : SetOfStop2 ;
167 str: String ;
168 BEGIN
169 s0 := SetOfStop0{} ;
170 s1 := SetOfStop1{} ;
171 s2 := SetOfStop2{} ;
172 IF ORD(t)<32
173 THEN
174 s0 := SetOfStop0{t}
175 ELSIF ORD(t)<64
176 THEN
177 s1 := SetOfStop1{t}
178 ELSE
179 s2 := SetOfStop2{t}
180 END ;
181 str := DescribeStop (s0, s1, s2) ;
182
183 str := ConCat (InitString ('syntax error,'), Mark (str)) ;
184 errorStringAt (str, getTokenNo ())
185 END WarnMissingToken ;
186
187
188 (*
189 MissingToken - generates a warning message about a missing token, t.
190 *)
191
192 PROCEDURE MissingToken (t: toktype) ;
193 BEGIN
194 WarnMissingToken (t) ;
195 IF (t#identtok) AND (t#integertok) AND (t#realtok) AND (t#stringtok)
196 THEN
197 IF Debugging
198 THEN
199 printf0 ('inserting token\n')
200 END ;
201 insertToken (t)
202 END
203 END MissingToken ;
204
205
206 (*
207 CheckAndInsert -
208 *)
209
210 PROCEDURE CheckAndInsert (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) : BOOLEAN ;
211 BEGIN
212 IF ((ORD(t)<32) AND (t IN stopset0)) OR
213 ((ORD(t)>=32) AND (ORD(t)<64) AND (t IN stopset1)) OR
214 ((ORD(t)>=64) AND (t IN stopset2))
215 THEN
216 WarnMissingToken (t) ;
217 insertTokenAndRewind (t) ;
218 RETURN( TRUE )
219 ELSE
220 RETURN( FALSE )
221 END
222 END CheckAndInsert ;
223
224
225 (*
226 InStopSet
227 *)
228
229 PROCEDURE InStopSet (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) : BOOLEAN ;
230 BEGIN
231 IF ((ORD(t)<32) AND (t IN stopset0)) OR
232 ((ORD(t)>=32) AND (ORD(t)<64) AND (t IN stopset1)) OR
233 ((ORD(t)>=64) AND (t IN stopset2))
234 THEN
235 RETURN( TRUE )
236 ELSE
237 RETURN( FALSE )
238 END
239 END InStopSet ;
240
241
242 (*
243 PeepToken - peep token checks to see whether the stopset is satisfied by currenttoken
244 If it is not then it will insert a token providing the token
245 is one of ; ] ) } . OF END ,
246
247 if the stopset contains <identtok> then we do not insert a token
248 *)
249
250 PROCEDURE PeepToken (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
251 BEGIN
252 (* and again (see above re: ORD)
253 *)
254 IF (NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR
255 ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR
256 ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2)))) AND
257 (NOT InStopSet(identtok, stopset0, stopset1, stopset2))
258 THEN
259 (* SyntaxCheck would fail since currentoken is not part of the stopset
260 we check to see whether any of currenttoken might be a commonly omitted token *)
261 IF CheckAndInsert(semicolontok, stopset0, stopset1, stopset2) OR
262 CheckAndInsert(rsbratok, stopset0, stopset1, stopset2) OR
263 CheckAndInsert(rparatok, stopset0, stopset1, stopset2) OR
264 CheckAndInsert(rcbratok, stopset0, stopset1, stopset2) OR
265 CheckAndInsert(periodtok, stopset0, stopset1, stopset2) OR
266 CheckAndInsert(oftok, stopset0, stopset1, stopset2) OR
267 CheckAndInsert(endtok, stopset0, stopset1, stopset2) OR
268 CheckAndInsert(commatok, stopset0, stopset1, stopset2)
269 THEN
270 END
271 END
272 END PeepToken ;
273
274
275 (*
276 Expect -
277 *)
278
279 PROCEDURE Expect (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
280 BEGIN
281 IF currenttoken=t
282 THEN
283 getToken ;
284 IF Pass1
285 THEN
286 PeepToken(stopset0, stopset1, stopset2)
287 END
288 ELSE
289 MissingToken(t)
290 END ;
291 SyntaxCheck(stopset0, stopset1, stopset2)
292 END Expect ;
293
294
295 (*
296 CompilationUnit - returns TRUE if the input was correct enough to parse
297 in future passes.
298 *)
299
300 PROCEDURE CompilationUnit () : BOOLEAN ;
301 BEGIN
302 WasNoError := TRUE ;
303 FileUnit(SetOfStop0{eoftok}, SetOfStop1{}, SetOfStop2{}) ;
304 RETURN( WasNoError )
305 END CompilationUnit ;
306
307
308 (*
309 Ident - error checking varient of Ident
310 *)
311
312 PROCEDURE Ident (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
313 BEGIN
314 curident := makekey(currentstring) ;
315 (*
316 PushTF(makekey(currentstring), identtok)
317 *)
318 Expect(identtok, stopset0, stopset1, stopset2)
319 END Ident ;
320
321
322 (*
323 string -
324 *)
325
326 PROCEDURE string (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
327 BEGIN
328 (*
329 PushTF(makekey(currentstring), stringtok) ;
330 BuildString
331 *)
332 Expect(stringtok, stopset0, stopset1, stopset2)
333 END string ;
334
335
336 (*
337 Integer -
338 *)
339
340 PROCEDURE Integer (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
341 BEGIN
342 (*
343 PushTF(makekey(currentstring), integertok) ;
344 BuildNumber
345 *)
346 Expect(integertok, stopset0, stopset1, stopset2)
347 END Integer ;
348
349
350 (*
351 Real -
352 *)
353
354 PROCEDURE Real (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
355 BEGIN
356 (*
357 PushTF(makekey(currentstring), realtok) ;
358 BuildNumber
359 *)
360 Expect(realtok, stopset0, stopset1, stopset2)
361 END Real ;
362
363
364 (*
365 registerImport - looks up module, ident, and adds it to the
366 current module import list.
367 *)
368
369 PROCEDURE registerImport (ident: Name; scoped: BOOLEAN) ;
370 VAR
371 n: node ;
372 BEGIN
373 n := lookupDef (ident) ;
374 addImportedModule (getCurrentModule (), n, scoped)
375 END registerImport ;
376
377
378 % module mcp1 end
379 END mcp1.
380 % rules
381 error 'ErrorArray' 'ErrorString'
382 tokenfunc 'currenttoken'
383
384 token '' eoftok -- internal token
385 token '+' plustok
386 token '-' minustok
387 token '*' timestok
388 token '/' dividetok
389 token ':=' becomestok
390 token '&' ambersandtok
391 token "." periodtok
392 token "," commatok
393 token ";" semicolontok
394 token '(' lparatok
395 token ')' rparatok
396 token '[' lsbratok -- left square brackets
397 token ']' rsbratok -- right square brackets
398 token '{' lcbratok -- left curly brackets
399 token '}' rcbratok -- right curly brackets
400 token '^' uparrowtok
401 token "'" singlequotetok
402 token '=' equaltok
403 token '#' hashtok
404 token '<' lesstok
405 token '>' greatertok
406 token '<>' lessgreatertok
407 token '<=' lessequaltok
408 token '>=' greaterequaltok
409 token '<*' ldirectivetok
410 token '*>' rdirectivetok
411 token '..' periodperiodtok
412 token ':' colontok
413 token '"' doublequotestok
414 token '|' bartok
415 token 'AND' andtok
416 token 'ARRAY' arraytok
417 token 'BEGIN' begintok
418 token 'BY' bytok
419 token 'CASE' casetok
420 token 'CONST' consttok
421 token 'DEFINITION' definitiontok
422 token 'DIV' divtok
423 token 'DO' dotok
424 token 'ELSE' elsetok
425 token 'ELSIF' elsiftok
426 token 'END' endtok
427 token 'EXCEPT' excepttok
428 token 'EXIT' exittok
429 token 'EXPORT' exporttok
430 token 'FINALLY' finallytok
431 token 'FOR' fortok
432 token 'FROM' fromtok
433 token 'IF' iftok
434 token 'IMPLEMENTATION' implementationtok
435 token 'IMPORT' importtok
436 token 'IN' intok
437 token 'LOOP' looptok
438 token 'MOD' modtok
439 token 'MODULE' moduletok
440 token 'NOT' nottok
441 token 'OF' oftok
442 token 'OR' ortok
443 token 'PACKEDSET' packedsettok
444 token 'POINTER' pointertok
445 token 'PROCEDURE' proceduretok
446 token 'QUALIFIED' qualifiedtok
447 token 'UNQUALIFIED' unqualifiedtok
448 token 'RECORD' recordtok
449 token 'REM' remtok
450 token 'REPEAT' repeattok
451 token 'RETRY' retrytok
452 token 'RETURN' returntok
453 token 'SET' settok
454 token 'THEN' thentok
455 token 'TO' totok
456 token 'TYPE' typetok
457 token 'UNTIL' untiltok
458 token 'VAR' vartok
459 token 'WHILE' whiletok
460 token 'WITH' withtok
461 token 'ASM' asmtok
462 token 'VOLATILE' volatiletok
463 token '...' periodperiodperiodtok
464 token '__DATE__' datetok
465 token '__LINE__' linetok
466 token '__FILE__' filetok
467 token '__ATTRIBUTE__' attributetok
468 token '__BUILTIN__' builtintok
469 token '__INLINE__' inlinetok
470 token 'integer number' integertok
471 token 'identifier' identtok
472 token 'real number' realtok
473 token 'string' stringtok
474
475 special Ident first { < identtok > } follow { }
476 special Integer first { < integertok > } follow { }
477 special Real first { < realtok > } follow { }
478 special string first { < stringtok > } follow { }
479
480 BNF
481
482 -- the following are provided by the module m2flex and also handbuild procedures below
483 -- Ident := Letter { ( Letter | Digit ) } =:
484 -- Integer := Digit { Digit } | OctalDigit { OctalDigit } ( " B " | " C " ) |
485 -- Digit { HexDigit } " H " =:
486 -- Real := Digit { Digit } " . " { Digit } [ ScaleFactor ] =:
487 -- ScaleFactor := " E " [ ( " + " | " - " ) ] Digit { Digit } =:
488 -- HexDigit := Digit | " A " | " B " | " C " | " D " | " E " | " F " =:
489 -- Digit := OctalDigit | " 8 " | " 9 " =:
490 -- OctalDigit := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" =:
491 -- String
492
493 FileUnit := DefinitionModule | ImplementationOrProgramModule
494 =:
495
496 ProgramModule := "MODULE"
497 Ident % curmodule := lookupModule (curident) %
498 % enterScope (curmodule) %
499 [ Priority
500 ]
501 ";"
502 { Import }
503 Block
504 Ident % checkEndName (curmodule, curident, 'program module') %
505 % leaveScope %
506
507 "."
508 =:
509
510 ImplementationModule := "IMPLEMENTATION" "MODULE"
511 Ident % curmodule := lookupImp (curident) %
512 % enterScope (lookupDef (curident)) %
513 % enterScope (curmodule) %
514 [ Priority
515 ] ";"
516 { Import }
517 Block
518 Ident % checkEndName (curmodule, curident, 'implementation module') %
519 % leaveScope ; leaveScope %
520 "."
521 =:
522
523 ImplementationOrProgramModule := ImplementationModule | ProgramModule
524 =:
525
526 Number := Integer | Real =:
527
528 --
529 -- Qualident needs some care as we must only parse module.module.ident
530 -- and not ident.recordfield. We leave the ident.recordfield to be parsed by
531 -- SubDesignator. Note that Qualident is called by SubDesignator so if
532 -- IsAutoPushOff then we just consume tokens.
533 --
534
535 Qualident :=
536 Ident { "." Ident }
537 =:
538
539 ConstExpression := SimpleConstExpr [ Relation SimpleConstExpr ]
540 =:
541
542 Relation := "="
543 | "#"
544 | "<>"
545 | "<"
546 | "<="
547 | ">"
548 | ">="
549 | "IN"
550 =:
551
552 SimpleConstExpr := UnaryOrConstTerm { AddOperator ConstTerm
553 } =:
554
555 UnaryOrConstTerm := "+"
556 ConstTerm
557 |
558 "-"
559 ConstTerm
560 |
561 ConstTerm =:
562
563 AddOperator := "+"
564 | "-"
565 | "OR"
566 =:
567
568 ConstTerm := ConstFactor { MulOperator ConstFactor
569 } =:
570
571 MulOperator := "*"
572 | "/"
573 | "DIV"
574 | "MOD"
575 | "REM"
576 | "AND"
577 | "&"
578 =:
579
580 ConstFactor := Number | ConstString | ConstSetOrQualidentOrFunction |
581 "(" ConstExpression ")" | "NOT" ConstFactor
582 | ConstAttribute =:
583
584 -- to help satisfy LL1
585
586 ConstString := string =:
587
588 ComponentElement := ConstExpression [ ".." ConstExpression ]
589 =:
590
591 ComponentValue := ComponentElement [ 'BY' ConstExpression ]
592 =:
593
594 ArraySetRecordValue := ComponentValue { ',' ComponentValue }
595 =:
596
597 Constructor := '{'
598 [ ArraySetRecordValue ]
599 '}' =:
600
601 ConstSetOrQualidentOrFunction := Qualident
602 [ Constructor | ConstActualParameters
603 ]
604 |
605 Constructor =:
606
607 ConstActualParameters :=
608 ActualParameters
609 =:
610
611 ConstAttribute := "__ATTRIBUTE__" "__BUILTIN__" "(" "("
612 ConstAttributeExpression
613 ")" ")" =:
614
615 ConstAttributeExpression :=
616 Ident
617 | "<" Qualident ',' Ident
618 ">"
619 =:
620
621 ByteAlignment := '<*' AttributeExpression '*>'
622 =:
623
624 OptAlignmentExpression := [ AlignmentExpression ] =:
625
626 AlignmentExpression := "(" ConstExpression ")" =:
627
628 Alignment := [ ByteAlignment ] =:
629
630 TypeDeclaration := Ident % VAR n: node ; %
631 % n := makeTypeImp (curident) %
632 "=" Type Alignment
633 =:
634
635 Type := ( SimpleType | ArrayType
636 | RecordType
637 | SetType
638 | PointerType
639 | ProcedureType )
640 =:
641
642 SimpleType := Qualident [ SubrangeType ] | Enumeration | SubrangeType =:
643
644 Enumeration := "(" ( IdentList )
645 ")"
646 =:
647
648 IdentList := Ident { "," Ident }
649 =:
650
651 SubrangeType := "[" ConstExpression ".." ConstExpression "]"
652 =:
653
654 ArrayType := "ARRAY"
655 SimpleType
656 { ","
657 SimpleType
658 } "OF"
659 Type
660 =:
661
662 RecordType := "RECORD" [ DefaultRecordAttributes ] FieldListSequence "END" =:
663
664 DefaultRecordAttributes := '<*'
665 AttributeExpression
666
667 '*>' =:
668
669 RecordFieldPragma := [ '<*' FieldPragmaExpression
670 { ',' FieldPragmaExpression } '*>' ] =:
671
672 FieldPragmaExpression := Ident PragmaConstExpression =:
673
674 PragmaConstExpression := [ '(' ConstExpression ')' ] =:
675
676 AttributeExpression := Ident '(' ConstExpression ')' =:
677
678 FieldListSequence := FieldListStatement { ";" FieldListStatement } =:
679
680 -- at present FieldListStatement is as follows:
681 FieldListStatement := [ FieldList ] =:
682 -- later replace it with FieldList to comply with PIM2
683
684 -- sadly the PIM rules are not LL1 as Ident and Qualident have the same first
685 -- symbols. We rewrite FieldList to inline qualident
686 -- was
687 -- FieldList := IdentList ":"
688 -- Type |
689 -- "CASE" [ Ident ":" ] Qualident "OF" Varient { "|" Varient }
690 -- [ "ELSE" FieldListSequence ] "END" =:
691
692 FieldList := IdentList ":"
693 Type RecordFieldPragma
694 |
695 "CASE"
696 CaseTag "OF"
697 Varient { "|" Varient }
698 [ "ELSE"
699 FieldListSequence
700 ] "END"
701 =:
702
703 TagIdent := [ Ident ] =:
704
705 CaseTag := TagIdent [":" Qualident ] =:
706
707 Varient := [
708 VarientCaseLabelList ":" FieldListSequence
709 ] =:
710
711 VarientCaseLabelList := VarientCaseLabels { "," VarientCaseLabels } =:
712
713 VarientCaseLabels := ConstExpression [ ".." ConstExpression ]
714 =:
715
716 --
717 -- the following rules are a copy of the ConstExpression ebnf rules but without
718 -- any actions all prefixed with Silent.
719 -- At present they are only used by CaseLabels, if this continues to be true we
720 -- might consider restricting the SilentConstExpression. Eg it makes no sence to allow
721 -- String in these circumstances!
722 --
723
724 SilentConstExpression :=
725 SilentSimpleConstExpr
726 [ SilentRelation SilentSimpleConstExpr ]
727 =:
728
729 SilentRelation := "=" | "#" | "<>" | "<" | "<=" | ">" | ">=" | "IN" =:
730
731 SilentSimpleConstExpr := SilentUnaryOrConstTerm { SilentAddOperator SilentConstTerm } =:
732
733 SilentUnaryOrConstTerm := "+" SilentConstTerm | "-" SilentConstTerm | SilentConstTerm =:
734
735 SilentAddOperator := "+" | "-" | "OR" =:
736
737 SilentConstTerm := SilentConstFactor { SilentMulOperator SilentConstFactor } =:
738
739 SilentMulOperator := "*" | "/" | "DIV" | "MOD" | "REM" | "AND" | "&" =:
740
741 SilentConstFactor := Number | SilentConstString | SilentConstSetOrQualidentOrFunction |
742 "(" SilentConstExpression ")" | "NOT" SilentConstFactor
743 | SilentConstAttribute =:
744
745 SilentConstString := string =:
746
747 SilentConstAttribute := "__ATTRIBUTE__" "__BUILTIN__" "(" "(" SilentConstAttributeExpression ")" ")" =:
748
749 SilentConstAttributeExpression := Ident | "<" Ident ',' SilentConstString ">" =:
750
751 SilentComponentElement := SilentConstExpression [ ".." SilentConstExpression ] =:
752
753 SilentComponentValue := SilentComponentElement [ 'BY' SilentConstExpression ] =:
754
755 SilentArraySetRecordValue := SilentComponentValue { ',' SilentComponentValue } =:
756
757 SilentConstructor := '{'
758 [ SilentArraySetRecordValue ] '}' =:
759
760 SilentConstSetOrQualidentOrFunction := SilentConstructor | Qualident
761 [ SilentConstructor | SilentActualParameters ] =:
762
763 SilentElement := SilentConstExpression [ ".." SilentConstExpression ] =:
764
765 SilentActualParameters := "(" [ SilentExpList ] ")" =:
766
767 SilentExpList := SilentConstExpression { "," SilentConstExpression } =:
768
769 -- end of the Silent constant rules
770
771 SetType := ( "SET" | "PACKEDSET" ) "OF" SimpleType =:
772
773 PointerType := "POINTER" "TO" Type
774 =:
775
776 ProcedureType := "PROCEDURE" [ FormalTypeList ] =:
777
778 FormalTypeList := "(" ( ")" FormalReturn |
779 ProcedureParameters ")" FormalReturn ) =:
780
781 FormalReturn := [ ":" OptReturnType ] =:
782
783 OptReturnType := "[" Qualident "]" | Qualident =:
784
785 ProcedureParameters := ProcedureParameter
786 { "," ProcedureParameter } =:
787
788 ProcedureParameter := "..." | "VAR" FormalType | FormalType =:
789
790 VarIdent := Ident % VAR n: node ; %
791 % n := makeVar (curident) %
792 [ "[" ConstExpression "]" ]
793 =:
794
795 VarIdentList := VarIdent { "," VarIdent } =:
796
797 VariableDeclaration := VarIdentList ":" Type Alignment =:
798
799 Designator := Qualident
800 { SubDesignator } =:
801
802 SubDesignator := "."
803 Ident
804 | "[" ArrayExpList
805 "]"
806 | "^"
807 =:
808
809 ArrayExpList :=
810 Expression
811 { ","
812 Expression
813 }
814 =:
815
816 ExpList := Expression { "," Expression }
817 =:
818
819 Expression := SimpleExpression [ Relation SimpleExpression ]
820 =:
821
822 SimpleExpression := UnaryOrTerm { AddOperator Term } =:
823
824 UnaryOrTerm := "+" Term
825 | "-" Term
826 | Term
827 =:
828
829 Term := Factor { MulOperator Factor
830 } =:
831
832 Factor := Number | string | SetOrDesignatorOrFunction |
833 "(" Expression ")" | "NOT" ( Factor
834 | ConstAttribute
835 ) =:
836
837 SetOrDesignatorOrFunction := Qualident
838 [ Constructor |
839 SimpleDes [ ActualParameters ]
840 ] |
841 Constructor =:
842
843 -- SimpleDes := { "." Ident | "[" ExpList "]" | "^" } =:
844 SimpleDes := { SubDesignator } =:
845
846 ActualParameters := "(" [ ExpList ] ")" =:
847
848 ExitStatement := "EXIT"
849 =:
850
851 ReturnStatement := "RETURN" [ Expression ]
852 =:
853
854 Statement := [ AssignmentOrProcedureCall | IfStatement | CaseStatement |
855 WhileStatement | RepeatStatement | LoopStatement |
856 ForStatement | WithStatement | AsmStatement |
857 ExitStatement | ReturnStatement | RetryStatement
858 ]
859 =:
860
861 RetryStatement := "RETRY"
862 =:
863
864 AssignmentOrProcedureCall := Designator
865 ( ":=" Expression |
866 ActualParameters | % (* epsilon *) %
867 )
868 =:
869
870 -- these two break LL1 as both start with a Designator
871 -- ProcedureCall := Designator [ ActualParameters ] =:
872 -- Assignment := Designator ":=" Expression =:
873
874 StatementSequence := Statement { ";" Statement }
875 =:
876
877 IfStatement := "IF"
878 Expression "THEN"
879 StatementSequence
880 { "ELSIF"
881
882 Expression "THEN"
883 StatementSequence
884 }
885 [ "ELSE"
886 StatementSequence ] "END"
887 =:
888
889 CaseStatement := "CASE"
890 Expression
891 "OF" Case { "|" Case }
892 CaseEndStatement
893 =:
894
895 CaseEndStatement := "END"
896 | "ELSE"
897 StatementSequence "END"
898 =:
899
900 Case := [ CaseLabelList ":" StatementSequence ]
901 =:
902
903 CaseLabelList := CaseLabels { "," CaseLabels } =:
904
905 CaseLabels := ConstExpression [ ".." ConstExpression ]
906 =:
907
908 WhileStatement := "WHILE" Expression "DO"
909 StatementSequence
910 "END"
911 =:
912
913 RepeatStatement := "REPEAT"
914 StatementSequence
915 "UNTIL" Expression
916 =:
917
918 ForStatement :=
919 "FOR" Ident ":=" Expression "TO" Expression [ "BY" ConstExpression ] "DO"
920 StatementSequence
921 "END"
922 =:
923
924 LoopStatement := "LOOP"
925 StatementSequence
926 "END"
927 =:
928
929 WithStatement := "WITH" Designator "DO"
930 StatementSequence
931 "END"
932 =:
933
934 ProcedureDeclaration := ProcedureHeading ";" ProcedureBlock
935 Ident
936 =:
937
938 DefProcedureIdent := Ident % curproc := makeProcedure (curident) ;
939 setProcedureComment (lastcomment, curident) ;
940 putCommentDefProcedure (curproc) ;
941 %
942 =:
943
944 ProcedureIdent := Ident % curproc := lookupSym (curident) ;
945 IF curproc=NIL
946 THEN
947 curproc := makeProcedure (curident)
948 END ;
949 setProcedureComment (lastcomment, curident) ;
950 putCommentModProcedure (curproc) ;
951 %
952 =:
953
954 DefineBuiltinProcedure := [ "__ATTRIBUTE__" "__BUILTIN__" "(" "(" Ident ")" ")" | "__INLINE__" ]
955 =:
956
957 ProcedureHeading := "PROCEDURE"
958 DefineBuiltinProcedure ( ProcedureIdent % enterScope (curproc) %
959 [ FormalParameters ] AttributeNoReturn )
960 =:
961
962 Builtin := [ "__BUILTIN__" | "__INLINE__" ] =:
963
964 DefProcedureHeading := "PROCEDURE" Builtin ( DefProcedureIdent [ DefFormalParameters ] AttributeNoReturn )
965 =:
966
967 -- introduced procedure block so we can produce more informative
968 -- error messages
969
970 ProcedureBlock := { Declaration } [ "BEGIN" ProcedureBlockBody ] "END" % leaveScope %
971 =:
972
973 Block := { Declaration } InitialBlock FinalBlock "END"
974 =:
975
976 InitialBlock := [ "BEGIN" InitialBlockBody ] =:
977
978 FinalBlock := [ "FINALLY" FinalBlockBody ] =:
979
980 InitialBlockBody := NormalPart [ "EXCEPT" ExceptionalPart ] =:
981
982 FinalBlockBody := NormalPart [ "EXCEPT" ExceptionalPart ] =:
983
984 ProcedureBlockBody := NormalPart [ "EXCEPT" ExceptionalPart ] =:
985
986 NormalPart := StatementSequence =:
987
988 ExceptionalPart := StatementSequence
989 =:
990
991 Declaration := "CONST" { ConstantDeclaration ";" } |
992 "TYPE" { TypeDeclaration ";" } |
993 "VAR" { VariableDeclaration ";" } |
994 ProcedureDeclaration ";" |
995 ModuleDeclaration ";" =:
996
997 DefFormalParameters := "(" [ DefMultiFPSection ] ")" FormalReturn =:
998
999 DefMultiFPSection := DefExtendedFP | FPSection [ ";" DefMultiFPSection ] =:
1000
1001 FormalParameters := "(" [ MultiFPSection ] ")" FormalReturn =:
1002
1003 AttributeNoReturn := [ "<*" Ident "*>" ] =:
1004
1005 AttributeUnused := [ "<*" Ident "*>" ] =:
1006
1007 MultiFPSection := ExtendedFP | FPSection [ ";" MultiFPSection ] =:
1008
1009 FPSection := NonVarFPSection | VarFPSection =:
1010
1011 DefExtendedFP := DefOptArg | "..." =:
1012
1013 ExtendedFP := OptArg | "..." =:
1014
1015 VarFPSection := "VAR" IdentList ":" FormalType [ AttributeUnused ] =:
1016
1017 NonVarFPSection := IdentList ":" FormalType [ AttributeUnused ] =:
1018
1019 OptArg := "[" Ident ":" FormalType [ "=" ConstExpression ] "]" =:
1020
1021 DefOptArg := "[" Ident ":" FormalType "=" ConstExpression "]" =:
1022
1023 FormalType := { "ARRAY" "OF" } Qualident =:
1024
1025 ModuleDeclaration := "MODULE" Ident [ Priority ] ";"
1026 { Import } [ Export ]
1027 Block Ident
1028 =:
1029
1030 Priority := "[" ConstExpression "]" =:
1031
1032 Export := "EXPORT" ( "QUALIFIED"
1033 IdentList |
1034 "UNQUALIFIED" % putDefUnqualified (curmodule) %
1035 IdentList |
1036 IdentList ) ";" =:
1037
1038 FromImport := "FROM" Ident % registerImport (curident, FALSE) %
1039 "IMPORT" IdentList ";"
1040 =:
1041
1042 ImportModuleList := Ident % registerImport (curident, TRUE) %
1043 { "," Ident % registerImport (curident, TRUE) %
1044 }
1045 =:
1046
1047 WithoutFromImport := "IMPORT" ImportModuleList ";"
1048 =:
1049
1050 Import := FromImport | WithoutFromImport =:
1051
1052 DefinitionModule := % VAR c: BOOLEAN ; %
1053 % c := FALSE %
1054 "DEFINITION" "MODULE" [ "FOR" string % c := TRUE %
1055 ] Ident ";" % curmodule := lookupDef (curident) %
1056 % IF c THEN putDefForC (curmodule) END %
1057 % enterScope (curmodule) %
1058 { Import } [ Export ]
1059 { Definition }
1060 "END" Ident "." % checkEndName (curmodule, curident, 'definition module') %
1061 % leaveScope %
1062 =:
1063
1064
1065 DefTypeDeclaration := { Ident % VAR n: node ; %
1066 % n := makeType (curident) %
1067 ( ";" % putTypeHidden (n) ;
1068 putTypeOpaque (n) %
1069 | "=" Type Alignment ";" ) }
1070 =:
1071
1072 ConstantDeclaration := Ident % VAR n: node ; %
1073 % n := makeConst (curident) %
1074 "=" ConstExpression
1075 =:
1076
1077 Definition := "CONST" { ConstantDeclaration ";" } |
1078 "TYPE" { DefTypeDeclaration } |
1079 "VAR" { VariableDeclaration ";" } |
1080 DefProcedureHeading ";" =:
1081
1082 AsmStatement := 'ASM' [ 'VOLATILE' ] '(' AsmOperands ')' =:
1083
1084 AsmOperands := string [ AsmOperandSpec ]
1085 =:
1086
1087 AsmOperandSpec := [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ]
1088 =:
1089
1090 AsmList := [ AsmElement ] { ',' AsmElement } =:
1091
1092 NamedOperand := '[' Ident ']' =:
1093
1094 AsmOperandName := [ NamedOperand ]
1095 =:
1096
1097 AsmElement := AsmOperandName string '(' Expression ')'
1098 =:
1099
1100 TrashList := [ string ] { ',' string } =:
1101
1102 FNB