Sirocco.ThreeC4
Copyright © 1986 by Xerox Corporation. All rights reserved.
Bhargava, August 12, 1986 11: 24: 02 pm PDT
Bill Jackson (bj) August 18, 1986 4:13:16 pm PDT
SiroccoParser: Control Module;
Wart: Module = Begin
Generic: EnumeratedBaseType = {array, boolean, bulkDataSink, bulkDataSource, cardinal, choice, enumeration, error, integer, longCardinal, longInteger, procedure, record, sequence, string, unspecified};
Tokens
identifier: GenericToken = "tokenID";
numberD: GenericToken = "tokenDECIMAL";
numberO: GenericToken = "tokenOCTAL";
numberH: GenericToken = "tokenHEX";
Rope: GenericToken = "tokenROPE";
Types
Primitive Types
BOOLEAN: CedarType;
CARDINAL: CedarType;
CARD: CedarType;
NAT: CedarType;
INT: CedarType;
Imported Types
CComponent: CedarType From SiroccoPrivate;
CType: CedarType From SiroccoPrivate;
EqualProc: CedarType From HashTable;
FunctionList: CedarType From SiroccoPrivate;
HashProc: CedarType From HashTable;
Key: CedarType From HashTable;
ROPE: CedarType From Rope;
SeqIndex: CedarType From HashTable;
Table: CedarType From HashTable;
TABLES: CedarType From SiroccoPrivate;
Value: CedarType From HashTable;
Imported Procs
Cat: CedarFunction [ROPE.a, ROPE.b, ROPE.c] Returns [ROPE.d] From Rope;
SharedReps [ROPE.a, ROPE.b, ROPE.c, ROPE.d];
Concat: CedarFunction [ROPE.a, ROPE.b] Returns [ROPE.c] From Rope;
Equal: CedarFunction [ROPE.a, ROPE.b] Returns [BOOLEAN] From Rope;
Fetch: CedarFunction [Table, ROPE] Returns [BOOLEAN, Value] From HashTable;
Nest: CedarFunction [ROPE.a, NAT.level] Returns [ROPE.b] From SiroccoPrivate;
NewFcn: CedarFunction [ROPE.name, ROPE.obj, INT.size] Returns [ROPE.out] From SiroccoPrivate;
RopeFromCard: CedarFunction [CARD] Returns [ROPE] From Convert;
RopeFromInt: CedarFunction [INT] Returns [ROPE] From Convert;
End;
ParserPrivate: Module = Begin
Since Casaba only understands INTs
card: BaseFunction [INT] Returns [CARD];
int: BaseFunction [CARD] Returns [INT];
nat: BaseFunction [INT] Returns [NAT];
Get values from tokens
GetCardFromDecimal: BaseFunction [numberD] Returns [CARD];
GetCardFromOctal: BaseFunction [numberO] Returns [CARD];
GetCardFromHex: BaseFunction [numberH] Returns [CARD];
RopeTokenToROPE: BaseFunction [Rope] Returns [ROPE];
Convince Casaba that things are not dammaged
CopyRope: BaseFunction [ROPE.a] Returns [ROPE.b];
CopyTables: BaseFunction [TABLES.ARG] Returns [TABLES.RES];
CopyAll: BaseFunction [ROPE.ARG, FunctionList.ARG, TABLES.ARG] Returns [ROPE.RES, FunctionList.RES, TABLES.RES];
Hash Key Functions
CreateCanonicalKey: BaseFunction [identifier, numberD.prog, numberD.val] Returns [ROPE];
CreateKey: BaseFunction [identifier] Returns [ROPE];
Hash Table Operations
CopyFunctionList: BaseFunction [FunctionList.ARG] Returns [FunctionList.RES];
CreateTables: BaseFunction Returns [TABLES];
DiskToTable: BaseFunction [TABLES.ARG, identifier, numberD.progno, numberD.verno] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
FetchFromGlobalTable: BaseFunction [TABLES.ARG, ROPE] Returns [Table];
Type Tree (lists) Operations
CheckCanonicalType: BaseFunction [ROPE.type, ROPE.constant, TABLES.ARG] Returns [TABLES.RES];
CheckResultsForSourceAndSink: BaseFunction [CComponent] Returns [INT]; -- actually BOOLEAN
CompareTypes: BaseFunction [CType.a, CType.b, TABLES] Returns [INT]; -- actually BOOLEAN
GetCType: BaseFunction [identifier, CComponent, TABLES] Returns [CType, ROPE];
GetLengthOfCComponentList: BaseFunction [CComponent, INT.arg] Returns [INT.res];
SeeIfArrOrSeq: BaseFunction [CType.arg, INT, TABLES] Returns [CType.res, ROPE];
Utility Operation
AddOne: BaseFunction [INT.ARG] Returns [INT.RES] DamagedReps [INT.ARG];
Canonical Type manipulation
CopyCComponent: BaseFunction [CComponent.arg] Returns [CComponent.res];
GetCTypeFirstChild: BaseFunction [CType] Returns [CComponent];
MkCComponent: BaseFunction [ROPE.name, INT.valBinding, ROPE.typeBinding, CComponent.sibling] Returns [CComponent];
MkCType: BaseFunction [Generic.class, INT.bound, CComponent.firstChild]
Returns [CType];
MkNILCComponent: BaseFunction [] Returns [CComponent];
Narrowing from Values from Hash Tables
ValueToConstant: BaseFunction [Value] Returns [Constant];
ValueToRope: BaseFunction [Value] Returns [ROPE];
ValueToRopeConstant: BaseFunction [Value, ROPE.a] Returns [ROPE.b] DamagedReps [ROPE.a];
Utility Functions
Copy: BaseFunction [ROPE.arg, CType.arg, Constant.arg, TABLES.arg] Returns [ROPE.res, CType.res, Constant.res, TABLES.res];
FetchFromTypeTable: BaseFunction [TABLES.ARG, ROPE] Returns [CType];
GetObjectName: BaseFunction [ROPE.type, TABLES] Returns [ROPE.typeobject];
MakeUpFunctionName: BaseFunction [] Returns [ROPE.name];
Remove: BaseFunction [identifier, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
SendError: BaseFunction [ROPE] Returns [CARD];
Insert Key, Value pairs into Tables
IntoCondensedFunctionTable: BaseFunction [ROPE.functionName, ROPE.function, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
IntoUnresolvedConstantTable: BaseFunction [TABLES.ARG, ROPE.key, Type.value, Constant.value] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
IntoUnresolvedTypeTable: BaseFunction [TABLES.ARG, ROPE.key, Type.value] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
Work Table Functions
ClearWorkTable: BaseFunction [TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
EnterNamesIntoWorkTable: BaseFunction [CType, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
FillWorkTable: BaseFunction [CType, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
Misc Functions
AddLocalConstantToRope: BaseFunction [identifier, ROPE.constantName, ROPE.constantType, FunctionList.functionList, ROPE.a, TABLES.ARG] Returns [ROPE.b, FunctionList.RES, TABLES.RES] DamagedReps [ROPE.a, FunctionList.functionList, TABLES.ARG];
CanonicaliseLocalReferenceType: BaseFunction [identifier, TABLES.ARG] Returns [ROPE, CType, TABLES.RES] DamagedReps [TABLES.ARG];
GetConstantType: BaseFunction [identifier, TABLES.ARG] Returns [ROPE, CType, Constant, TABLES.RES] DamagedReps [TABLES.ARG];
TryToCoerceNumber: BaseFunction [CType, CARD] Returns [INT];
Predicates
Array: BaseFunction [ROPE.type, TABLES] Returns [BOOLEAN];-- Sees if type is array
CheckIfEmpty: BaseFunction [TABLES.ARG] Returns [TABLES.RES];
CompareClass: BaseFunction [CType, Generic.b] Returns [CComponent];
InsureErrorType: BaseFunction [identifier, TABLES.ARG] Returns [TABLES.RES];
IsEnumerationConstant: BaseFunction [CType, identifier] Returns [INT];
NotEnumeration: BaseFunction [CType] Returns [BOOLEAN];
SeeIfDuplicated: BaseFunction [TABLES.ARG, identifier, CARD] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
SeeIfInt: BaseFunction [CType] Returns [BOOLEAN];
Unknown Purpose...
AddFunctionList: BaseFunction [Value, FunctionList.ARG] Returns [FunctionList.RES] DamagedReps [FunctionList.ARG];
AddFunctionToTable: BaseFunction [Value, FunctionList, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
ConsFunctionList: BaseFunction [FunctionList.arg, ROPE] Returns [FunctionList.res] DamagedReps [FunctionList.arg];
GetTypeOfComponent: BaseFunction [identifier, ROPE.arg, TABLES] Returns [ROPE.TypeOfSequence];
TypeOfSequence: BaseFunction [ROPE.sequenceName, TABLES] Returns [ROPE.TypeOfSequence];
End;
AbstractTypes: Module = Begin
Abstract Types
Program: AbstractType [MakeSymbolTable];
ReferencedProgramList: AbstractType [ReadInTable];
ReferencedProgram: AbstractType [ReadInTable];
DeclarationList: AbstractType [BuildTable, RecordNames];
Declaration: AbstractType [BuildTable, RecordNames];
Type: AbstractType [CanonicaliseType];
CorrespondenceList: AbstractType [CanonicaliseCorrespondenceList, CheckCorrespondenceList];
CandidateList: AbstractType [CanonicaliseCandidateList, EmptyWorkTableOfNames];
FieldList: AbstractType [CanonicaliseFieldList]; -- I want a FIELD type (ajd)
Constant: AbstractType [Coerce, GetCARDINAL, ConstantToRope];
ElementList: AbstractType [CoerceElementList, ConstantToRope, Size, ConstructFunction];
ComponentList: AbstractType [CoerceComponents, ConstantToRope, CheckAllNames];
Component: AbstractType [CoerceComponents, ConstantToRope, CheckAllNames];
NameList: AbstractType [CheckIfErrorNames, CanonicaliseFieldsFromNameList, CoerceComponentNameList, NameListToRope, EmptyWorkTableOfNames, TypeOfNameList];
number: AbstractType [GetCARDINAL, NumberToCard];
Abstract Type Operations
BuildTable: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
CanonicaliseCandidateList: TreeRecursiveFunction [Tree, CComponent.arg, CType, TABLES.ARG] Returns [CComponent.res, TABLES.RES] DamagedReps [TABLES.ARG] SharedReps [CComponent.arg, CComponent.res];
CanonicaliseCorrespondenceList: TreeRecursiveFunction [Tree, CComponent.arg, TABLES.ARG] Returns [CComponent.res, TABLES.RES] DamagedReps [TABLES.ARG] SharedReps [CComponent.arg, CComponent.res];
CanonicaliseFieldList: TreeRecursiveFunction [Tree, CComponent.arg, TABLES.ARG] Returns [CComponent.res, TABLES.RES] DamagedReps [TABLES.ARG] SharedReps [CComponent.arg, CComponent.res];
CanonicaliseFieldsFromNameList: TreeRecursiveFunction [Tree, ROPE.arg, CComponent.arg, TABLES.ARG] Returns [CComponent.res, TABLES.RES] DamagedReps [TABLES.ARG] SharedReps [CComponent.arg, CComponent.res];
NOTE: THIS PROBABLY DOES NOT NEED THE TABLES ARGUMENT/RESULT
CanonicaliseType: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [ROPE, CType, TABLES.RES] DamagedReps [TABLES.ARG];
CheckAllNames: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
CheckCorrespondenceList: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
CheckIfErrorNames: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
Coerce: TreeRecursiveFunction [Tree, CType, ROPE, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
CoerceComponentNameList: TreeRecursiveFunction [Tree, Constant, CComponent, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
CoerceComponents: TreeRecursiveFunction [Tree, CComponent, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
CoerceElementList: TreeRecursiveFunction [Tree, CType, ROPE, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
ConstantToRope: TreeRecursiveFunction [Tree, ROPE.constantName, ROPE.constantType, FunctionList.functionList, ROPE.arg, TABLES.ARG] Returns [ROPE.res, FunctionList.res, TABLES.RES] DamagedReps [ROPE.arg, TABLES.ARG, FunctionList.functionList];
ConstructFunction: TreeRecursiveFunction [Tree, INT.ElementNo, ROPE.functionSoFar, ROPE.constantName, ROPE.constantType, FunctionList.constantFunctions, TABLES.ARG] Returns [ROPE.res, FunctionList.RES, TABLES.RES] DamagedReps [ROPE.functionSoFar, INT.ElementNo, FunctionList.constantFunctions, TABLES.ARG];
EmptyWorkTableOfNames: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
GetCARDINAL: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [CARD, TABLES.RES] DamagedReps [TABLES.ARG];
MakeSymbolTable: TreeRecursiveFunction [Tree] Returns [TABLES.RES];
NumberToCard: TreeRecursiveFunction [Tree] Returns [CARD];
NameListToRope: TreeRecursiveFunction [Tree, ROPE.arg, ROPE.const, TABLES.ARG] Returns [ROPE.res] DamagedReps [ROPE.arg];
ReadInTable: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
RecordNames: TreeRecursiveFunction [Tree, TABLES.ARG] Returns [TABLES.RES] DamagedReps [TABLES.ARG];
ReturnNodeClass: TreeRecursiveFunction [Tree] Returns [Generic];
Size: TreeRecursiveFunction [Tree, INT.arg] Returns [INT.res] DamagedReps [INT.arg]; --Gets Size of Element List
TypeOfNameList: TreeRecursiveFunction [Tree, ROPE.constantType, TABLES] Returns [ROPE.typeOf];
End;
AbstractProductions: Module = Begin
Program: AbstractType [MakeSymbolTable];
Program: AbstractProduction [identifier, numberD.progno, numberD.verno, ReferencedProgramList, DeclarationList];
ReferencedProgramList: AbstractType [ReadInTable];
ReferencedProgramList.empty: AbstractProduction [];
ReferencedProgramList.more: AbstractProduction [ReferencedProgramList, ReferencedProgram];
ReferencedProgram: AbstractType [ReadInTable];
ReferencedProgram: AbstractProduction [identifier, numberD.progno, numberD.verno];
DeclarationList: AbstractType [BuildTable, RecordNames];
DeclarationList.empty: AbstractProduction [];
DeclarationList.more: AbstractProduction [DeclarationList, Declaration];
Declaration: AbstractType [BuildTable, RecordNames];
Declaration.type: AbstractProduction [identifier, Type];
Declaration.constant: AbstractProduction [identifier, Type, Constant];
Type: AbstractType [CanonicaliseType];
Type.array: AbstractProduction [Constant, Type];
Type.boolean: AbstractProduction [];
Type.bulkDataSink: AbstractProduction [];
Type.bulkDataSource: AbstractProduction [];
Type.cardinal: AbstractProduction [];
Type.choice: AbstractProduction [Type, CandidateList];
Type.emptyRecord: AbstractProduction [];
Type.enumeration: AbstractProduction [CorrespondenceList];
Type.error: AbstractProduction [FieldList];
Type.integer: AbstractProduction [];
Type.localReference: AbstractProduction [identifier];
Type.longCardinal: AbstractProduction [];
Type.longInteger: AbstractProduction [];
Type.procedure: AbstractProduction [FieldList.arg, FieldList.res, NameList];
Type.record: AbstractProduction [FieldList];
Type.remoteReference: AbstractProduction [identifier.a, identifier.b];
Type.sequence: AbstractProduction [Constant, Type];
Type.string: AbstractProduction [];
Type.unspecified: AbstractProduction [];
CorrespondenceList: AbstractType [CanonicaliseCorrespondenceList, CheckCorrespondenceList];
CorrespondenceList.one: AbstractProduction [identifier, Constant];
CorrespondenceList.more: AbstractProduction [CorrespondenceList.value, CorrespondenceList.next];
CandidateList: AbstractType [CanonicaliseCandidateList, EmptyWorkTableOfNames];
CandidateList.one: AbstractProduction [NameList, Type];
CandidateList.more: AbstractProduction [CandidateList.value, CandidateList.next];
FieldList: AbstractType [CanonicaliseFieldList]; -- I want a FIELD type (ajd)
FieldList.empty: AbstractProduction [];
FieldList.one: AbstractProduction [NameList, Type];
FieldList.more: AbstractProduction [FieldList.value, FieldList.rest];
Constant: AbstractType [Coerce, GetCARDINAL, ConstantToRope];
Constant.choice: AbstractProduction [identifier, Constant];
Constant.componentlist: AbstractProduction [ComponentList];
Constant.elementList: AbstractProduction [ElementList];
Constant.empty: AbstractProduction [];
Constant.false: AbstractProduction [];
Constant.id: AbstractProduction [identifier];
Constant.negativeNumber: AbstractProduction [number];
Constant.number: AbstractProduction [number];
Constant.remoteReference: AbstractProduction [identifier.left, identifier.right];
Constant.string: AbstractProduction [Rope];
Constant.true: AbstractProduction [];
Constant.unbounded: AbstractProduction [];
ElementList: AbstractType [CoerceElementList, ConstantToRope, Size, ConstructFunction];
ElementList.one: AbstractProduction [Constant];
ElementList.more: AbstractProduction [Constant, ElementList];
ComponentList: AbstractType [CoerceComponents, ConstantToRope, CheckAllNames];
ComponentList.one: AbstractProduction [Component];
ComponentList.more: AbstractProduction [Component, ComponentList];
Component: AbstractType [CoerceComponents, ConstantToRope, CheckAllNames];
Component: AbstractProduction [NameList, Constant];
NameList: AbstractType [CheckIfErrorNames, CanonicaliseFieldsFromNameList, CoerceComponentNameList, NameListToRope, EmptyWorkTableOfNames, TypeOfNameList];
NameList.empty: AbstractProduction [];
NameList.one: AbstractProduction [identifier];
NameList.more: AbstractProduction [identifier, NameList];
number: AbstractType [GetCARDINAL, NumberToCard];
number.decimal: AbstractProduction [numberD];
number.hex: AbstractProduction [numberH];
number.octal: AbstractProduction [numberO];
End;
AbstractSyntax: Module = Begin
Program: AbstractType [MakeSymbolTable];
for Program: AbstractProduction [identifier, numberD.progno, numberD.verno, ReferencedProgramList, DeclarationList]
let MakeSymbolTable[tree] ← BuildTable[DeclarationList, tables2]
where tables2 ← ReadInTable[ReferencedProgramList, tables1]
where programKey ← CreateCanonicalKey[identifier, numberD.progno, numberD.verno]
where tables1 ← RecordNames[DeclarationList, tables]
where tables ← CreateTables[]
;
ReferencedProgramList: AbstractType [ReadInTable];
for ReferencedProgramList.empty: AbstractProduction []
let ReadInTable[tree, tables] ← CopyTables[tables]
;
for ReferencedProgramList.more: AbstractProduction [ReferencedProgramList, ReferencedProgram]
let ReadInTable[tree, tables] ← ReadInTable[ReferencedProgram, tables1]
where tables1 ← ReadInTable[ReferencedProgramList, tables]
;
ReferencedProgram: AbstractType [ReadInTable];
for ReferencedProgram: AbstractProduction [identifier, numberD.progno, numberD.verno]
let ReadInTable[tree, tables] ← DiskToTable[tables, identifier, numberD.progno, numberD.verno]
;
DeclarationList: AbstractType [BuildTable, RecordNames];
for DeclarationList.empty: AbstractProduction []
let BuildTable[tree, tables] ← CopyTables[tables]
let RecordNames[tree, tables] ← CopyTables[tables]
;
for DeclarationList.more: AbstractProduction [DeclarationList, Declaration]
let BuildTable[tree, tables] ← tables2
where tables2 ← BuildTable[DeclarationList, tables1]
where tables1 ← BuildTable[Declaration, tables]
let RecordNames[tree, tables] ← RecordNames[DeclarationList, RecordNames[Declaration, tables]]
;
Declaration: AbstractType [BuildTable, RecordNames];
for Declaration.type: AbstractProduction [identifier, Type]
let BuildTable[tree, tables] ← tables1
where < canonicalType, typeTree, tables1 > ← CanonicaliseLocalReferenceType[identifier, tables]
let RecordNames[tree, tables] ← IntoUnresolvedTypeTable[tables, CreateKey[identifier], Type]
;
for Declaration.constant: AbstractProduction [identifier, Type, Constant]
let BuildTable[tree, tables] ← tables1
where < canonicalType, constantTree, value, tables1 > ← GetConstantType[identifier, tables]
let RecordNames[tree, tables] ← IntoUnresolvedConstantTable[tables, CreateKey[identifier], Type, Constant]
;
Type: AbstractType [CanonicaliseType];
for Type.array: AbstractProduction [Constant, Type]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType2, tables2 >
where cType2 ← MkCType[Generic.array, int[bound], cComponent]
where < bound, tables2 > ← GetCARDINAL[Constant, tables1]
where cComponent ← MkCComponent["", 0, cName1, MkNILCComponent[]]
where < cName1, cType1, tables1 > ← CanonicaliseType[Type, tables]
N.B. Type is a simple type, so no need to check if cName1 = "DEFAULT"
;
for Type.boolean: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "BOOLEAN", MkCType[Generic.boolean, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.bulkDataSink: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "SINK", MkCType[Generic.bulkDataSink, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.bulkDataSource: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "SOURCE", MkCType[Generic.bulkDataSource, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.cardinal: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "CARDINAL", MkCType[Generic.cardinal, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.choice: AbstractProduction [Type, CandidateList]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType2, tables5 >
where cType2 ← MkCType[Generic.choice, 0, cComponent2]
where cComponent2 ← MkCComponent["", 0, cName1, cComponent1] -- the tag type
where < cComponent1, tables5 > ← CanonicaliseCandidateList[CandidateList, MkNILCComponent[], cType1, tables3]
Check that cType1 is enumerated type - Done
where junk ← CheckIfEmpty[tables3]
where tables3 ← EmptyWorkTableOfNames[CandidateList, tables2]
where tables2 ← FillWorkTable[cType1, tables1]
where match ← CompareClass[cType1, Generic.enumeration]
where < cName1, cType1, tables1 > ← CanonicaliseType[Type, tables]
;
for Type.emptyRecord: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType, CopyTables[tables] >
where cType ← MkCType[Generic.record, 0, MkNILCComponent[]]
;
for Type.enumeration: AbstractProduction [CorrespondenceList]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType, tables2 >
where cType ← MkCType[Generic.enumeration, 0, cComponent]
where < cComponent, tables2 > ← CanonicaliseCorrespondenceList[CorrespondenceList, MkNILCComponent[], tables1]
where tables1 ← CheckCorrespondenceList[CorrespondenceList, ClearWorkTable[tables]]
;
for Type.error: AbstractProduction [FieldList]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType, tables1 >
where cType ← MkCType[Generic.error, 0, cComponent]
where < cComponent, tables1 > ← CanonicaliseFieldList[FieldList, MkNILCComponent[], tables]
;
for Type.integer: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "INTEGER", MkCType[Generic.integer, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.localReference: AbstractProduction [identifier]
let CanonicaliseType[tree, tables] ← CanonicaliseLocalReferenceType[identifier, tables]
;
for Type.longCardinal: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "LONGCARDINAL", MkCType[Generic.longCardinal, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.longInteger: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "LONGINTEGER", MkCType[Generic.longInteger, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.procedure: AbstractProduction [FieldList.arg, FieldList.res, NameList]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType, tables3 >
where cType ← MkCType[Generic.procedure, nArgs, cComponent]
where nArgs ← GetLengthOfCComponentList[cComponent, nResults]
where < cComponent, tables3 > ← CanonicaliseFieldList[FieldList.arg, resultCComponent, tables2]
where nResults ← GetLengthOfCComponentList[resultCComponent, 0]
where okay ← CheckResultsForSourceAndSink[resultCComponent]
where < resultCComponent, tables2 > ← CanonicaliseFieldList[FieldList.res, MkNILCComponent[], tables1]
where tables1 ← CheckIfErrorNames[NameList, tables]
;
for Type.record: AbstractProduction [FieldList]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType, tables1 >
where cType ← MkCType[Generic.record, 0, cComponent]
where < cComponent, tables1 > ← CanonicaliseFieldList[FieldList, MkNILCComponent[], tables]
;
for Type.remoteReference: AbstractProduction [identifier.a, identifier.b]
let CanonicaliseType[tree, tables] ← < canonicalName, cType, CopyTables[tables] >
where cType ← FetchFromTypeTable[tables, canonicalName]
where canonicalName ← ValueToRope[DirectoryEntry]
N.B. NEED TO CHECK SUCCESSFUL !!!! - Done
where okay ← if successful then 0 else int[SendError["Undeclared Remote Identifier"]]
where < successful, DirectoryEntry > ← Fetch[remoteDirectory, CreateKey[identifier.b]]
where remoteDirectory ← FetchFromGlobalTable[tables, CreateKey[identifier.a]]
;
for Type.sequence: AbstractProduction [Constant, Type]
let CanonicaliseType[tree, tables] ← < "DEFAULT", cType2, tables2 >
where cType2 ← MkCType[Generic.sequence, int[bound], cComponent]
where < bound, tables2 > ← GetCARDINAL[Constant, tables1]
where cComponent ← MkCComponent["", 0, cName1, MkNILCComponent[]]
where < cName1, cType1, tables1 > ← CanonicaliseType[Type, tables]
N.B. Type is a simple type, so no need to check if cName1 = "DEFAULT"
;
for Type.string: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "STRING", MkCType[Generic.string, 0, MkNILCComponent[]], CopyTables[tables] >
;
for Type.unspecified: AbstractProduction []
let CanonicaliseType[tree, tables] ← < "UNSPECIFIED", MkCType[Generic.unspecified, 0, MkNILCComponent[]], CopyTables[tables] >
;
CorrespondenceList: AbstractType [CanonicaliseCorrespondenceList, CheckCorrespondenceList];
for CorrespondenceList.one: AbstractProduction [identifier, Constant]
let CanonicaliseCorrespondenceList[tree, cComponentArg, tables] ← < cComponent, tables1 >
where cComponent ← MkCComponent[CreateKey[identifier], int[value], "", cComponentArg]
where < value, tables1 > ← GetCARDINAL[Constant, tables]
Check that no id or Constant appears twice -Done
let CheckCorrespondenceList[tree, tables] ← SeeIfDuplicated[tables1, identifier, value]
where < value, tables1 > ← GetCARDINAL[Constant, tables]
;
for CorrespondenceList.more: AbstractProduction [CorrespondenceList.value, CorrespondenceList.next]
INVARIANT: CorrespondenceList.value is expanded as CorrespondenceList.one.
let CanonicaliseCorrespondenceList[tree, cComponentArg, tables] ← CanonicaliseCorrespondenceList[CorrespondenceList.value, cComponent1, tables1]
where < cComponent1, tables1 > ← CanonicaliseCorrespondenceList[CorrespondenceList.next, cComponentArg, tables]
let CheckCorrespondenceList[tree, tables] ← CheckCorrespondenceList[CorrespondenceList.next, CheckCorrespondenceList[CorrespondenceList.value, tables]]
;
CandidateList: AbstractType [CanonicaliseCandidateList, EmptyWorkTableOfNames];
for CandidateList.one: AbstractProduction [NameList, Type]
let CanonicaliseCandidateList[tree, cComponentArg, cTypeTag, tables] ← CanonicaliseFieldsFromNameList[NameList, variantCName, cComponentArg, tables1]
Check if all members are of enumeration
& all members of enumeration are listed
also ascertain that the enumeration is continous - Done
where < variantCName, variantCType, tables1 > ← CanonicaliseType[Type, tables]
let EmptyWorkTableOfNames[tree, tables] ← EmptyWorkTableOfNames[NameList, tables]
;
for CandidateList.more: AbstractProduction [CandidateList.value, CandidateList.next]
INVARIANT: CandidateList.value is expanded as CandidateList.one.
let CanonicaliseCandidateList[tree, cComponentArg, cTypeTag, tables] ← CanonicaliseCandidateList[CandidateList.value, cComponent1, cTypeTag, tables1]
where < cComponent1, tables1 > ← CanonicaliseCandidateList[CandidateList.next, cComponentArg, cTypeTag, tables]
let EmptyWorkTableOfNames[tree, tables] ← EmptyWorkTableOfNames[CandidateList.next, EmptyWorkTableOfNames[CandidateList.value, tables]]
;
FieldList: AbstractType [CanonicaliseFieldList]; -- I want a FIELD type (ajd)
for FieldList.empty: AbstractProduction []
let CanonicaliseFieldList[tree, CComponentArg, tables] ← < CopyCComponent[CComponentArg], CopyTables[tables] >
;
for FieldList.one: AbstractProduction [NameList, Type]
let CanonicaliseFieldList[tree, cComponentArg, tables] ← CanonicaliseFieldsFromNameList[NameList, cName, cComponentArg, tables1]
where < cName, cType, tables1 > ← CanonicaliseType[Type, tables]
;
for FieldList.more: AbstractProduction [FieldList.value, FieldList.rest]
INVARIANT: FieldList.value is expanded as FieldList.one.
let CanonicaliseFieldList[tree, CComponentArg, tables] ← CanonicaliseFieldList[FieldList.value, cComponent1, tables1]
where < cComponent1, tables1 > ← CanonicaliseFieldList[FieldList.rest, CComponentArg, tables]
;
Constant: AbstractType [Coerce, GetCARDINAL, ConstantToRope];
for Constant.choice: AbstractProduction [identifier, Constant]
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found Choice"], CopyTables[tables] >
let Coerce[tree, typeCtype, typeTypeName, tables] ← Coerce[Constant, cType, ctypeName, tables]
where < cType, ctypeName > ← GetCType[identifier, cComponent, tables]
where cComponent ← GetCTypeFirstChild[typeCtype]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← CopyAll[Concat[rope2, "]]"], constantFunctions1, tables1]
where < rope2, constantFunctions1, tables1 > ← ConstantToRope[Constant, constantName, constantType1, constantFunctions, rope1, tables]
where constantType1 ← GetTypeOfComponent[identifier, constantType, tables]
where rope1 ← Concat[constantValue, Cat["[", CreateKey[identifier], "["]]
;
for Constant.componentlist: AbstractProduction [ComponentList]
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found Record"], CopyTables[tables] >
let Coerce[tree, typeCtype, typeTypeName, tables] ← CoerceComponents[ComponentList, cComponent, tables2]
N.B. Add Code to Check If All Names are Declared => CheckAllNames[ComponentList, typeCtype, tables]; - Done
where junk ← CheckIfEmpty[tables2]
where tables2 ← CheckAllNames[ComponentList, tables1]
where tables1 ← EnterNamesIntoWorkTable[typeCtype, tables]
where cComponent ← CompareClass[typeCtype, Generic.record]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← CopyAll[Concat[rope2, "]"], constantFunctions1, tables1]
where < rope2, constantFunctions1, tables1 > ← ConstantToRope[ComponentList, constantName, constantType, constantFunctions, rope1, tables]
where rope1 ← Concat["[", constantValue]
;
for Constant.elementList: AbstractProduction [ElementList]
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found ElementList"], CopyTables[tables] >
let Coerce[tree, typeCtype, typeTypeName, tables] ← CoerceElementList[ElementList, cType, cName, tables]
where < cType, cName > ← SeeIfArrOrSeq[typeCtype, numberOfElementInList, tables]
where numberOfElementInList ← Size[ElementList, 0]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← CopyAll[Concat[rope2, "]"], constantFunctions3, tables3]
where < rope2, constantFunctions3, tables3 > ←
if Array[constantType, tables]
then <
ConstantToRope[ElementList, constantName, constantType, constantFunctions, rope1, tables]
where rope1 ← Concat[constantValue, "["]
>
else <
CopyAll[rope1, constantFunctions1, tables1]
where rope1 ← Cat[constantValue, functionName, "["]
where tables1 ← IntoCondensedFunctionTable[functionName, function, tables2]
where function ← Nest[Cat[functionBody, "};", ""], nat[1]]
where < functionBody, constantFunctions1, tables2 > ← ConstructFunction[ElementList, 0, functionHeader, constantName, TypeOfElements, constantFunctions2, tables]
where TypeOfElements ← TypeOfSequence[constantType, tables]
where functionHeader ← NewFcn[functionName, ObjectName, Size[ElementList, 0]]
where ObjectName ← GetObjectName[constantType, tables]
where constantFunctions2 ← ConsFunctionList[constantFunctions, functionName]
where functionName ← MakeUpFunctionName[]
>
;
for Constant.empty: AbstractProduction []
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found Empty ElementList"], CopyTables[tables] >
let Coerce[tree, typeCtype, typeTypeName, tables] ← tables1
where junk ← CheckIfEmpty[tables1]
where tables1 ← EnterNamesIntoWorkTable[typeCtype, tables]
where cComponent ← CompareClass[typeCtype, Generic.record]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, "NULL"], CopyFunctionList[constantFunctions], CopyTables[tables]]
;
for Constant.false: AbstractProduction []
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found Boolean"], CopyTables[tables] >
let Coerce[tree, type, typeTypeName, tables] ← CheckCanonicalType[typeTypeName, "BOOLEAN", tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, "FALSE"], CopyFunctionList[constantFunctions], CopyTables[tables]]
;
for Constant.id: AbstractProduction [identifier]
let GetCARDINAL[tree, tables] ← GetCARDINAL[value, tables1]
where < constantType, constantTree, value, tables1 > ← GetConstantType[identifier, tables]
let Coerce[tree, typeCtype, typeTypeName, tables] ← tables1
where match ←
if Equal[typeTypeName, constantTypeName]
then 0
else CompareTypes[typeCtype, ConstantCType, tables1]
where < constantTypeName, ConstantCType, value, tables1 > ←
if NotEnumeration[typeCtype]
then GetConstantType[identifier, tables]
else <
Copy[typeTypeName, typeCtype, tree, tables]
where junk ← IsEnumerationConstant[typeCtype, identifier]
>
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← AddLocalConstantToRope[identifier, constantName, constantType, constantFunctions, invalue, tables]
Add the Functions associated with identifier to constantFunctions -- Done In AddLocalConstantToRope
Add the Functions associated with identifier to CondensedFunctionTable -- Done In AddLocalConstantToRope
;
for Constant.negativeNumber: AbstractProduction [number]
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found Negative Number"], CopyTables[tables] >
let Coerce[tree, ctype, typeName, tables] ← tables1
where okay ← TryToCoerceNumber[ctype, value]
where < value, tables1 > ← GetCARDINAL[number, tables]
where junk ← SeeIfInt[ctype]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, addedValue], CopyFunctionList[constantFunctions], CopyTables[tables]]
where addedValue ← Concat["-", RopeFromCard[NumberToCard[number]]]
;
for Constant.number: AbstractProduction [number]
let GetCARDINAL[tree, tables] ← GetCARDINAL[number, tables]
let Coerce[tree, ctype, typeName, tables] ← tables1
where okay ← TryToCoerceNumber[ctype, value]
where < value, tables1 > ← GetCARDINAL[number, tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, addedValue], CopyFunctionList[constantFunctions], CopyTables[tables]]
where addedValue ← RopeFromCard[NumberToCard[number]]
;
for Constant.remoteReference: AbstractProduction [identifier.left, identifier.right]
let GetCARDINAL[tree, tables] ← GetCARDINAL[value, tables]
where value ← ValueToConstant[DirectoryEntry]
where constantType ← ValueToRope[DirectoryEntry]
where okay ← if successful
then 0
else int[SendError["Undeclared Remote Identifier"]]
where < successful, DirectoryEntry > ← Fetch[remoteDirectory, CreateKey[identifier.right]]
where remoteDirectory ← FetchFromGlobalTable[tables, CreateKey[identifier.left]]
let Coerce[tree, typeCtype, typeTypeName, tables] ← CopyTables[tables]
where match ← if Equal[typeTypeName, constantTypeName]
then 0
else CompareTypes[ConstantCType, typeCtype, tables]
where value ← ValueToConstant[DirectoryEntry]
where ConstantCType ← FetchFromTypeTable[tables, constantTypeName]
where constantTypeName ← ValueToRope[DirectoryEntry]
where < successful2, DirectoryEntry > ← Fetch[remoteDirectory, CreateKey[identifier.right]]
where remoteDirectory ← FetchFromGlobalTable[tables, CreateKey[identifier.left]]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[ValueToRopeConstant[DirectoryEntry, invalue], constantFunctions1, tables1]
Add the Functions associated with DirectoryEntry to constantFunctions -- Done
where constantFunctions1 ← AddFunctionList[DirectoryEntry, constantFunctions]
Add the Functions associated with DirectoryEntry to CondensedFunctionTable -- Done
where tables1 ← AddFunctionToTable[DirectoryEntry, constantFunctions, tables]
where < successful2, DirectoryEntry > ← Fetch[remoteDirectory, CreateKey[identifier.right]]
where remoteDirectory ← FetchFromGlobalTable[tables, CreateKey[identifier.left]]
;
for Constant.string: AbstractProduction [Rope]
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found String"], CopyTables[tables] >
let Coerce[tree, type, canonicalType, tables] ← CheckCanonicalType[canonicalType, "STRING", tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, RopeTokenToROPE[Rope]], CopyFunctionList[constantFunctions], CopyTables[tables]]
;
for Constant.true: AbstractProduction []
let GetCARDINAL[tree, tables] ← < SendError["Expected CARDINAL found Boolean"], CopyTables[tables] >
let Coerce[tree, type, typeTypeName, tables] ← CheckCanonicalType[typeTypeName, "BOOLEAN", tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, "TRUE"], CopyFunctionList[constantFunctions], CopyTables[tables]]
;
for Constant.unbounded: AbstractProduction []
let GetCARDINAL[tree, tables] ← < card[65536], CopyTables[tables] >
let Coerce[tree, type, canonicalType, tables] ← CheckCanonicalType[canonicalType, "UNBOUNDED", tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, invalue, tables] ← CopyAll[Concat[invalue, "65536"], CopyFunctionList[constantFunctions], CopyTables[tables]]
;
ElementList: AbstractType [CoerceElementList, ConstantToRope, Size, ConstructFunction];
for ElementList.one: AbstractProduction [Constant]
let CoerceElementList[tree, cType, ctypeName, tables] ← Coerce[Constant, cType, ctypeName, tables]
let Size[tree, numberOfElementInList] ← AddOne[numberOfElementInList]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← ConstantToRope[Constant, constantName, constantType, constantFunctions, constantValue, tables]
let ConstructFunction[tree, ElementNo, functionSoFar, constantName, constantType, constantFunctions, tables] ← CopyAll[Cat[functionSoFar, variable, value], constantFunctions1, tables1]
where value ← Concat[value1, ";\n"]
where < value1, constantFunctions1, tables1 > ← ConstantToRope[Constant, constantName, constantType, constantFunctions, "", tables]
where variable ← Cat["temp[", RopeFromInt[ElementNo], "] ←"]
;
for ElementList.more: AbstractProduction [Constant, ElementList]
let CoerceElementList[tree, cType, ctypeName, tables] ← CoerceElementList[ElementList, cType, ctypeName, tables1]
where tables1 ← Coerce[Constant, cType, ctypeName, tables]
let Size[tree, numberOfElementInList] ← Size[ElementList, AddOne[numberOfElementInList]]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← ConstantToRope[ElementList, constantName, constantType, constantFunctions1, rope2, tables1]
where rope2 ← Concat[rope1, ", "]
where < rope1, constantFunctions1, tables1 > ← ConstantToRope[Constant, constantName, constantType, constantFunctions, constantValue, tables]
let ConstructFunction[tree, ElementNo, functionSoFar, constantName, TypeOfElement, constantFunctions, tables] ←
ConstructFunction[ElementList, AddOne[ElementNo], functionSoFar1, constantName, TypeOfElement, constantFunctions1, tables1]
where functionSoFar1 ← Cat[functionSoFar, variable, value]
where value ← Concat[value1, ";\n"]
where < value1, constantFunctions1, tables1 > ← ConstantToRope[Constant, constantName, TypeOfElement, constantFunctions, "", tables]
where variable ← Cat["temp[", RopeFromInt[ElementNo], "] ←"]
;
ComponentList: AbstractType [CoerceComponents, ConstantToRope, CheckAllNames];
for ComponentList.one: AbstractProduction [Component]
let CoerceComponents[tree, cComponent, tables] ← CoerceComponents[Component, cComponent, tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← ConstantToRope[Component, constantName, constantType, constantFunctions, constantValue, tables]
let CheckAllNames[tree, tables] ← CheckAllNames[Component, tables]
;
for ComponentList.more: AbstractProduction [Component, ComponentList]
let CoerceComponents[tree, cComponent, tables] ← CoerceComponents[ComponentList, cComponent, tables1]
where tables1 ← CoerceComponents[Component, cComponent, tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← ConstantToRope[ComponentList, constantName, constantType, constantFunctions1, rope1, tables1]
where rope1 ← Concat[rope2, ", "]
where < rope2, constantFunctions1, tables1 > ← ConstantToRope[Component, constantName, constantType, constantFunctions, constantValue, tables]
let CheckAllNames[tree, tables] ← CheckAllNames[ComponentList, CheckAllNames[Component, tables]]
;
Component: AbstractType [CoerceComponents, ConstantToRope, CheckAllNames];
for Component: AbstractProduction [NameList, Constant]
let CoerceComponents[tree, cComponent, tables] ← CoerceComponentNameList[NameList, Constant, cComponent, tables]
let ConstantToRope[tree, constantName, constantType, constantFunctions, constantValue, tables] ← CopyAll[NameListToRope[NameList, constantValue, rope0, tables1], constantFunctions1, tables1]
where < rope0, constantFunctions1, tables1 > ← ConstantToRope[Constant, constantName, constantType1, constantFunctions, "", tables]
where constantType1 ← TypeOfNameList[NameList, constantType, tables]
let CheckAllNames[tree, tables] ← EmptyWorkTableOfNames[NameList, tables]
;
NameList: AbstractType [CheckIfErrorNames, CanonicaliseFieldsFromNameList, CoerceComponentNameList, NameListToRope, EmptyWorkTableOfNames, TypeOfNameList];
for NameList.empty: AbstractProduction []
let CheckIfErrorNames[tree, tables] ← CopyTables[tables]
let CanonicaliseFieldsFromNameList[tree, cName, cComponentArg, tables] ← < MkNILCComponent[], CopyTables[tables] >
let CoerceComponentNameList[tree, constant, cComponent, tables] ← CopyTables[tables]
let NameListToRope[tree, invalue, constantRope, tables] ← CopyRope[invalue]
let EmptyWorkTableOfNames[tree, tables] ← CopyTables[tables]
let TypeOfNameList[tree, constantType, tables] ← CopyRope[constantType] -- Should Yield Error
;
for NameList.one: AbstractProduction [identifier]
let CheckIfErrorNames[tree, tables] ← InsureErrorType[identifier, tables]
let CanonicaliseFieldsFromNameList[tree, cName, cComponentArg, tables] ← < cComponentres, CopyTables[tables] >
where cComponentres ← MkCComponent[CreateKey[identifier], 0, cName, cComponentArg]
let CoerceComponentNameList[tree, constant, cComponent, tables] ← Coerce[constant, cType, ctypeName, tables]
where < cType, ctypeName > ← GetCType[identifier, cComponent, tables]
let NameListToRope[tree, invalue, constantRope, tables] ← Cat[rope1, ": ", constantRope]
where rope1 ← Concat[invalue, CreateKey[identifier]]
let EmptyWorkTableOfNames[tree, tables] ← Remove[identifier, tables]
let TypeOfNameList[tree, constantType, tables] ← GetTypeOfComponent[identifier, constantType, tables]
;
for NameList.more: AbstractProduction [identifier, NameList]
let CheckIfErrorNames[tree, tables] ← CheckIfErrorNames[NameList, tables1]
where tables1 ← InsureErrorType[identifier, tables]
let CanonicaliseFieldsFromNameList[tree, cName, cComponentArg, tables] ← < cComponentres, CopyTables[tables1] >
where cComponentres ← MkCComponent[CreateKey[identifier], 0, cName, cComponent1]
where < cComponent1, tables1 > ← CanonicaliseFieldsFromNameList[NameList, cName, cComponentArg, tables]
let CoerceComponentNameList[tree, constant, cComponent, tables] ← tables2
where tables2 ← CoerceComponentNameList[NameList, constant, cComponent, tables1]
where tables1 ← Coerce[constant, cType, ctypeName, tables]
where < cType, ctypeName > ← GetCType[identifier, cComponent, tables]
let NameListToRope[tree, invalue, constantRope, tables] ← NameListToRope[NameList, rope3, constantRope, tables]
where rope3 ← Concat[rope2, ", "]
where rope2 ← Cat[rope1, ": ", constantRope]
where rope1 ← Concat[invalue, CreateKey[identifier]]
let EmptyWorkTableOfNames[tree, tables] ← EmptyWorkTableOfNames[NameList, Remove[identifier, tables]]
let TypeOfNameList[tree, constantType, tables] ← GetTypeOfComponent[identifier, constantType, tables]
;
number: AbstractType [GetCARDINAL, NumberToCard];
for number.decimal: AbstractProduction [numberD]
let GetCARDINAL[tree, tables] ← < GetCardFromDecimal[numberD], CopyTables[tables] >
let NumberToCard[tree] ← GetCardFromDecimal[numberD]
;
for number.hex: AbstractProduction [numberH]
let GetCARDINAL[tree, tables] ← < GetCardFromHex[numberH], CopyTables[tables] >
let NumberToCard[tree] ← GetCardFromHex[numberH]
;
for number.octal: AbstractProduction [numberO]
let GetCARDINAL[tree, tables] ← < GetCardFromOctal[numberO], CopyTables[tables] >
let NumberToCard[tree] ← GetCardFromOctal[numberO]
;
End;
ConcreteSyntax: Module = Begin
Simple Tokens
{
"ARRAY"
"BEGIN"
"BOOLEAN"
"CARDINAL"
"CHOICE"
"DEPENDS"
"END"
"ERROR"
"FALSE"
"INTEGER"
"LONG"
"OF"
"PROCEDURE"
"PROGRAM"
"RECORD"
"REPORTS"
"RETURNS"
"SEQUENCE"
"SINK"
"SOURCE"
"STRING"
"TRUE"
"TYPE"
"UNSPECIFIED"
"UPON"
"VERSION"
}: SimpleTokens;
{
"(" ")"
"[" "]"
"{" "}"
":"
"."
";"
"="
"=>"
","
"-"
}: SimpleTokens;
The Courier Program in Question:
OuterProgram: NonTerminal Builds Program;
for OuterProgram ← Program "."
Build Program;
Program: NonTerminal Builds Program;
for Program ← identifier ":" "PROGRAM" numberD.a "VERSION" numberD.b "="
"BEGIN" DependencyList DeclarationList "END"
Build Program[identifier, numberD.a, numberD.b, DependencyList, DeclarationList];
DependencyList: NonTerminal Builds ReferencedProgramList;
for DependencyList.empty ←
Build ReferencedProgramList.empty[];
for DependencyList.more← "DEPENDS" "UPON" ReferencedProgramList ";"
Build ReferencedProgramList;
ReferencedProgramList: NonTerminal Builds ReferencedProgramList;
for ReferencedProgramList.one ← ReferencedProgram
Build ReferencedProgramList.more[ReferencedProgramList.empty[[ReferencedProgram,
ReferencedProgram)], ReferencedProgram];
for ReferencedProgramList.more ← ReferencedProgramList "," ReferencedProgram
Build ReferencedProgramList.more[ReferencedProgramList, ReferencedProgram];
ReferencedProgram: NonTerminal Builds ReferencedProgram;
for ReferencedProgram ← identifier "(" numberD.a ")" "VERSION" numberD.b
Build ReferencedProgram[identifier, numberD.a, numberD.b];
DeclarationList: NonTerminal Builds DeclarationList;
for DeclarationList.a ←
Build DeclarationList.empty[];
for DeclarationList .b← DeclarationList Declaration
Build DeclarationList.more[DeclarationList, Declaration];
Declaration: NonTerminal Builds Declaration;
for Declaration.type ← identifier ":" "TYPE" "=" Type";"
Build Declaration.type[identifier, Type];
for Declaration.constant ← identifier ":" Type "=" Constant ";"
Build Declaration.constant[identifier, Type, Constant];
for Declaration.id ← identifier.name ":" Type "=" identifier.constant ";"
Build Declaration.constant[identifier.name, Type, Constant.id[identifier.constant]];
Type Declaration
Type: NonTerminal Builds Type;
for Type.simple ← SimpleType
Build SimpleType;
for Type.ConstructedType ← ConstructedType
Build ConstructedType;
SimpleType: NonTerminal Builds Type;
for SimpleType.predefinedType ← PredefinedType
Build PredefinedType;
for SimpleType.referencedType ← ReferencedType
Build ReferencedType;
PredefinedType: NonTerminal Builds Type;
for PredefinedType.boolean ← "BOOLEAN"
Build Type.boolean[];
for PredefinedType.Cardinal ← "CARDINAL"
Build Type.cardinal[];
for PredefinedType.longCardinal ← "LONG" "CARDINAL"
Build Type.longCardinal[];
for PredefinedType.integer← "INTEGER"
Build Type.integer[];
for PredefinedType.longInteger ← "LONG" "INTEGER"
Build Type.longInteger[];
for PredefinedType.string ← "STRING"
Build Type.string[];
for PredefinedType.unspecified ← "UNSPECIFIED"
Build Type.unspecified[];
for PredefinedType.bulkDataSource ← "SOURCE"
Build Type.bulkDataSource[];
for PredefinedType.bulkDataSink ← "SINK"
Build Type.bulkDataSink[];
ConstructedType: NonTerminal Builds Type;
for ConstructedType.enumeration ← "{" CorrespondenceList "}"
Build Type.enumeration[CorrespondenceList];
for ConstructedType.array ← "ARRAY" MandatoryNumber "OF" SimpleType
Build Type.array[MandatoryNumber, SimpleType];
for ConstructedType.sequence ← "SEQUENCE" OptionalNumber "OF" SimpleType
Build Type.sequence[OptionalNumber, SimpleType]; --Can be empty
for ConstructedType.record ← "RECORD" "[" FieldList"]"
Build Type.record[FieldList];
for ConstructedType.emptyRecord ← "RECORD" "[" "]"
Build Type.emptyRecord[];
for ConstructedType.choice ← "CHOICE" ReferencedType "OF" "{" CandidateList "}"
Build Type.choice[ReferencedType, CandidateList];
for ConstructedType.procedure ← "PROCEDURE" ArgumentList ResultList ErrorList
Build Type.procedure[ArgumentList, ResultList, ErrorList];
for ConstructedType.error ← "ERROR" ArgumentList
Build Type.error[ArgumentList];
ReferencedType: NonTerminal Builds Type;
for ReferencedType.localReference ← identifier
Build Type.localReference[identifier];
for ReferencedType.remoteReference ← identifier.remote "." identifier.id
Build Type.remoteReference[identifier.remote, identifier.id];
CorrespondenceList: NonTerminal Builds CorrespondenceList;
for CorrespondenceList.one ← Correspondence
Build Correspondence;
for CorrespondenceList.more ← Correspondence "," CorrespondenceList
Build CorrespondenceList.more[Correspondence, CorrespondenceList];
Correspondence: NonTerminal Builds CorrespondenceList;
for Correspondence ← identifier "(" MandatoryNumber ")"
Build CorrespondenceList.one[identifier, MandatoryNumber];
OptionalNumber: NonTerminal Builds Constant;
for OptionalNumber.nonEmpty ← Constant
Build Constant;
for OptionalNumber.localReference ← identifier
Build Constant.id[identifier];
for OptionalNumber.empty ←
Build Constant.unbounded[];
MandatoryNumber: NonTerminal Builds Constant;
for MandatoryNumber.value ← Constant
Build Constant;
for MandatoryNumber.localReference ← identifier
Build Constant.id[identifier];
CandidateList: NonTerminal Builds CandidateList;
for CandidateList.one ← Candidate
Build Candidate;
for CandidateList.more ← Candidate "," CandidateList
Build CandidateList.more[Candidate, CandidateList];
Candidate: NonTerminal Builds CandidateList;
for Candidate.one ← NameList "=>" SimpleType
Build CandidateList.one[NameList, SimpleType];
for Candidate.two ← NameList "(" number ")" "=>" SimpleType
Build CandidateList.one[NameList, SimpleType];
ArgumentList: NonTerminal Builds FieldList;
for ArgumentList.a ←
Build FieldList.empty[];
for ArgumentList.b ← "[" FieldList "]"
Build FieldList;
for ArgumentList.c ← "[" "]"
Build FieldList.empty[];
ResultList: NonTerminal Builds FieldList;
for ResultList.a ←
Build FieldList.empty[];
for ResultList.b ← "RETURNS" "[" FieldList "]"
Build FieldList;
for ResultList.c ← "RETURNS" "[" "]"
Build FieldList.empty[];
ErrorList: NonTerminal Builds NameList;
for ErrorList.a ←
Build NameList.empty[];
for ErrorList.b ← "REPORTS" "[" NameList "]"
Build NameList;
FieldList: NonTerminal Builds FieldList;
for FieldList.a ← Field
Build FieldList.more[Field, FieldList.empty[[Field, Field)]];
for FieldList.b ← Field "," FieldList
Build FieldList.more[Field, FieldList];
Field: NonTerminal Builds FieldList;
for Field ← NameList ":" SimpleType
Build FieldList.one[NameList, SimpleType];
Constant
Constant: NonTerminal Builds Constant;
for Constant.predefined ← PredefinedConstant
Build PredefinedConstant;
for Constant.constructed ← ConstructedConstant
Build ConstructedConstant;
for Constant.choiceConstant ← identifier Constant
Build Constant.choice[identifier, Constant];
for Constant.choiceIdentifier ← identifier.first identifier.next
Build Constant.choice[identifier.first, Constant.id[identifier.next]];
for Constant.remoteReference ← identifier.left "." identifier.right
Build Constant.remoteReference[identifier.left, identifier.right];
RefConst (id.id) as well as id id ... id.id
PredefinedConstant: NonTerminal Builds Constant;
for PredefinedConstant.true ← "TRUE"
Build Constant.true[];
for PredefinedConstant.false ← "FALSE"
Build Constant.false[];
for PredefinedConstant.number ← number
Build Constant.number[number];
for PredefinedConstant.negativeNumber ← "-" number
Build Constant.negativeNumber[number];
for PredefinedConstant.string ← Rope
Build Constant.string[Rope];
ConstructedConstant: NonTerminal Builds Constant;
for ConstructedConstant.elementList ← "[" ElementList "]"
Build Constant.elementList[ElementList];
for ConstructedConstant.componentlist ← "[" ComponentList "]"
Build Constant.componentlist[ComponentList];
for ConstructedConstant.empty ← "[" "]"
Build Constant.empty[];
ElementList: NonTerminal Builds ElementList;
for ElementList.one ← Constant
Build ElementList.one[Constant];
for ElementList.more ← Constant "," ElementList
Build ElementList.more[Constant, ElementList];
for ElementList.id ← identifier
Build ElementList.one[Constant.id[identifier]];
for ElementList.idAndMore ← identifier "," ElementList
Build ElementList.more[Constant.id[identifier], ElementList];
ComponentList: NonTerminal Builds ComponentList;
for ComponentList.one ← Component
Build ComponentList.one[Component];
for ComponentList.more ← Component "," ComponentList
Build ComponentList.more[Component, ComponentList];
Component: NonTerminal Builds Component;
for Component.more ← NameList ":" Constant
Build Component[NameList, Constant];
for Component.one ← NameList ":" identifier
Build Component[NameList, Constant.id[identifier]];
NameList: NonTerminal Builds NameList;
for NameList.one ← identifier
Build NameList.one[identifier];
for NameList.more ← identifier "," NameList
Build NameList.more[identifier, NameList];
number: NonTerminal Builds number;
for number.a ← numberD
Build number.decimal[numberD];
for number.b ← numberO
Build number.octal[numberO];
for number.c ← numberH
Build number.hex[numberH]
End.