RiscAssemblerParser: Control Module;

RiscAssemblerToken: Module = Begin
{ "NOOP" "GOTO" ":" ";" "." } : SimpleTokens;

id: GenericToken = "tokenID";

End;

RiscAssemblerCG: Module = Begin

goal:	NonTerminal Builds Program;

for goal	_ program
Build	program;

program:	NonTerminal Builds Program;

for program.list	_ list "."
Build	Program.list[list];

list:	NonTerminal Builds List;

for list.statement	_ statement
Build	List.statement[statement]; 
for list.dangle	_ statement ";"
Build	List.dangle[statement]; 
for list.cons	_ statement ";" list
Build	List.cons[statement, list];

statement:	NonTerminal Builds Statement;

for statement.label	_ label ":" statement
Build	Statement.label[label, statement];
for statement.op	_ op
Build	Statement.op[op];
for statement.oprand	_ op rand
Build	Statement.oprand[op, rand];

label:	NonTerminal Builds Label;

for label.id	_ id
Build	Label.id[id];

op:	NonTerminal Builds Op;

for op.noop	_ "NOOP"
Build	Op.noop[];
for op.goto	_ "GOTO"
Build	Op.goto[];

rand:	NonTerminal Builds Rand;

for rand.id	_ id
Build	Rand.id[id];

End;

RiscAssemblerAG: Module = Begin
Program.list:	AbstractProduction [ List ];

List.statement:	AbstractProduction [ Statement ];
List.dangle:	AbstractProduction [ Statement ];
List.cons:	AbstractProduction [ Statement, List ];

Statement.label:	AbstractProduction [ Label, Statement ];
Statement.op:	AbstractProduction [ Op ];
Statement.oprand:	AbstractProduction [ Op, Rand ];

Label.id:	AbstractProduction [ id ];

Op.noop:	AbstractProduction [  ];
Op.goto:	AbstractProduction [  ];

Rand.id:	AbstractProduction [ id ];

End;

RiscAssemblerDoit: Module = Begin
for Program.list:	AbstractProduction [ List ]
let Assemble[tree] _ < codeBody, symbolTable, nextAddress >
where codeBody _ CodeSequence[List, symbolTable]
where < symbolTable, nextAddress > _ SymbolTable[List, initialTable, initialAddress]
where initialAddress _ CodeOrigin[]
where initialTable _ InitialSymbolTable[]
;
for List.statement:	AbstractProduction [ Statement ]
let SymbolTable[tree, initialTable, initialAddress] _
SymbolTable[Statement, initialTable, initialAddress]
let CodeSequence[tree, symbolTable] _ CodeSequence[Statement, symbolTable]
;
for List.dangle:	AbstractProduction [ Statement ]
let SymbolTable[tree, initialTable, initialAddress] _
SymbolTable[Statement, initialTable, initialAddress]
let CodeSequence[tree, symbolTable] _ CodeSequence[Statement, symbolTable]
;
for List.cons:	AbstractProduction [ Statement, List ]
let SymbolTable[tree, initialTable, initialAddress] _
SymbolTable[List, newTable, nextAddress]
where < newTable, nextAddress> _ SymbolTable[Statement, initialTable, initialAddress]
let CodeSequence[tree, symbolTable] _ CodeConcat[first, rest]
where rest _ CodeSequence[List, symbolTable]
where first _ CodeSequence[Statement, symbolTable]
;
for Statement.label:	AbstractProduction [ Label, Statement ]
let SymbolTable[tree, initialTable, initialAddress] _ SymbolTable[Statement, newTable, nextAddress]
where newTable _ SymbolConcat[initialTable, entry]
where entry _ NotePosition[Label, initialAddress, definedAt]
where nextAddress _ Succ[initialAddress]
where definedAt _ SourcePosition[Label]
where len _ SourceLength[Label]
let CodeSequence[tree, symbolTable] _ CodeSequence[Statement, symbolTable]
;
for Statement.op:	AbstractProduction [ Op ]
let SymbolTable[tree, initialTable, initialAddress] _ < newTable, nextAddress >
where newTable _ SymbolCopy[initialTable]
where nextAddress _ Succ[initialAddress]
let CodeSequence[tree, symbolTable] _ InstructionSequence[segment]
where segment _ Instruction[Op]
;
for Statement.oprand:	AbstractProduction [ Op, Rand ]
let SymbolTable[tree, initialTable, initialAddress] _ < newTable, nextAddress >
where newTable _ SymbolCopy[initialTable]
where nextAddress _ Succ[initialAddress]
let CodeSequence[tree, symbolTable] _ InstructionSequence[segment]
where segment _ InstructionRand[Op, label]
where label _ Index[Rand, symbolTable]
;
for Label.id:	AbstractProduction [ id ]
let NotePosition[tree, address, definedAt] _ NewLabel[id, address, definedAt]
;
for Op.noop:	AbstractProduction [  ]
let Instruction[tree] _ Code[Opcode.noop]
let InstructionRand[tree, index] _ CodeRandFirewall[Opcode.noop, index]
;
for Op.goto:	AbstractProduction [  ]
let Instruction[tree] _ CodeFirewall[Opcode.goto]
let InstructionRand[tree, index] _ CodeRand[Opcode.goto, index]
;
for Rand.id:	AbstractProduction [ id ]
let Index[tree, symbolTable] _ SymbolIndex[symbolTable, id]
;

