]>
Commit | Line | Data |
---|---|---|
7401123f GM |
1 | -- |
2 | -- m2-h.bnf grammar and associated actions for pass h. | |
3 | -- | |
3d864fce | 4 | -- Copyright (C) 2001-2022 Free Software Foundation, Inc. |
7401123f GM |
5 | -- Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
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 PHBuild begin | |
23 | (* output from m2-h.bnf, automatically generated do not edit if these | |
24 | are the top two lines in the file. | |
25 | ||
3d864fce | 26 | Copyright (C) 2001-2022 Free Software Foundation, Inc. |
7401123f GM |
27 | Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
28 | ||
29 | This file is part of GNU Modula-2. | |
30 | ||
31 | GNU Modula-2 is free software; you can redistribute it and/or modify | |
32 | it under the terms of the GNU General Public License as published by | |
33 | the Free Software Foundation; either version 3, or (at your option) | |
34 | any later version. | |
35 | ||
36 | GNU Modula-2 is distributed in the hope that it will be useful, but | |
37 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
38 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
39 | General Public License for more details. | |
40 | ||
41 | You should have received a copy of the GNU General Public License | |
42 | along with GNU Modula-2; see the file COPYING. If not, | |
43 | see <https://www.gnu.org/licenses/>. *) | |
44 | ||
45 | IMPLEMENTATION MODULE PHBuild ; | |
46 | ||
47 | FROM M2LexBuf IMPORT currentstring, currenttoken, GetToken, InsertToken, InsertTokenAndRewind, GetTokenNo ; | |
48 | FROM M2Error IMPORT ErrorStringAt ; | |
49 | FROM NameKey IMPORT NulName, Name, makekey ; | |
50 | FROM M2Reserved IMPORT NulTok, ByTok, PeriodPeriodTok, tokToTok, toktype ; | |
51 | FROM DynamicStrings IMPORT String, InitString, KillString, Mark, ConCat, ConCatChar ; | |
52 | FROM M2Printf IMPORT printf0 ; | |
53 | FROM M2Debug IMPORT Assert ; | |
54 | FROM P2SymBuild IMPORT BuildString, BuildNumber ; | |
55 | ||
56 | FROM M2Quads IMPORT PushT, PopT, PushTF, PopTF, PopNothing, PushTFtok, PopTFtok, PopTtok, | |
57 | StartBuildDefFile, StartBuildModFile, | |
58 | BuildModuleStart, | |
59 | EndBuildFile, | |
60 | StartBuildInit, | |
61 | EndBuildInit, | |
62 | BuildProcedureStart, | |
63 | BuildProcedureEnd, | |
806751e5 | 64 | BuildAssignment, BuildAssignConstant, |
7401123f GM |
65 | BuildFunctionCall, BuildConstFunctionCall, |
66 | BuildBinaryOp, BuildUnaryOp, BuildRelOp, BuildNot, | |
67 | BuildEmptySet, BuildInclRange, BuildInclBit, | |
68 | BuildSetStart, BuildSetEnd, | |
69 | BuildSizeCheckStart, | |
70 | BuildRepeat, BuildUntil, | |
71 | BuildWhile, BuildDoWhile, BuildEndWhile, | |
72 | BuildLoop, BuildExit, BuildEndLoop, | |
73 | BuildThenIf, BuildElse, BuildEndIf, | |
74 | BuildForToByDo, BuildPseudoBy, BuildEndFor, | |
75 | BuildElsif1, BuildElsif2, | |
76 | BuildProcedureCall, BuildReturn, BuildNulExpression, | |
77 | StartBuildWith, EndBuildWith, | |
78 | BuildInline, | |
79 | BuildCaseStart, | |
80 | BuildCaseOr, | |
81 | BuildCaseElse, | |
82 | BuildCaseEnd, | |
83 | BuildCaseStartStatementSequence, | |
84 | BuildCaseEndStatementSequence, | |
85 | BuildCaseList, | |
86 | BuildCaseRange, BuildCaseEquality, | |
87 | BuildConstructorStart, | |
88 | BuildConstructorEnd, | |
89 | SilentBuildConstructorStart, | |
90 | BuildComponentValue, BuildTypeForConstructor, | |
91 | BuildBooleanVariable, BuildAlignment, | |
92 | RecordOp, | |
93 | BuildNulParam, | |
94 | BuildDesignatorRecord, | |
95 | BuildDesignatorArray, | |
96 | BuildDesignatorPointer, | |
97 | BeginVarient, EndVarient, ElseVarient, | |
98 | BeginVarientList, EndVarientList, | |
99 | AddVarientRange, AddVarientEquality, | |
100 | CheckWithReference, | |
101 | IsAutoPushOn, PushAutoOff, PushAutoOn, PopAuto ; | |
102 | ||
103 | FROM P3SymBuild IMPORT P3StartBuildProgModule, | |
104 | P3EndBuildProgModule, | |
105 | ||
106 | P3StartBuildDefModule, | |
107 | P3EndBuildDefModule, | |
108 | ||
109 | P3StartBuildImpModule, | |
110 | P3EndBuildImpModule, | |
111 | ||
112 | StartBuildInnerModule, | |
113 | EndBuildInnerModule, | |
114 | ||
115 | StartBuildProcedure, | |
116 | BuildProcedureHeading, | |
117 | EndBuildProcedure, | |
118 | BuildConst, | |
119 | BuildSubrange, | |
120 | BuildNulName ; | |
121 | ||
122 | FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, PutGnuAsmInput, | |
123 | PutGnuAsmOutput, PutGnuAsmTrash, PutGnuAsmVolatile, | |
124 | MakeRegInterface, | |
125 | PutRegInterface, GetRegInterface, | |
126 | GetSymName, GetType, | |
127 | NulSym, | |
128 | StartScope, EndScope, | |
129 | PutIncluded, | |
130 | IsVarParam, IsProcedure, IsDefImp, IsModule, | |
131 | IsRecord, | |
132 | RequestSym, | |
133 | GetSym, GetLocalSym ; | |
134 | ||
135 | FROM M2Batch IMPORT IsModuleKnown ; | |
136 | ||
137 | FROM M2CaseList IMPORT BeginCaseList, EndCaseList, ElseCase ; | |
138 | ||
139 | FROM M2Reserved IMPORT NulTok, ImportTok, ExportTok, QualifiedTok, UnQualifiedTok, | |
140 | EqualTok, HashTok, LessGreaterTok, LessTok, LessEqualTok, | |
141 | GreaterTok, GreaterEqualTok, InTok, PlusTok, MinusTok, | |
142 | OrTok, TimesTok, DivTok, DivideTok, ModTok, RemTok, AndTok, AmbersandTok ; | |
143 | ||
fd948137 GM |
144 | IMPORT M2Error ; |
145 | ||
7401123f GM |
146 | |
147 | CONST | |
148 | Debugging = FALSE ; | |
149 | Pass1 = FALSE ; (* permanently disabled for the time being *) | |
150 | Pass2 = FALSE ; (* permanently disabled for the time being *) | |
151 | Pass3 = FALSE ; | |
152 | ||
153 | VAR | |
154 | WasNoError: BOOLEAN ; | |
155 | ||
156 | ||
157 | PROCEDURE ErrorString (s: String) ; | |
158 | BEGIN | |
159 | ErrorStringAt(s, GetTokenNo()) ; | |
160 | WasNoError := FALSE | |
161 | END ErrorString ; | |
162 | ||
163 | ||
164 | PROCEDURE ErrorArray (a: ARRAY OF CHAR) ; | |
165 | BEGIN | |
166 | ErrorString(InitString(a)) | |
167 | END ErrorArray ; | |
168 | ||
169 | ||
170 | % declaration PHBuild begin | |
171 | ||
172 | ||
173 | (* | |
174 | SyntaxError - after a syntax error we skip all tokens up until we reach | |
175 | a stop symbol. | |
176 | *) | |
177 | ||
178 | PROCEDURE SyntaxError (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
179 | BEGIN | |
35e03669 | 180 | DescribeError ; |
7401123f GM |
181 | IF Debugging |
182 | THEN | |
183 | printf0('\nskipping token *** ') | |
184 | END ; | |
185 | (* --fixme-- this assumes a 32 bit word size. *) | |
186 | WHILE NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR | |
187 | ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR | |
188 | ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2))) | |
189 | DO | |
190 | GetToken | |
191 | END ; | |
192 | IF Debugging | |
193 | THEN | |
194 | printf0(' ***\n') | |
195 | END | |
196 | END SyntaxError ; | |
197 | ||
198 | ||
199 | (* | |
200 | SyntaxCheck - | |
201 | *) | |
202 | ||
203 | PROCEDURE SyntaxCheck (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
204 | BEGIN | |
205 | (* --fixme-- this assumes a 32 bit word size. *) | |
206 | IF NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR | |
207 | ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR | |
208 | ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2))) | |
209 | THEN | |
210 | SyntaxError(stopset0, stopset1, stopset2) | |
211 | END | |
212 | END SyntaxCheck ; | |
213 | ||
214 | ||
215 | (* | |
216 | WarnMissingToken - generates a warning message about a missing token, t. | |
217 | *) | |
218 | ||
219 | PROCEDURE WarnMissingToken (t: toktype) ; | |
220 | VAR | |
221 | s0 : SetOfStop0 ; | |
222 | s1 : SetOfStop1 ; | |
223 | s2 : SetOfStop2 ; | |
224 | str: String ; | |
225 | BEGIN | |
226 | s0 := SetOfStop0{} ; | |
227 | s1 := SetOfStop1{} ; | |
228 | s2 := SetOfStop2{} ; | |
229 | IF ORD(t)<32 | |
230 | THEN | |
231 | s0 := SetOfStop0{t} | |
232 | ELSIF ORD(t)<64 | |
233 | THEN | |
234 | s1 := SetOfStop1{t} | |
235 | ELSE | |
236 | s2 := SetOfStop2{t} | |
237 | END ; | |
238 | str := DescribeStop(s0, s1, s2) ; | |
239 | ||
240 | str := ConCat(InitString('syntax error,'), Mark(str)) ; | |
241 | ErrorStringAt(str, GetTokenNo()) | |
242 | END WarnMissingToken ; | |
243 | ||
244 | ||
245 | (* | |
246 | MissingToken - generates a warning message about a missing token, t. | |
247 | *) | |
248 | ||
249 | PROCEDURE MissingToken (t: toktype) ; | |
250 | BEGIN | |
251 | WarnMissingToken(t) ; | |
252 | IF (t#identtok) AND (t#integertok) AND (t#realtok) AND (t#stringtok) | |
253 | THEN | |
254 | IF Debugging | |
255 | THEN | |
256 | printf0('inserting token\n') | |
257 | END ; | |
258 | InsertToken(t) | |
259 | END | |
260 | END MissingToken ; | |
261 | ||
262 | ||
263 | (* | |
264 | CheckAndInsert - | |
265 | *) | |
266 | ||
267 | PROCEDURE CheckAndInsert (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) : BOOLEAN ; | |
268 | BEGIN | |
269 | IF ((ORD(t)<32) AND (t IN stopset0)) OR | |
270 | ((ORD(t)>=32) AND (ORD(t)<64) AND (t IN stopset1)) OR | |
271 | ((ORD(t)>=64) AND (t IN stopset2)) | |
272 | THEN | |
273 | WarnMissingToken(t) ; | |
274 | InsertTokenAndRewind(t) ; | |
275 | RETURN( TRUE ) | |
276 | ELSE | |
277 | RETURN( FALSE ) | |
278 | END | |
279 | END CheckAndInsert ; | |
280 | ||
281 | ||
282 | (* | |
283 | InStopSet | |
284 | *) | |
285 | ||
286 | PROCEDURE InStopSet (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) : BOOLEAN ; | |
287 | BEGIN | |
288 | IF ((ORD(t)<32) AND (t IN stopset0)) OR | |
289 | ((ORD(t)>=32) AND (ORD(t)<64) AND (t IN stopset1)) OR | |
290 | ((ORD(t)>=64) AND (t IN stopset2)) | |
291 | THEN | |
292 | RETURN( TRUE ) | |
293 | ELSE | |
294 | RETURN( FALSE ) | |
295 | END | |
296 | END InStopSet ; | |
297 | ||
298 | ||
299 | (* | |
300 | PeepToken - peep token checks to see whether the stopset is satisfied by currenttoken | |
301 | If it is not then it will insert a token providing the token | |
302 | is one of ; ] ) } . OF END , | |
303 | ||
304 | if the stopset contains <identtok> then we do not insert a token | |
305 | *) | |
306 | ||
307 | PROCEDURE PeepToken (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
308 | BEGIN | |
309 | (* and again (see above re: ORD) | |
310 | *) | |
311 | IF (NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR | |
312 | ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR | |
313 | ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2)))) AND | |
314 | (NOT InStopSet(identtok, stopset0, stopset1, stopset2)) | |
315 | THEN | |
316 | (* SyntaxCheck would fail since currentoken is not part of the stopset | |
317 | we check to see whether any of currenttoken might be a commonly omitted token *) | |
318 | IF CheckAndInsert(semicolontok, stopset0, stopset1, stopset2) OR | |
319 | CheckAndInsert(rsbratok, stopset0, stopset1, stopset2) OR | |
320 | CheckAndInsert(rparatok, stopset0, stopset1, stopset2) OR | |
321 | CheckAndInsert(rcbratok, stopset0, stopset1, stopset2) OR | |
322 | CheckAndInsert(periodtok, stopset0, stopset1, stopset2) OR | |
323 | CheckAndInsert(oftok, stopset0, stopset1, stopset2) OR | |
324 | CheckAndInsert(endtok, stopset0, stopset1, stopset2) OR | |
325 | CheckAndInsert(commatok, stopset0, stopset1, stopset2) | |
326 | THEN | |
327 | END | |
328 | END | |
329 | END PeepToken ; | |
330 | ||
331 | ||
332 | (* | |
333 | Expect - | |
334 | *) | |
335 | ||
336 | PROCEDURE Expect (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
337 | BEGIN | |
338 | IF currenttoken=t | |
339 | THEN | |
340 | GetToken ; | |
341 | IF Pass1 | |
342 | THEN | |
343 | PeepToken(stopset0, stopset1, stopset2) | |
344 | END | |
345 | ELSE | |
346 | MissingToken(t) | |
347 | END ; | |
348 | SyntaxCheck(stopset0, stopset1, stopset2) | |
349 | END Expect ; | |
350 | ||
351 | ||
352 | (* | |
353 | CompilationUnit - returns TRUE if the input was correct enough to parse | |
354 | in future passes. | |
355 | *) | |
356 | ||
357 | PROCEDURE CompilationUnit () : BOOLEAN ; | |
358 | BEGIN | |
359 | WasNoError := TRUE ; | |
360 | FileUnit(SetOfStop0{eoftok}, SetOfStop1{}, SetOfStop2{}) ; | |
361 | RETURN( WasNoError ) | |
362 | END CompilationUnit ; | |
363 | ||
364 | ||
365 | (* | |
366 | Ident - error checking varient of Ident | |
367 | *) | |
368 | ||
369 | PROCEDURE Ident (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
370 | BEGIN | |
371 | IF IsAutoPushOn() | |
372 | THEN | |
373 | PushTF(makekey(currentstring), identtok) | |
374 | END ; | |
375 | Expect(identtok, stopset0, stopset1, stopset2) | |
376 | END Ident ; | |
377 | ||
378 | ||
379 | (* | |
380 | string - | |
381 | *) | |
382 | ||
383 | PROCEDURE string (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
384 | BEGIN | |
385 | IF IsAutoPushOn() | |
386 | THEN | |
387 | PushTF(makekey(currentstring), stringtok) ; | |
388 | BuildString | |
389 | END ; | |
390 | Expect(stringtok, stopset0, stopset1, stopset2) | |
391 | END string ; | |
392 | ||
393 | ||
394 | (* | |
395 | Integer - | |
396 | *) | |
397 | ||
398 | PROCEDURE Integer (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
399 | BEGIN | |
400 | IF IsAutoPushOn() | |
401 | THEN | |
402 | PushTFtok (makekey(currentstring), integertok, GetTokenNo ()) ; | |
403 | BuildNumber | |
404 | END ; | |
405 | Expect(integertok, stopset0, stopset1, stopset2) | |
406 | END Integer ; | |
407 | ||
408 | ||
409 | (* | |
410 | Real - | |
411 | *) | |
412 | ||
413 | PROCEDURE Real (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; | |
414 | BEGIN | |
415 | IF IsAutoPushOn() | |
416 | THEN | |
417 | PushTFtok (makekey(currentstring), realtok, GetTokenNo ()) ; | |
418 | BuildNumber | |
419 | END ; | |
420 | Expect(realtok, stopset0, stopset1, stopset2) | |
421 | END Real ; | |
422 | ||
423 | % module PHBuild end | |
424 | END PHBuild. | |
425 | % rules | |
426 | error 'ErrorArray' 'ErrorString' | |
427 | tokenfunc 'currenttoken' | |
428 | ||
429 | token '' eoftok -- internal token | |
430 | token '+' plustok | |
431 | token '-' minustok | |
432 | token '*' timestok | |
433 | token '/' dividetok | |
434 | token ':=' becomestok | |
435 | token '&' ambersandtok | |
436 | token "." periodtok | |
437 | token "," commatok | |
438 | token ";" semicolontok | |
439 | token '(' lparatok | |
440 | token ')' rparatok | |
441 | token '[' lsbratok -- left square brackets | |
442 | token ']' rsbratok -- right square brackets | |
443 | token '{' lcbratok -- left curly brackets | |
444 | token '}' rcbratok -- right curly brackets | |
445 | token '^' uparrowtok | |
446 | token "'" singlequotetok | |
447 | token '=' equaltok | |
448 | token '#' hashtok | |
449 | token '<' lesstok | |
450 | token '>' greatertok | |
451 | token '<>' lessgreatertok | |
452 | token '<=' lessequaltok | |
453 | token '>=' greaterequaltok | |
454 | token '<*' ldirectivetok | |
455 | token '*>' rdirectivetok | |
456 | token '..' periodperiodtok | |
457 | token ':' colontok | |
458 | token '"' doublequotestok | |
459 | token '|' bartok | |
460 | token 'AND' andtok | |
461 | token 'ARRAY' arraytok | |
462 | token 'BEGIN' begintok | |
463 | token 'BY' bytok | |
464 | token 'CASE' casetok | |
465 | token 'CONST' consttok | |
466 | token 'DEFINITION' definitiontok | |
467 | token 'DIV' divtok | |
468 | token 'DO' dotok | |
469 | token 'ELSE' elsetok | |
470 | token 'ELSIF' elsiftok | |
471 | token 'END' endtok | |
472 | token 'EXCEPT' excepttok | |
473 | token 'EXIT' exittok | |
474 | token 'EXPORT' exporttok | |
475 | token 'FINALLY' finallytok | |
476 | token 'FOR' fortok | |
477 | token 'FROM' fromtok | |
478 | token 'IF' iftok | |
479 | token 'IMPLEMENTATION' implementationtok | |
480 | token 'IMPORT' importtok | |
481 | token 'IN' intok | |
482 | token 'LOOP' looptok | |
483 | token 'MOD' modtok | |
484 | token 'MODULE' moduletok | |
485 | token 'NOT' nottok | |
486 | token 'OF' oftok | |
487 | token 'OR' ortok | |
488 | token 'PACKEDSET' packedsettok | |
489 | token 'POINTER' pointertok | |
490 | token 'PROCEDURE' proceduretok | |
491 | token 'QUALIFIED' qualifiedtok | |
492 | token 'UNQUALIFIED' unqualifiedtok | |
493 | token 'RECORD' recordtok | |
494 | token 'REM' remtok | |
495 | token 'REPEAT' repeattok | |
496 | token 'RETRY' retrytok | |
497 | token 'RETURN' returntok | |
498 | token 'SET' settok | |
499 | token 'THEN' thentok | |
500 | token 'TO' totok | |
501 | token 'TYPE' typetok | |
502 | token 'UNTIL' untiltok | |
503 | token 'VAR' vartok | |
504 | token 'WHILE' whiletok | |
505 | token 'WITH' withtok | |
506 | token 'ASM' asmtok | |
507 | token 'VOLATILE' volatiletok | |
508 | token '...' periodperiodperiodtok | |
509 | token '__DATE__' datetok | |
510 | token '__LINE__' linetok | |
511 | token '__FILE__' filetok | |
512 | token '__ATTRIBUTE__' attributetok | |
513 | token '__BUILTIN__' builtintok | |
514 | token '__INLINE__' inlinetok | |
515 | token 'integer number' integertok | |
516 | token 'identifier' identtok | |
517 | token 'real number' realtok | |
518 | token 'string' stringtok | |
519 | ||
520 | special Ident first { < identtok > } follow { } | |
521 | special Integer first { < integertok > } follow { } | |
522 | special Real first { < realtok > } follow { } | |
523 | special string first { < stringtok > } follow { } | |
524 | ||
525 | BNF | |
526 | ||
527 | -- the following are provided by the module m2flex and also handbuild procedures below | |
528 | -- Ident := Letter { ( Letter | Digit ) } =: | |
529 | -- Integer := Digit { Digit } | OctalDigit { OctalDigit } ( " B " | " C " ) | | |
530 | -- Digit { HexDigit } " H " =: | |
531 | -- Real := Digit { Digit } " . " { Digit } [ ScaleFactor ] =: | |
532 | -- ScaleFactor := " E " [ ( " + " | " - " ) ] Digit { Digit } =: | |
533 | -- HexDigit := Digit | " A " | " B " | " C " | " D " | " E " | " F " =: | |
534 | -- Digit := OctalDigit | " 8 " | " 9 " =: | |
535 | -- OctalDigit := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" =: | |
536 | -- String | |
537 | ||
538 | FileUnit := % PushAutoOff % | |
539 | ( DefinitionModule | | |
540 | ImplementationOrProgramModule ) % PopAuto % | |
541 | =: | |
542 | ||
fd948137 GM |
543 | ProgramModule := "MODULE" % M2Error.DefaultProgramModule % |
544 | % PushAutoOn % | |
7401123f GM |
545 | Ident % P3StartBuildProgModule % |
546 | % BuildModuleStart % | |
547 | % PushAutoOff % | |
548 | [ Priority | |
549 | ] | |
550 | ";" | |
551 | { Import | |
552 | } % StartBuildInit % | |
553 | Block % PushAutoOn % | |
554 | Ident % EndBuildFile % | |
555 | % P3EndBuildProgModule % | |
556 | "." % PopAuto ; | |
557 | EndBuildInit ; | |
558 | PopAuto % | |
559 | =: | |
560 | ||
fd948137 GM |
561 | ImplementationModule := "IMPLEMENTATION" % M2Error.DefaultImplementationModule % |
562 | "MODULE" % PushAutoOn % | |
7401123f GM |
563 | Ident % StartBuildModFile % |
564 | % P3StartBuildImpModule % | |
565 | % BuildModuleStart % | |
566 | % PushAutoOff % | |
567 | [ Priority | |
568 | ] ";" | |
569 | { Import | |
570 | } % StartBuildInit % | |
571 | Block % PushAutoOn % | |
572 | ||
573 | Ident % EndBuildFile % | |
574 | % P3EndBuildImpModule % | |
575 | "." % PopAuto ; | |
576 | EndBuildInit ; | |
577 | PopAuto ; | |
578 | PopAuto % | |
579 | =: | |
580 | ||
581 | ImplementationOrProgramModule := % PushAutoOff % | |
582 | ( ImplementationModule | ProgramModule ) % PopAuto % | |
583 | =: | |
584 | ||
585 | Number := Integer | Real =: | |
586 | ||
587 | Qualident := % VAR name: Name ; | |
588 | Type, Sym, tok: CARDINAL ; % | |
589 | Ident | |
590 | % IF IsAutoPushOn() | |
591 | THEN | |
592 | PopTtok(name, tok) ; | |
593 | Sym := RequestSym (tok, name) ; | |
594 | IF IsDefImp(Sym) OR IsModule(Sym) | |
595 | THEN | |
596 | Expect(periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; | |
597 | StartScope(Sym) ; | |
598 | Qualident(stopset0, stopset1, stopset2) ; | |
599 | (* should we test for lack of ident? *) | |
600 | PopTFtok(Sym, Type, tok) ; | |
601 | PushTFtok(Sym, Type, tok) ; | |
602 | EndScope ; | |
603 | PutIncluded(Sym) | |
604 | ELSE | |
605 | PushTFtok(Sym, GetType(Sym), tok) ; | |
606 | END | |
607 | ELSE (* just parse qualident *) % | |
608 | { "." Ident } % END % | |
609 | =: | |
610 | ||
611 | ConstantDeclaration := % PushAutoOn % | |
612 | % VAR tokno: CARDINAL ; % | |
613 | ( Ident "=" % tokno := GetTokenNo () % | |
614 | % BuildConst % | |
806751e5 | 615 | ConstExpression ) % BuildAssignConstant (tokno) % |
7401123f GM |
616 | % PopAuto % |
617 | =: | |
618 | ||
619 | ConstExpression := % VAR tokpos: CARDINAL ; % | |
620 | % PushAutoOn % | |
621 | SimpleConstExpr [ Relation % tokpos := GetTokenNo ()-1 % | |
622 | SimpleConstExpr % BuildRelOp (tokpos) % | |
623 | ] % PopAuto % | |
624 | =: | |
625 | ||
626 | Relation := "=" % PushT(EqualTok) % | |
627 | | "#" % PushT(HashTok) % | |
628 | | "<>" % PushT(LessGreaterTok) % | |
629 | | "<" % PushT(LessTok) % | |
630 | | "<=" % PushT(LessEqualTok) % | |
631 | | ">" % PushT(GreaterTok) % | |
632 | | ">=" % PushT(GreaterEqualTok) % | |
633 | | "IN" % PushT(InTok) % | |
634 | =: | |
635 | ||
636 | SimpleConstExpr := UnaryOrConstTerm { AddOperator ConstTerm % BuildBinaryOp % | |
637 | } =: | |
638 | ||
639 | UnaryOrConstTerm := "+" % PushT(PlusTok) % | |
640 | ConstTerm % BuildUnaryOp % | |
641 | | | |
642 | "-" % PushT(MinusTok) % | |
643 | ConstTerm % BuildUnaryOp % | |
644 | | | |
645 | ConstTerm =: | |
646 | ||
647 | AddOperator := "+" % PushT(PlusTok) ; | |
648 | RecordOp % | |
649 | | "-" % PushT(MinusTok) ; | |
650 | RecordOp % | |
651 | | "OR" % PushT(OrTok) ; | |
652 | RecordOp % | |
653 | =: | |
654 | ||
655 | ConstTerm := ConstFactor { MulOperator ConstFactor % BuildBinaryOp % | |
656 | } =: | |
657 | ||
658 | MulOperator := "*" % PushT(TimesTok) ; | |
659 | RecordOp % | |
660 | | "/" % PushT(DivideTok) ; | |
661 | RecordOp % | |
662 | | "DIV" % PushT(DivTok) ; | |
663 | RecordOp % | |
664 | | "MOD" % PushT(ModTok) ; | |
665 | RecordOp % | |
666 | | "REM" % PushT(RemTok) ; | |
667 | RecordOp % | |
668 | | "AND" % PushT(AndTok) ; | |
669 | RecordOp % | |
670 | | "&" % PushT(AmbersandTok) ; | |
671 | RecordOp % | |
672 | =: | |
673 | ||
674 | ConstFactor := Number | ConstString | ConstSetOrQualidentOrFunction | | |
675 | "(" ConstExpression ")" | "NOT" ConstFactor % BuildNot % | |
676 | | ConstAttribute =: | |
677 | ||
678 | -- to help satisfy LL1 | |
679 | ||
680 | ConstString := string =: | |
681 | ||
682 | ComponentElement := ConstExpression ( ".." ConstExpression % PushT(PeriodPeriodTok) % | |
683 | | % PushT(NulTok) % | |
684 | ) | |
685 | =: | |
686 | ||
687 | ComponentValue := ComponentElement ( 'BY' ConstExpression % PushT(ByTok) % | |
688 | ||
689 | | % PushT(NulTok) % | |
690 | ) | |
691 | =: | |
692 | ||
693 | ArraySetRecordValue := ComponentValue % BuildComponentValue % | |
694 | { ',' ComponentValue % BuildComponentValue % | |
695 | } | |
696 | =: | |
697 | ||
698 | Constructor := '{' % BuildConstructorStart % | |
699 | [ ArraySetRecordValue ] % BuildConstructorEnd % | |
700 | '}' =: | |
701 | ||
702 | ConstSetOrQualidentOrFunction := Qualident | |
703 | [ Constructor | ConstActualParameters % BuildConstFunctionCall % | |
704 | ] | |
705 | | % BuildTypeForConstructor % | |
706 | Constructor =: | |
707 | ||
708 | ConstAttribute := "__ATTRIBUTE__" "__BUILTIN__" "(" "(" ConstAttributeExpression ")" ")" =: | |
709 | ||
710 | ConstAttributeExpression := Ident | "<" Qualident ',' Ident ">" =: | |
711 | ||
712 | ByteAlignment := '<*' % PushAutoOn % | |
713 | AttributeExpression % BuildAlignment % | |
714 | '*>' % PopAuto % | |
715 | =: | |
716 | ||
35e03669 | 717 | -- OptAlignmentExpression := [ AlignmentExpression ] =: |
7401123f | 718 | |
35e03669 | 719 | -- AlignmentExpression := "(" ConstExpression ")" =: |
7401123f GM |
720 | |
721 | Alignment := [ ByteAlignment ] =: | |
722 | ||
723 | TypeDeclaration := Ident "=" Type Alignment | |
724 | =: | |
725 | ||
726 | Type := | |
727 | % PushAutoOff % | |
728 | ( SimpleType | ArrayType | |
729 | | RecordType | |
730 | | SetType | |
731 | | PointerType | |
732 | | ProcedureType ) % PopAuto % | |
733 | =: | |
734 | ||
735 | SimpleType := Qualident [ SubrangeType ] | Enumeration | SubrangeType =: | |
736 | ||
737 | Enumeration := "(" | |
738 | ( IdentList | |
739 | ) | |
740 | ")" | |
741 | =: | |
742 | ||
743 | IdentList := Ident % VAR | |
744 | on: BOOLEAN ; | |
745 | n : CARDINAL ; % | |
746 | % on := IsAutoPushOn() ; | |
747 | IF on | |
748 | THEN | |
749 | n := 1 | |
750 | END % | |
751 | { "," Ident % IF on | |
752 | THEN | |
753 | INC(n) | |
754 | END % | |
755 | } % IF on | |
756 | THEN | |
757 | PushT(n) | |
758 | END % | |
759 | =: | |
760 | ||
761 | SubrangeType := "[" ConstExpression ".." ConstExpression "]" % BuildSubrange ; % | |
762 | =: | |
763 | ||
764 | ArrayType := "ARRAY" | |
765 | ||
766 | SimpleType | |
767 | { "," | |
768 | SimpleType | |
769 | } "OF" | |
770 | Type | |
771 | =: | |
772 | ||
773 | RecordType := "RECORD" [ DefaultRecordAttributes ] FieldListSequence "END" =: | |
774 | ||
775 | DefaultRecordAttributes := '<*' AttributeExpression '*>' =: | |
776 | ||
777 | RecordFieldPragma := [ '<*' FieldPragmaExpression | |
778 | { ',' FieldPragmaExpression } '*>' ] =: | |
779 | ||
780 | FieldPragmaExpression := % PushAutoOff % | |
781 | Ident [ '(' ConstExpression ')' ] % PopAuto % | |
782 | =: | |
783 | ||
784 | AttributeExpression := % PushAutoOff % | |
785 | Ident '(' ConstExpression ')' % PopAuto % | |
786 | =: | |
787 | ||
788 | FieldListSequence := FieldListStatement { ";" FieldListStatement } =: | |
789 | ||
790 | -- at present FieldListStatement is as follows: | |
791 | FieldListStatement := [ FieldList ] =: | |
792 | -- later replace it with FieldList to comply with PIM2 | |
793 | ||
794 | -- sadly the PIM rules are not LL1 as Ident and Qualident have the same first | |
795 | -- symbols. We rewrite FieldList to inline qualident | |
796 | -- was | |
797 | -- FieldList := IdentList ":" % BuildNulName % | |
798 | -- Type | | |
799 | -- "CASE" [ Ident ] [ ":" Qualident ] "OF" Varient { "|" Varient } | |
800 | -- [ "ELSE" FieldListSequence ] "END" =: | |
801 | ||
802 | FieldList := IdentList ":" | |
803 | Type RecordFieldPragma | |
804 | | | |
805 | "CASE" % BeginVarient % | |
806 | CaseTag "OF" | |
807 | Varient { "|" Varient } | |
808 | [ "ELSE" % ElseVarient % | |
809 | FieldListSequence | |
810 | ] "END" % EndVarient % | |
811 | =: | |
812 | ||
813 | TagIdent := [ Ident ] =: | |
814 | ||
815 | CaseTag := TagIdent [":" Qualident ] =: | |
816 | ||
817 | Varient := [ % BeginVarientList % | |
818 | VarientCaseLabelList ":" FieldListSequence % EndVarientList % | |
819 | ] =: | |
820 | ||
821 | VarientCaseLabelList := VarientCaseLabels { "," VarientCaseLabels } =: | |
822 | ||
823 | VarientCaseLabels := ConstExpression ( ".." ConstExpression % AddVarientRange % | |
824 | | % AddVarientEquality ; (* epsilon *) % | |
825 | ) | |
826 | =: | |
827 | ||
828 | SilentCaseLabelList := SilentCaseLabels { "," SilentCaseLabels } =: | |
829 | ||
830 | SilentCaseLabels := SilentConstExpression [ ".." SilentConstExpression ] =: | |
831 | ||
832 | -- | |
833 | -- the following rules are a copy of the ConstExpression ebnf rules but without | |
834 | -- any actions all prefixed with Silent. | |
835 | -- | |
836 | ||
837 | SilentConstExpression := % PushAutoOff % | |
838 | SilentSimpleConstExpr | |
839 | [ SilentRelation SilentSimpleConstExpr ] % PopAuto % | |
840 | =: | |
841 | ||
842 | SilentRelation := "=" | "#" | "<>" | "<" | "<=" | ">" | ">=" | "IN" =: | |
843 | ||
844 | SilentSimpleConstExpr := SilentUnaryOrConstTerm { SilentAddOperator SilentConstTerm } =: | |
845 | ||
846 | SilentUnaryOrConstTerm := "+" SilentConstTerm | "-" SilentConstTerm | SilentConstTerm =: | |
847 | ||
848 | SilentAddOperator := "+" | "-" | "OR" =: | |
849 | ||
850 | SilentConstTerm := SilentConstFactor { SilentMulOperator SilentConstFactor } =: | |
851 | ||
852 | SilentMulOperator := "*" | "/" | "DIV" | "MOD" | "REM" | "AND" | "&" =: | |
853 | ||
854 | SilentConstFactor := Number | SilentConstString | SilentConstSetOrQualidentOrFunction | | |
855 | "(" SilentConstExpression ")" | "NOT" SilentConstFactor | |
856 | | SilentConstAttribute =: | |
857 | ||
858 | SilentConstString := string =: | |
859 | ||
860 | SilentConstAttribute := "__ATTRIBUTE__" "__BUILTIN__" "(" "(" SilentConstAttributeExpression ")" ")" =: | |
861 | ||
862 | SilentConstAttributeExpression := Ident | "<" Ident ',' SilentConstString ">" =: | |
863 | ||
864 | SilentConstSetOrQualidentOrFunction := Qualident [ SilentConstructor | SilentActualParameters ] | | |
865 | SilentConstructor =: | |
866 | ||
867 | SilentSetOrDesignatorOrFunction := ( Qualident | |
868 | [ SilentConstructor | | |
869 | SilentSimpleDes [ SilentActualParameters ] | |
870 | ] | SilentConstructor ) | |
871 | =: | |
872 | ||
873 | SilentSimpleDes := { SilentSubDesignator } =: | |
874 | ||
875 | SilentConstructor := "{" % SilentBuildConstructorStart % | |
876 | [ SilentElement { "," SilentElement } ] "}" =: | |
877 | ||
878 | SilentElement := SilentConstExpression [ ".." SilentConstExpression ] =: | |
879 | ||
880 | SilentActualParameters := "(" [ SilentExpList ] ")" =: | |
881 | ||
882 | SilentSubDesignator := "." Ident | "[" SilentExpList "]" | "^" | |
883 | =: | |
884 | ||
885 | SilentExpList := SilentExpression { "," SilentExpression } =: | |
886 | ||
887 | SilentDesignator := Qualident { SilentSubDesignator } =: | |
888 | ||
889 | SilentExpression := | |
890 | SilentSimpleExpression | |
891 | [ SilentRelation | |
892 | SilentSimpleExpression ] | |
893 | =: | |
894 | ||
895 | SilentSimpleExpression := SilentUnaryOrTerm { SilentAddOperator SilentTerm } =: | |
896 | ||
897 | SilentUnaryOrTerm := "+" | |
898 | SilentTerm | |
899 | | "-" | |
900 | SilentTerm | |
901 | | SilentTerm =: | |
902 | ||
903 | SilentTerm := SilentFactor { SilentMulOperator SilentFactor | |
904 | } =: | |
905 | ||
906 | SilentFactor := Number | string | SilentSetOrDesignatorOrFunction | | |
907 | "(" SilentExpression ")" | "NOT" SilentFactor | ConstAttribute =: | |
908 | ||
909 | -- end of the Silent constant rules | |
910 | ||
911 | SetType := ( "SET" | "PACKEDSET" ) "OF" SimpleType =: | |
912 | ||
913 | PointerType := "POINTER" "TO" Type | |
914 | =: | |
915 | ||
916 | ProcedureType := "PROCEDURE" | |
917 | [ FormalTypeList ] =: | |
918 | ||
919 | FormalTypeList := "(" ( ")" FormalReturn | | |
920 | ProcedureParameters ")" FormalReturn ) =: | |
921 | ||
922 | FormalReturn := [ ":" OptReturnType ] =: | |
923 | ||
924 | OptReturnType := "[" Qualident "]" | Qualident =: | |
925 | ||
926 | ProcedureParameters := ProcedureParameter | |
927 | { "," ProcedureParameter } =: | |
928 | ||
929 | ProcedureParameter := "..." | "VAR" FormalType | FormalType =: | |
930 | ||
931 | VarIdent := % VAR Sym, Type: CARDINAL ; % | |
932 | Ident [ "[" ConstExpression % PopTF(Sym, Type) % | |
933 | "]" ] | |
934 | =: | |
935 | ||
936 | VarIdentList := VarIdent % VAR | |
937 | on: BOOLEAN ; | |
938 | n : CARDINAL ; % | |
939 | % on := IsAutoPushOn() ; | |
940 | IF on | |
941 | THEN | |
942 | n := 1 | |
943 | END % | |
944 | { "," VarIdent % IF on | |
945 | THEN | |
946 | INC(n) | |
947 | END % | |
948 | } % IF on | |
949 | THEN | |
950 | PushT(n) | |
951 | END % | |
952 | =: | |
953 | ||
954 | VariableDeclaration := VarIdentList ":" Type Alignment | |
955 | =: | |
956 | ||
957 | Designator := Qualident | |
958 | { SubDesignator } =: | |
959 | ||
960 | SubDesignator := "." | |
961 | Ident | |
962 | | "[" ExpList | |
963 | "]" | |
964 | | "^" | |
965 | =: | |
966 | ||
967 | ExpList := | |
968 | Expression | |
969 | { "," | |
970 | Expression | |
971 | } | |
972 | =: | |
973 | ||
974 | ||
975 | Expression := | |
976 | SimpleExpression [ SilentRelation SimpleExpression | |
977 | ] | |
978 | =: | |
979 | ||
980 | SimpleExpression := UnaryOrTerm { SilentAddOperator Term | |
981 | } =: | |
982 | ||
983 | UnaryOrTerm := "+" | |
984 | Term | |
985 | | "-" | |
986 | Term | |
987 | | Term =: | |
988 | ||
989 | Term := Factor { SilentMulOperator Factor | |
990 | } =: | |
991 | ||
992 | Factor := Number | string | SetOrDesignatorOrFunction | | |
993 | "(" Expression ")" | "NOT" Factor | ConstAttribute =: | |
994 | ||
995 | -- again Set | Designator causes problems as both has a first symbol, ident or Qualident | |
996 | ||
997 | SetOrDesignatorOrFunction := ( Qualident [ Constructor | | |
998 | SimpleDes [ ActualParameters ] | |
999 | ] | Constructor | |
1000 | ) | |
1001 | =: | |
1002 | ||
1003 | -- SimpleDes := { "." Ident | "[" ExpList "]" | "^" } =: | |
1004 | SimpleDes := { SubDesignator } =: | |
1005 | ||
1006 | ActualParameters := "(" | |
1007 | ( ExpList | % (* epsilon *) % | |
1008 | ) ")" =: | |
1009 | ||
1010 | ConstActualParameters := "(" % BuildSizeCheckStart % | |
1011 | ( ConstExpList | % BuildNulParam % | |
1012 | ) ")" =: | |
1013 | ||
1014 | ConstExpList := % VAR n: CARDINAL ; % | |
1015 | ConstExpression % BuildBooleanVariable % | |
1016 | % n := 1 % | |
1017 | { "," | |
1018 | ConstExpression % BuildBooleanVariable % | |
1019 | % INC(n) % | |
1020 | } | |
1021 | % PushT(n) % | |
1022 | =: | |
1023 | ||
1024 | Statement := | |
1025 | [ AssignmentOrProcedureCall | IfStatement | CaseStatement | | |
1026 | WhileStatement | RepeatStatement | LoopStatement | | |
1027 | ForStatement | WithStatement | AsmStatement | | |
1028 | "EXIT" | |
1029 | | "RETURN" | |
1030 | ( Expression | % (* in epsilon *) % | |
1031 | ) | RetryStatement | |
1032 | ] | |
1033 | =: | |
1034 | ||
1035 | RetryStatement := "RETRY" =: | |
1036 | ||
1037 | AssignmentOrProcedureCall := Designator ( ":=" SilentExpression | | |
1038 | SilentActualParameters | % (* in epsilon *) % | |
1039 | ) =: | |
1040 | ||
1041 | -- these two break LL1 as both start with a Designator | |
1042 | -- ProcedureCall := Designator [ ActualParameters ] =: | |
1043 | -- Assignment := Designator ":=" Expression =: | |
1044 | ||
1045 | StatementSequence := | |
1046 | Statement | |
1047 | { ";" | |
1048 | Statement } | |
1049 | =: | |
1050 | ||
1051 | IfStatement := | |
1052 | "IF" | |
1053 | SilentExpression "THEN" | |
1054 | StatementSequence | |
1055 | { "ELSIF" | |
1056 | Expression "THEN" | |
1057 | StatementSequence | |
1058 | } | |
1059 | [ "ELSE" | |
1060 | StatementSequence ] "END" | |
1061 | =: | |
1062 | ||
1063 | CaseStatement := "CASE" | |
1064 | SilentExpression | |
1065 | "OF" Case { "|" Case } | |
1066 | [ "ELSE" | |
1067 | StatementSequence ] "END" | |
1068 | =: | |
1069 | ||
1070 | Case := [ SilentCaseLabelList ":" StatementSequence ] =: | |
1071 | ||
1072 | WhileStatement := "WHILE" | |
1073 | SilentExpression | |
1074 | "DO" | |
1075 | StatementSequence | |
1076 | "END" | |
1077 | =: | |
1078 | ||
1079 | RepeatStatement := "REPEAT" | |
1080 | StatementSequence | |
1081 | "UNTIL" | |
1082 | SilentExpression | |
1083 | =: | |
1084 | ||
1085 | ForStatement := "FOR" | |
1086 | Ident ":=" SilentExpression "TO" SilentExpression | |
1087 | ( "BY" SilentConstExpression | % (* epsilon *) % | |
1088 | ) "DO" | |
1089 | StatementSequence "END" | |
1090 | =: | |
1091 | ||
1092 | LoopStatement := "LOOP" | |
1093 | StatementSequence | |
1094 | "END" | |
1095 | =: | |
1096 | ||
1097 | WithStatement := "WITH" | |
1098 | SilentDesignator "DO" | |
1099 | StatementSequence | |
1100 | "END" | |
1101 | =: | |
1102 | ||
1103 | ProcedureDeclaration := ProcedureHeading ";" ( ProcedureBlock % PushAutoOn % | |
1104 | Ident ) % EndBuildProcedure % | |
1105 | % PopAuto % | |
1106 | =: | |
1107 | ||
1108 | DefineBuiltinProcedure := [ "__ATTRIBUTE__" "__BUILTIN__" "(" "(" Ident ")" ")" | | |
1109 | "__INLINE__" ] | |
1110 | =: | |
1111 | ||
fd948137 | 1112 | ProcedureHeading := "PROCEDURE" % M2Error.DefaultProcedure % |
7401123f GM |
1113 | DefineBuiltinProcedure % PushAutoOn % |
1114 | ( Ident % StartBuildProcedure % | |
1115 | % PushAutoOff % | |
1116 | [ FormalParameters ] AttributeNoReturn | |
1117 | % PopAuto % | |
1118 | ) % PopAuto % | |
1119 | =: | |
1120 | ||
1121 | Builtin := [ "__BUILTIN__" | "__INLINE__" ] =: | |
1122 | ||
966f05c8 | 1123 | DefProcedureHeading := "PROCEDURE" % M2Error.DefaultProcedure % |
7401123f GM |
1124 | Builtin |
1125 | ( Ident | |
1126 | [ DefFormalParameters ] AttributeNoReturn | |
966f05c8 | 1127 | ) % M2Error.LeaveErrorScope % |
7401123f GM |
1128 | =: |
1129 | ||
1130 | AttributeNoReturn := [ "<*" Ident "*>" ] =: | |
1131 | ||
206c4f77 GM |
1132 | AttributeUnused := [ "<*" Ident "*>" ] =: |
1133 | ||
7401123f GM |
1134 | -- introduced procedure block so we can produce more informative |
1135 | -- error messages | |
1136 | ||
1137 | ProcedureBlock := { Declaration } [ "BEGIN" BlockBody ] "END" | |
1138 | =: | |
1139 | ||
1140 | Block := { Declaration } InitialBlock FinalBlock "END" =: | |
1141 | ||
1142 | InitialBlock := [ "BEGIN" BlockBody ] =: | |
1143 | ||
1144 | FinalBlock := [ "FINALLY" BlockBody ] =: | |
1145 | ||
1146 | BlockBody := NormalPart [ "EXCEPT" ExceptionalPart ] =: | |
1147 | ||
1148 | NormalPart := StatementSequence =: | |
1149 | ||
1150 | ExceptionalPart := StatementSequence =: | |
1151 | ||
1152 | Declaration := "CONST" { ConstantDeclaration ";" } | | |
1153 | "TYPE" { TypeDeclaration ";" } | | |
1154 | "VAR" { VariableDeclaration ";" } | | |
1155 | ProcedureDeclaration ";" | | |
1156 | ModuleDeclaration ";" =: | |
1157 | ||
1158 | DefFormalParameters := "(" [ DefMultiFPSection ] ")" FormalReturn =: | |
1159 | ||
1160 | DefMultiFPSection := DefExtendedFP | | |
1161 | FPSection [ ";" DefMultiFPSection ] =: | |
1162 | ||
1163 | FormalParameters := "(" [ MultiFPSection ] ")" FormalReturn =: | |
1164 | ||
1165 | MultiFPSection := ExtendedFP | | |
1166 | FPSection [ ";" MultiFPSection ] =: | |
1167 | ||
1168 | FPSection := NonVarFPSection | VarFPSection =: | |
1169 | ||
1170 | DefExtendedFP := DefOptArg | "..." =: | |
1171 | ||
1172 | ExtendedFP := OptArg | "..." =: | |
1173 | ||
206c4f77 | 1174 | VarFPSection := "VAR" IdentList ":" FormalType [ AttributeUnused ] =: |
7401123f | 1175 | |
206c4f77 | 1176 | NonVarFPSection := IdentList ":" FormalType [ AttributeUnused ] =: |
7401123f GM |
1177 | |
1178 | OptArg := "[" Ident ":" FormalType [ "=" SilentConstExpression ] "]" =: | |
1179 | ||
1180 | DefOptArg := "[" Ident ":" FormalType "=" SilentConstExpression "]" =: | |
1181 | ||
1182 | FormalType := { "ARRAY" "OF" } Qualident =: | |
1183 | ||
fd948137 GM |
1184 | ModuleDeclaration := "MODULE" % M2Error.DefaultInnerModule % |
1185 | % PushAutoOn % | |
7401123f GM |
1186 | Ident % StartBuildInnerModule ; |
1187 | BuildModuleStart ; | |
1188 | ||
1189 | PushAutoOff % | |
1190 | [ Priority ] ";" | |
1191 | { Import | |
1192 | } [ Export | |
1193 | ] | |
1194 | Block % PushAutoOn % | |
1195 | Ident % EndBuildInnerModule % | |
1196 | % PopAuto ; PopAuto ; PopAuto % | |
1197 | =: | |
1198 | ||
1199 | Priority := "[" SilentConstExpression "]" =: | |
1200 | ||
1201 | Export := "EXPORT" ( "QUALIFIED" | |
1202 | IdentList | | |
1203 | "UNQUALIFIED" | |
1204 | IdentList | | |
1205 | IdentList ) ";" =: | |
1206 | ||
1207 | Import := "FROM" Ident "IMPORT" IdentList ";" | | |
1208 | "IMPORT" | |
1209 | IdentList ";" =: | |
1210 | ||
fd948137 GM |
1211 | DefinitionModule := "DEFINITION" % M2Error.DefaultDefinitionModule % |
1212 | "MODULE" % PushAutoOn % | |
7401123f GM |
1213 | [ "FOR" string ] |
1214 | Ident % StartBuildDefFile ; | |
1215 | P3StartBuildDefModule ; | |
1216 | PushAutoOff % | |
1217 | ";" | |
1218 | { Import | |
1219 | } [ Export | |
1220 | ] | |
1221 | { Definition } | |
1222 | "END" % PushAutoOn % | |
1223 | Ident % EndBuildFile ; | |
1224 | P3EndBuildDefModule % | |
1225 | "." % PopAuto ; PopAuto ; PopAuto % | |
1226 | =: | |
1227 | ||
1228 | Definition := "CONST" { ConstantDeclaration ";" } | | |
1229 | "TYPE" | |
1230 | { Ident ( ";" | |
1231 | | "=" Type Alignment ";" ) | |
1232 | } | |
1233 | | | |
1234 | "VAR" { VariableDeclaration ";" } | | |
1235 | DefProcedureHeading ";" =: | |
1236 | ||
1237 | AsmStatement := 'ASM' [ 'VOLATILE' ] '(' AsmOperands ')' =: | |
1238 | ||
1239 | NamedOperand := '[' Ident ']' =: | |
1240 | ||
1241 | AsmOperandName := [ NamedOperand ] =: | |
1242 | ||
1243 | AsmOperands := AsmOperandName string [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ] | |
1244 | =: | |
1245 | ||
1246 | AsmList := [ AsmElement ] { ',' AsmElement } =: | |
1247 | ||
1248 | AsmElement := string '(' Expression ')' | |
1249 | =: | |
1250 | ||
1251 | TrashList := [ string ] { ',' string } =: | |
1252 | ||
1253 | FNB |