<> <> <> <> 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] ; <