jackd5011

COMP3000 HLAL Parser

Aug 2nd, 2021 (edited)
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.56 KB | None | 0 0
  1. /*
  2.  * This file is part of COMP3000 high-level assembly language.
  3.  *
  4.  * Copyright (C) 2021 Kym Haines, Macquarie University.
  5.  *
  6.  * This Source Code Form is subject to the terms of the Mozilla Public
  7.  * License, v. 2.0. If a copy of the MPL was not distributed with this
  8.  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9.  */
  10.  
  11. package org.mq.hasm
  12.  
  13. /**
  14. * The top level object of the application.
  15. */
  16. object Main {
  17.  
  18.     import Instr._
  19.  
  20.     import scala.io.Source
  21.     import scala.collection.mutable.ListBuffer
  22.  
  23.     /**
  24.     * Main entry point of the application.
  25.     *
  26.     * @param args the array of options and parameters passed on
  27.     * the command line.
  28.     */
  29.     def main(args: Array[String]) {
  30.         // open file to read lines
  31.         val lines = Source.fromFile("main.hlal")
  32.         var srcBuf = new ListBuffer[Txt]()
  33.  
  34.         // read each line and append to the list
  35.         for(line <- lines.getLines())
  36.             srcBuf += Txt(line)
  37.  
  38.         // close file and finalise lines
  39.         lines.close()
  40.         val src = srcBuf.toList
  41.  
  42.         setHeapSize(100)
  43.         setStackSize(100)
  44.  
  45.         displayQuadInstr(assignAddresses(src))
  46.  
  47.         if(symbolsNotFound.size > 0)
  48.         {
  49.         println("Symbols not found:")
  50.         symbolsNotFound foreach println
  51.         return
  52.         }
  53.         if(!loadMemory()) return
  54.         trace = false // set to true for tracing information
  55.         displayMemory
  56.         exec(1000)    // allow at most 1000 instructions to be executed
  57.         displayRegisters
  58.         displayMemory
  59.     }
  60. }
  61.  
Add Comment
Please, Sign In to add comment