Example #1
0
 /**
  * Create an object file using the given inputs.
  *
  * @param input Input source from pass 1
  * @param symb The symbol table
  * @param report an assembly report to be generated
  * @refcode OB
  * @errtest
  *  N/A
  * @errmsg
  *  N/A
  * @author Jacob Peddicord
  * @creation May 10, 2011
  * @modlog
  * @teststandard Andrew Buelow
  * @codestandard Mark Mathis
  */
 public ObjectFile(ref IntermediateFile input, ref SymbolTable symb, ref AssemblyReport report)
 {
     this.input = input;
     this.symb = symb;
     this.report = report;
 }
Example #2
0
        /**
         * Parses an entire source code file.
         *
         * @param path the path of the source file to parse.
         * @param interSource resultant intermediate file from this source
         * @param symb resultant symbol table from this source
         *
         * @refcode N/A
         * @errtest
         *  N/A
         * @errmsg
         *  N/A
         * @author Mark Mathis
         * @creation April 8, 2011
         * @modlog
         *  - April 9, 2011 -  Mark - Parses entire source code file from a string.
         *  - April 9, 2011 -  Mark - Reads source file in from a file.
         *  - April 9, 2011 -  Mark - Catches exceptions possibly raised by reading the file.
         *  - April 9, 2011 - Jacob - Adds symbols to the symbol table. Changed the parameters to
         *      pass in an IntermediateFile and SymbolTable with an expected out value. Return type
         *      is now void.
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        public void ParseSource(string path, out IntermediateFile interSource, out SymbolTable symb)
        {
            string[] sourceCode = new string[1];
            try
            {
                Logger.Log("Opening file: " + path, "Parser");
                sourceCode = File.ReadAllLines(path);
            }
            catch (FileNotFoundException ex)
            {
                Logger.Log("Failed to open file. Error: " + ex.Message, "Parser");
                Console.WriteLine("{0}\n{1}", ex.Message, "Exiting program");
                System.Environment.Exit(1);
            }

            interSource = new IntermediateFile();
            symb = new SymbolTable();

            // first line is expected to hold the start directive
            IntermediateLine line = ParseLine(sourceCode[0], 1, ref symb);
            interSource.AddLine(line);
            if (line.Directive != null)
            {
                if (line.Directive.ToUpper() != "START")
                {
                    // file must start with a valid start directive
                    line.AddError(Errors.Category.Fatal, 2);
                    return;
                }
                else if (HasFatalError(line))
                {
                    return;
                }
            }
            else
            {
                line.AddError(Errors.Category.Fatal, 2);
                return;
            }

            bool reachedEnd = false;

            // iterate the lines of the file
            for (short i = 2; i <= sourceCode.Length; i++)
            {
                // parse a line and create an intermediate version
                line = ParseLine(sourceCode[i - 1].TrimEnd(), i, ref symb);

                // if we're at the end and processing another line
                if (reachedEnd)
                {
                    if (line.SourceLine.Length > 0)
                    line.AddError(Errors.Category.Fatal, 7);
                }

                // check the LC. at this point, the line will have incremented
                // already, so check if it's 1024 instead of 1023.
                if (Convert.ToInt32(Parser.LC, 16) > 1024)
                {
                    line.AddError(Errors.Category.Fatal, 3);
                }

                // add to source
                if (!reachedEnd || line.SourceLine.Length > 0)
                interSource.AddLine(line);

                // did we find le end?
                if (line.Directive == "END")
                {
                    reachedEnd = true;
                }

                // check for fatal errors
                if (HasFatalError(line))
                {
                    break;
                }
            }
        }