compilationUnit := definitionModule | implOrPrgmModule | blueprint ;
definitionModule := DEFINITION MODULE moduleIdent ( '[' blueprintToObey ']' )? ( FOR typeToExtend )? ';' ( import ';' )* definition* END moduleIdent '.' ;
moduleIdent := Ident ; blueprintIdent := Ident ; typeToExtend := Ident ;
blueprintToObey := blueprintIdent ;
import := IMPORT impexLib ( ',' moreImpexLibs | ALIAS unqualifiedAliases )? | libGenDirective ;
impexLib := Ident reExport? ;
moreImpexLibs := impexLib ( ',' impexLib )* ;
reExport := '+' ;
unqualifiedAliases := identList ;
libGenDirective := GENLIB libIdent FROM template FOR templateParamList END ;
libIdent := Ident ; template := Ident ; placeholder := Ident ;
replacement := NumberLiteral | StringLiteral | ChevronText ;
identList := Ident ( ',' Ident )* ;
definition := CONST ( constDefinition ';' )+ | TYPE ( typeDefinition ';' )+ | VAR ( identList '=' typeIdent ';' )+ | procedureHeader ';' ;
typeIdent := qualident ;
constDefinition := ( '[' propertyToBindTo ']' | restrictedExport )? Ident '=' constExpression ;
constExpression := expression ;
restrictedExport := '*' ;
typeDefinition := restrictedExport? Ident '=' ( type | OPAQUE ) ;
qualident := Ident ( '.' Ident )* ;
type := derivedType | equivType | subrangeType | enumType | setType | arrayType | recordType | pointerType | coroutineType | procedureType ;
derivedType := typeIdent ;
equivType := ALIAS OF typeIdent | CONST dynamicTypeIdent ;
dynamicTypeIdent := typeIdent ;
subrangeType := range OF ordinalOrScalarType ;
range := '[' greaterThan? constExpression '..' lessThan? constExpression ']' ;
greaterThan := '>' ;
lessThan := '<' ;
ordinalOrScalarType := typeIdent ;
enumType := '(' ( '+' enumTypeToExtend )? identList ')' ;
enumTypeToExtend := typeIdent ;
enumTypeIdent := typeIdent ;
setType := SET OF enumTypeIdent ;
arrayType := ARRAY lessThan? valueCount ( ',' valueCount )* OF typeIdent ;
valueCount := constExpression ;
recordType := RECORD ( '(' recTypeToExtend ')' )? fieldList ( ';' fieldList )* ) ;
fieldList : restrictedExport? variableDeclaration ( '=' constExpression )? ;
recTypeToExtend := typeIdent ;
pointerType := POINTER TO CONST? typeIdent ;
coroutineType := COROUTINE '(' assocProcType ')' ;
assocProcType : typeIdent ;
procedureType := PROCEDURE ( formalType ( ',' formalType )* )? ( ':' returnedType )? ;
formalType := simpleFormalType | attributedFormalType | variadicFormalType ;
simpleFormalType := ( ARRAY OF )? typeIdent | castingFormalType ;
castingFormalType := CAST ( ARRAY OF OCTET | addressTypeIdent ) ;
addressTypeIdent := ( UNSAFE '.' )? ADDRESS ;
attributedFormalType := ( CONST | NEW | VAR ) ( simpleFormalType | simpleVariadicFormalType ) ;
simpleVariadicFormalType := ARGLIST reqNumOfArgs? OF simpleFormalType terminator? ;
reqNumOfArgs := greaterThan? constExpression ;
terminator := '|' constQualident ;
constQualident := qualident ;
variadicFormalType := ARGLIST reqNumOfArgs? OF ( '{' nonVariadicFormalType ( ';' nonVariadicFormalType )* '}' | simpleFormalType ) terminator? ;
nonVariadicFormalType := ( CONST | NEW | VAR )? simpleFormalType ;
procedureHeader := PROCEDURE ( '[' ( entityToBindTo | COROUTINE ) ']' | restrictedExport )? procedureSignature ;
procedureSignature := Ident ( '(' formalParams ( ';' formalParams )* ')' )? ( ':' returnedType )? ;
formalParams := identList ':' ( simpleFormalType | variadicFormalParams ) | attributedFormalParams ;
attributedFormalParams := ( CONST | NEW | VAR ) identList ':' ( simpleFormalType | simpleVariadicFormalType ) ;
variadicFormalParams := ARGLIST reqNumOfArgs? OF ( ( '{' nonVariadicFormalParams ( ';' nonVariadicFormalParams )* '}') | simpleFormalType ) terminator? ;
nonVariadicFormalParams := ( CONST | NEW | VAR )? identList ':' simpleFormalType ;
implOrPrgmModule := IMPLEMENTATION? MODULE moduleIdent ';' ( privateImport ';' )* block moduleIdent '.' ;
privateImport := IMPORT importLib ( ',' moreImportLibs | ALIAS privateAliases )? ;
importLib := Ident ;
moreImportLibs := identList ;
privateAliases := identList | '*' ;
block := declaration* ( BEGIN statementSequence )? END ;
declaration := CONST ( Ident '=' constExpression ';' )+ | TYPE ( typeDeclaration ';' )+ | VAR ( variableDeclaration ';' )+ | ALIAS localAliases FOR origin ';' procedureHeader ';' block Ident ';' ;
localAliases := privateAliases ;
origin := ( Ident '.' )+ '*' ;
typeDeclaration := Ident '=' ( type | indeterminateRecType ) ;
indeterminateRecType := '~' RECORD ( variableDeclaration ';' )+ indeterminateField END ;
indeterminateRecType := '~' Ident ':' ARRAY '~' discriminantFieldIdent OF typeIdent END ;
discriminantFieldIdent := Ident ;
variableDeclaration := identList ':' ( ( ARRAY valueCount OF )? typeIdent | subrangeType ) ;
statementSequence := statement ( ';' statement )* ;
statement := memMgtOperation | updateOrProcCall | ifStatement | caseStatement | loopStatement | whileStatement | repeatStatement | forStatement | EXIT ;
memMgtOperation := NEW designator ( OF initSize | := initValue )? | RETAIN designator | RELEASE designator ;
initSize := expression ; initValue := expression ;
updateOrProcCall := designator ( incOrDecSuffix | ':=' expression | '(' expressionList ')' )? | COPY designator ':=' expression ;
incOrDecSuffix := '++' | '--' ;
returnStatement := ( RETURN | YIELD ) expression? ;
ifStatement := IF boolExpression THEN statementSequence ( ELSIF boolExpression THEN statementSequence )? ( ELSE statementSequence )? END ;
boolExpression := expression ;
caseStatement := CASE expression OF ( '|' case )+ ( ELSE statementSequence )? END ;
case := caseLabels ( ',' caseLabels )* ':' statementSequence ;
caseLabels := constExpression ( '..' constExpression )? ;
loopStatement := LOOP statementSequence END ;
whileStatement := WHILE boolExpression DO statementSequence END ;
repeatStatement := REPEAT statementSequence UNTIL boolExpression ;
forStatement := FOR forLoopVariants IN iterableExpr DO statementSequence END ;
forLoopVariants := accessor ascOrDesc? ( ',' value )? | VALUE value ascOrDesc? ;
accessor := Ident ; value := Ident ;
iterableExpr := designator | '[' expression '..' expression ']' OF ordinalType ;
ascOrDesc := incOrDecSuffix ;
ordinalType := typeIdent ;
designator := qualident designatorTail? ;
designatorTail := ( ( '[' exprListOrSlice ']' | '^' ) ( '.' Ident )* )+ ;
exprListOrSlice := expression ( ( ',' expression )* | '..' expression? ) ;
expressionList := expression ( ',' expression )* ;
expression := simpleExpression ( operL1 simpleExpression )? ;
operL1 := '=' | '#' | '<' | '<=' | '>' | '>=' | IN | identityOp ;
identityOp := '==' ;
simpleExpression := term ( operL2 term )* | '-' simpleFactor ;
operL2 := '+' | '-' | OR | concatOp ;
concatOp := '&' ;
term := simpleTerm ( operL3 simpleTerm )* ;
operL3 := '*' | '/' | DIV | MOD | AND | setDiffOp ;
setDiffOp := '\' ;
simpleTerm := NOT? factorOrTypeConv ;
factor := simpleFactor ( typeConvOp typeIdent )? ;
typeConvOp := '::' ;
simpleFactor := NumberLiteral | StringLiteral | structuredValue | designatorOrFuncCall | '(' expression ')' ;
designatorOrFuncCall := designator ( '(' expressionList? ')' )? ;
structuredValue := '{' valueComponent ( ',' valueComponent )* '}' ;
valueComponent := constExpression (( BY | '..' )? constExpression )? | runtimeExpression ;
runtimeExpression := expression ;
blueprint := BLUEPRINT blueprintIdent ( '[' blueprintToRefine ']' )? ( FOR blueprintForTypeToExtend )? ';' ( REFERENTIAL identList ';' )? MODULE TYPE '=' ( typeClassification ( ';' literalCompatibility)? | NONE ) ';' ( constraint ';' )* ( requirement ';' )* END blueprintIdent '.' ;
blueprintIdent := Ident ;
blueprintToRefine := blueprintIdent ; blueprintForTypeToExtend := blueprintIdent ;
typeClassification := '{' determinedClassification ( ';' refinableClassification )? ( ';' '*' )? '}' | '*' ;
determinedClassification := classificationIdent ( ',' classificationIdent )* ;
refinableClassification := '~' classificationIdent ( ',' '~' classificationIdent )* ;
classificationIdent := Ident ;
literalCompatibility := TLITERAL '=' protoLiteral ( '|' protoLiteral )* ;
protoLiteral := protoLiteralIdent | structuredProtoLiteral ;
protoLiteralIdent := Ident ;
structuredProtoLiteral := '{' ( ARGLIST reqValueCount? OF ( '{' builtinOrReferential ( ',' builtinOrReferential )* '}' | builtinOrReferential ) ) | builtinOrReferential '}' ;
reqValueCount := greaterThan? wholeNumber ;
greaterThan := '>' ;
wholeNumber : NumberLiteral ;
builtinOrReferential := Ident ;
constraint := constraintTerm ( oneWayDependency | mutualDependencyOrExclusion ) ;
constraintTerm := '(' classificationOrFlagIdent ')' | '[' bindableEntityOrProperty ']' ;
bindableEntityOrProperty := entityToBindTo | propertyToBindTo ;
oneWayDependency := '->' termList ( '|' termList )* ;
mutualDependencyOrExclusion := ( '<>' | '><' ) termList ;
termList := constraintTerm ( ',' constraintTerm )* ;
classificationOrFlagIdent := Ident ;
requirement := condition '->' ( typeRequirement | constRequirement | procRequirement ) ;
condition := NOT? boolConstIdent ;
boolConstIdent := Ident ;
typeRequirement := TYPE typeDefinition ;
constRequirement := CONST ( '[' propertyToBindTo ']' ( simpleConstRequirement | '=' NONE ) | restrictedExport? simpleConstRequirement ) ;
simpleConstRequirement := Ident ( '=' constExpression | ':' builtinTypeIdent ) ;
constExpression := expression ;
builtinTypeIdent := Ident ;
restrictedExport := '*' ;
propertyToBindTo := memMgtProperty | collectionProperty | scalarProperty | TFLAGS ;
memMgtProperty := TDYN | TREFC ;
collectionProperty := TORDERED | TSORTED | TLIMIT ;
scalarProperty := TSCALAR | TMAX | TMIN ;
procRequirement := PROCEDURE ( '[' ( entityToBindTo | COROUTINE ) ']' ( procedureSignature | '=' NONE ) | restrictedExport? procedureSignature ) ;
entityToBindTo := bindableResWord | bindableOperator | bindableMacro ;
bindableResWord := NEW | RETAIN | RELEASE | COPY | bindableFor ;
bindableFor := FOR forBindingDifferentiator? ;
forBindingDifferentiator := ':' ( '++' | '--' ) ;
bindableOperator := '+' | '-' | '*' | '/' | '\' | '=' | '<' | '>' | '::' | IN | DIV | MOD | unaryMinus ;
unaryMinus := '+/-' ;
bindableMacro := ABS | LENGTH | EXISTS | SUBSET | READ | READNEW | WRITE | WRITEF | SXF | VAL | multiBindableMacro1 | multiBindableMacro2 | multiBindableMacro3 ;
multiBindableMacro1 := ( COUNT | VALUE | SEEK ) bindingDifferentiator1? ;
bindingDifferentiator1 := ':' '#' ;
multiBindableMacro2 := ( STORE | INSERT | REMOVE ) bindingDifferentiator2? ;
bindingDifferentiator2 := ':' ( ',' | '#' | '*' ) ;
multiBindableMacro3 := APPEND bindingDifferentiator3? ;
bindingDifferentiator3 := ':' ( ',' | '*' ) ;