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