End;

RiscAssemblerAT: Module = Begin

Program:	AbstractType [ Assemble ];
List:	AbstractType [ SymbolTable, CodeSequence ];
Statement:	AbstractType [ SymbolTable, CodeSequence ];
Label:	AbstractType [ NotePosition ];
Op:	AbstractType [ Instruction, InstructionRand ];
Rand:	AbstractType [ Index ];

End;

RiscAssemblerTree: Module = Begin
Assemble:
TreeRecursiveFunction [ Tree ]
Returns [ EncodingSequence.program, Table.all, INT.nextAddress ];

SymbolTable:
TreeRecursiveFunction [ Tree, Table.old, INT.first ]
Returns [ Table.new, INT.next ];

NotePosition:
TreeRecursiveFunction [ Tree, INT.address, INT.definedAt ]
Returns [ LabelInstance.id ];

CodeSequence:
TreeRecursiveFunction [ Tree, Table ]
Returns [ EncodingSequence.list ];

Instruction:
TreeRecursiveFunction [ Tree ]
Returns [ Encoding.instr ];

InstructionRand:
TreeRecursiveFunction [ Tree, LabelInstance.id ]
Returns [ Encoding.instr ];

Index:
TreeRecursiveFunction [ Tree, Table ]
Returns [ LabelInstance.index ];

End;

RiscAssemblerBase: Module = Begin
INT:	CedarType;
ROPE:	CedarType From Rope;

LabelInstance:	CedarType From RiscAssembler;
Encoding:	CedarType From RiscAssembler;
EncodingSequence:	CedarType From RiscAssembler;
Table:	CedarType From RedBlackTree;

Succ:
CedarFunction [ INT.val ]
Returns [ INT.succ ]
From RiscAssembler;

Opcode: EnumeratedBaseType = { noop, goto };

CodeConcat:
BaseFunction [ EncodingSequence.left, EncodingSequence.right ]
Returns [ EncodingSequence.list ];

InstructionSequence:
BaseFunction [ Encoding.instr ]
Returns [ EncodingSequence.list ];

Code:
BaseFunction [ Opcode.op ]
Returns [ Encoding.instr ];

CodeFirewall:
BaseFunction [ Opcode.op ]
Returns [ Encoding.instr ];

CodeRand:
BaseFunction [ Opcode.op, LabelInstance.index ]
Returns [ Encoding.instr ];

CodeRandFirewall:
BaseFunction [ Opcode.op, LabelInstance.index ]
Returns [ Encoding.instr ];

SymbolCopy:
BaseFunction [ Table.old ]
Returns [ Table.new ]
SharedReps [ Table.old ];

SymbolConcat:
BaseFunction [ Table.old, LabelInstance.entry ]
Returns [ Table.new ]
SharedReps [ Table.old ];

CodeOrigin:
BaseFunction [ ]
Returns [ INT.origin ];

InitialSymbolTable:
BaseFunction [ ]
Returns [ Table.new ];

NewLabel:
BaseFunction [ id, INT.address, INT.definedAt ]
Returns [ LabelInstance.id ];

SymbolIndex:
BaseFunction [ Table, id.label ]
Returns [ LabelInstance.index ];

End.


����RiscAssembler.ThreeC4
Copyright Ó 1987 by Xerox Corporation.  All rights reserved.
Bill Jackson (bj) May 27, 1987 7:49:06 pm PDT
Lucy Hederman July 15, 1987 4:52:11 pm PDT
Tokens
Program: AbstractType[  ];
List: AbstractType[  ];
Statement: AbstractType[  ];
Label: AbstractType[  ];
Op: AbstractType[  ];
Rand: AbstractType[  ];
Program
List
We might want to issue a warning here about the null statement!
Statement
Label
There's a lie here in that the "initialTable" is being augmented with an entry for the new symbol which contains only the text, but that can be fixed later...
Op
Rand
Recursive Functions
the primary (synthesis) operation of the assembler, produces a code sequence, a symbol table, and the length of the code sequence (represented as start+len=last+1).  Note that this is a two pass operations where the symbol table is constructed in pass 1, and the code sequence is produced in pass 2 (where children recieve the symbol table as an inherited value).
the operation which produces values for symbols by synthesizing representations (virtual addresses in INT's) as values for symbolic labels
a noop which provides us with the ability to recognize positions of GenericTokens(id)
the gradual synthesis of the module/program via concatenation of Instruction Sequences.
the encoding of a primitive operation for the "machine".
the encoding of a primitive operation (with operand) for the "machine".
the virtual program counter for instructions.
Cedar Primitives
Base Functions
eof...
�Ê‡��•StyleDefÛBeginStyle
(cedar) AttachStyle
(codeTab30) (set up the fancy tabs) {code 30 mm flushLeft tabStop} StyleRule
(codeTab35) (set up the fancy tabs) {code 35 mm flushLeft tabStop} StyleRule
(codeTab40) (set up the fancy tabs) {code 40 mm flushLeft tabStop} StyleRule
(codeTab45) (set up the fancy tabs) {code 45 mm flushLeft tabStop} StyleRule
EndStyle˜�	codetab35™K™<Kšœ-™-Icode™*—K˜�KšÏnÏt˜$K˜�š
Ðbnœžœ˜"headšÏz™KšœÏsœ¡œÐizœ˜-K˜�Kšœ¢œ
˜K˜�—K˜K˜�—šœžœ˜K˜�	codetab45šÏbœ¢œ¢œ	˜!N˜�š¢œ˜Nš¢Ïiœ˜—N˜�—š£œ¢œ¢œ	˜$N˜�š¢œ˜Nš¢¤œ˜—N˜�—š£œ¢œ¢œ˜N˜�š¢œ˜Nš¢¤œ˜!—š¢œ˜Nš¢¤œ˜—š¢œ˜"Nš¢¤œ˜!—N˜�—š£	œ¢œ¢œ˜(N˜�š¢œ&˜)Nš¢¤œ"˜(—š¢œ˜Nš¢¤œ˜—š¢œ˜Nš¢¤œ˜!—N˜�—š£œ¢œ¢œ˜ N˜�š¢œ˜Nš¢¤œ
˜—N˜�—š£œ¢œ¢œ˜N˜�š¢œ¡œ˜Nš¢¤œ
˜—š¢œ¡œ˜Nš¢¤œ
˜—N˜�—š£œ¢œ¢œ˜K˜�š¢œ
˜Kš¢¤œ˜—K˜�—K˜K˜�—šœžœ˜š ™Nš£œ¢œ
˜*K˜�—š ™Nš£œ¢œ˜1Nš£œ¢œ˜.Nš£	œ¢œ˜2K˜�—šÐnz	 ™Nš£œ¢œ˜9Nš£œ¢œ˜(Nš£œ¢œ˜2K˜�—š ™Nš£œ¢œ˜$K˜�—š¥ ™Nš£œ¢œ˜!Nš£œ¢œ˜!K˜�—š¥ ™Nš£œ¢œ˜#K˜�—K˜K˜�—šœžœ˜!š ™š¢œ£œ¢œ	˜-š¢œ8˜;š¢œ+˜0š¢œO˜TNš¢œ˜#Nš¢œ$˜)———Nšœ˜——š ™š¢œ£œ¢œ˜4Nš¢œg˜jNš¢œG˜JNšœ˜—š¢œ£œ¢œ˜1Nš¢œg˜jNš¢œG˜JN™?Nšœ˜—š¢œ£	œ¢œ˜5š¢œ[˜^Nš¢œP˜U—š¢œ:˜=Nš¢œ'˜,Nš¢œ-˜2—N˜——š 	™	š¢œ£œ¢œ˜<š¢œ`˜cNš¢œ-˜2Nš¢œ7˜<Nš¢œ#˜(Nš¢œ"˜'Nš¢œ˜—Nš¢œG˜JNšœ˜—š¢œ£œ¢œ˜+š¢œL˜ONš¢œ$˜)Nš¢œ#˜(—š¢œ?˜BNš¢œ˜—Nšœ˜—š¢œ£œ¢œ
˜5š¢œL˜ONš¢œ$˜)Nš¢œ#˜(—š¢œ?˜Bš¢œ%˜*Nš¢œ!˜&——Nšœ˜——š ™š¢œ£œ¢œ˜'Nš¢œJ˜MNšœž™žNšœ˜——š ™š¢œ£œ¢œ˜$Nš¢œ&˜)Nš¢œD˜GNšœ˜—š¢œ£œ¢œ˜$Nš¢œ.˜1Nš¢œ<˜?Nšœ˜——š ™š¢œ£œ¢œ˜&Nš¢œ8˜;Nšœ˜N˜�——N˜N˜�—šœžœ˜N˜�Nš£œ¢œ˜#Nš£œ¢œ˜1Nš£	œ¢œ˜6NšŸœ¢œ˜%Nš£œ¢œ"˜2š£œ¢œ˜N˜�—N˜N˜�—šœžœ˜!š ™š£œ˜	Nš¢œ	˜Nš¢œÏkœ¦œ˜AN™ëN˜�—š£œ˜Nš¢œ¦œ˜4Nš¢œ¦œ˜ N™ŠN˜�—š£œ˜
Nš¢œ	¦œ
¦œ˜:Nš¢œ˜N™UN˜�—š£œ˜
Nš¢œ˜%Nš¢œ˜"NšœW™WN˜�—š£œ˜Nš¢œ	˜Nš¢œ˜Nšœ8™8N˜�—š£œ˜Nš¢œ˜0Nš¢œ˜NšœG™GN˜�—š£œ˜Nš¢œ˜%Nš¢œ˜ N™-——N˜�N˜N˜�—šœžœ˜!š ™Nš¦œ¢	œ˜Nš¦œ¢	œ¢œ˜N˜�Nš
œ¢	œ¢œ˜,Nšœ¢	œ¢œ˜'Nš£œ¢	œ¢œ˜/Nšœ¢	œ¢œ˜#N˜�š£œ˜Nš¢
œ¦œ˜Nš¢œ¦œ˜Nš¢œ˜——š ™N˜�Nš£œ¢œ˜,N˜�š£
œ˜Nš¢œ2˜>Nš¢œ˜"N˜�—š£œ˜Nš¢œ˜Nš¢œ˜"N˜�—š£œ˜Nš¢œ˜Nš¢œ˜N˜�—š£œ˜
Nš¢œ˜Nš¢œ˜N˜�—š£œ˜	Nš¢œ#˜/Nš¢œ˜N˜�—š£œ˜Nš¢œ#˜/Nš¢œ˜N˜�—š£
œ˜Nš¢œ˜Nš¢œ¦œ˜Nš¢
œ˜N˜�—š£œ˜
Nš¢œ#˜/Nš¢œ¦œ˜Nš¢
œ˜N˜�—š£
œ˜Nš¢œ˜Nš¢œ¦œ
˜N˜�—š£œ˜Nš¢œ˜Nš¢œ¦œ˜N˜�—š£œ˜	Nš¢œ¦œ
¦œ˜/Nš¢œ˜N˜�—š£œ˜Nš¢œ˜ Nš¢œ˜ N˜�——N˜—K˜�K™K˜�—�…—����Æ��,1��