/** * Parses a single modify record. * * @param rec the modify record to be parsed * @param mod the module this text record will be a part of * * @refcode * OB4 * @errtest * @errmsg * EW.15, EW.16, EW.17, ES.24, ES.25, ES.26, ES.27, ES.28, ES.29, ES.30, ES.31, ES.32 * @author Mark Mathis * @creation May 19, 2011 * @modlog * @teststandard Andrew Buelow * @codestandard Mark Mathis */ public void ParseModify(string rec, Module mod) { string[] field = rec.Split(':'); Modify modRecord = new Modify(); // check the location string loc = field[1]; // check the length of the location if (loc.Length != 4) { // error, incorrect length errPrinter.PrintError(ErrCat.Warning, 15); } // check that it is a valid hex string int locVal = 0; try { locVal = Convert.ToInt32(loc, 16); } catch (FormatException) { // error, not valid hex throw new Error(ErrCat.Serious, 24); } // check that the location value is in the proper range if (locVal < 0 || locVal > 1023) { // error, location invalid throw new Error(ErrCat.Serious, 25); } // add location to the linker modification record modRecord.Location = locVal; // check the hex code of the word string hex = field[2]; // check the length of the hex code if (hex.Length < 4) { // error, too short errPrinter.PrintError(ErrCat.Warning, 16); } else if (hex.Length > 4) { // error, too long throw new Error(ErrCat.Serious, 26); } // check that it is a valid hex string int hexVal = 0; try { hexVal = Convert.ToInt32(hex, 16); } catch (FormatException) { // error, not valid hex throw new Error(ErrCat.Serious, 27); } // add the hex code of the word to be modified to the linker modification record modRecord.Word = hexVal; /* Regular expression used to determine if all characters in the token are * letters or numbers. */ Regex alphaNumeric = new Regex(@"[^0-9a-zA-Z]"); // go through the modifications and make sure they are formatted correctly string sign = field[3]; // check that sign is a + or - if (!(sign == "+" || sign == "-")) { // error, sign must be a + or - throw new Error(ErrCat.Serious, 28); } int i = 4; while (sign == "+" || sign == "-") { string label = field[i++]; // check that label is valid label if (2 <= label.Length && label.Length <= 32) { if (!(!alphaNumeric.IsMatch(label) && char.IsLetter(label[0]))) { // label is not a valid label errPrinter.PrintError(ErrCat.Serious, 29); } } else { // label is not the right length errPrinter.PrintError(ErrCat.Serious, 29); } // add adjustments to the linker modification record modRecord.AddAdjustments(sign, label); // get next sign try { sign = field[i++]; } catch (IndexOutOfRangeException) { throw new Error(ErrCat.Serious, 32); } } // reached end of modification record, or there was an error // in the format of modifications // check that label is valid label if (2 <= sign.Length && sign.Length <= 32) { if (!(!alphaNumeric.IsMatch(sign) && char.IsLetter(sign[0]))) { // label is not a valid label errPrinter.PrintError(ErrCat.Serious, 29); } } else { // label is not the right length errPrinter.PrintError(ErrCat.Serious, 29); } // check if the label is in the symbol table // if it is, it's probably not an error // if it isn't, it could be an error: say something about it if (mod.ModuleName != sign) { // error, program name at the end of modification record must match // program name of program being parsed throw new Error(ErrCat.Serious, 30); } if (!symb.ContainsSymbol(sign)) { // error, something isn't in the symbol table throw new Error(ErrCat.Serious, 31); } //check to see that the modify record doesn't have too many adjustments if (modRecord.Adjustments.Count > 15) { // error, can only have 15 adjustments in a modify record errPrinter.PrintError(ErrCat.Warning, 17); } // add modification record to module mod.AddRecord(modRecord); }
/** * Parses a single text record. * * @param rec the text record to be parsed * @param mod the module this text record will be a part of * * @refcode * OB3 * @errtest * @errmsg * EW.11, EW.12, EW.13, EW.14, ES.16, ES.17, ES.18, ES.19, ES.20, ES.21, ES.22, ES.23 * @author Mark Mathis * @creation May 19, 2011 * @modlog * @teststandard Andrew Buelow * @codestandard Mark Mathis */ public void ParseText(string rec, Module mod) { string[] field = rec.Split(':'); Text textRecord = new Text(); // check that the record has the correct number of fields if (field.Length != 6) { // error, wrong number of fields throw new Error(ErrCat.Serious, 16); } // check program assigned location string progLoc = field[1].ToUpper(); // check length, should be 4 digit hex number if (progLoc.Length != 4) { // error, wrong length errPrinter.PrintError(ErrCat.Warning, 11); } //check that it is valid hex int progLocVal = 0; try { progLocVal = Convert.ToInt32(progLoc, 16); } catch (FormatException) { // error, not valid hex errPrinter.PrintError(ErrCat.Serious, 17); } // check that it is in the correct range if (progLocVal < 0 || progLocVal > 1023) { // error, must be between 0 and 1023 errPrinter.PrintError(ErrCat.Serious, 18); } // add program location to the linker text record textRecord.Location = progLocVal; // check the hex code of the instruction string hexCode = field[2].ToUpper(); // check length, should be 4 digit hex number if (hexCode.Length < 4) { // error, too short errPrinter.PrintError(ErrCat.Warning, 12); } else if (hexCode.Length > 4) { // error, too long errPrinter.PrintError(ErrCat.Serious, 19); hexCode = "8000"; } //check that it is valid hex int hexCodeVal = 0; try { hexCodeVal = Convert.ToInt32(hexCode, 16); } catch (FormatException) { // error, not valid hex errPrinter.PrintError(ErrCat.Serious, 20); hexCodeVal = Convert.ToInt32("8000", 16); } // add hex code of instruction to linker text record textRecord.Word = hexCodeVal; // check address status flag string addStatus = field[3].ToUpper(); // check length of flag, should be 1 if (addStatus.Length != 1) { // error wrong length errPrinter.PrintError(ErrCat.Serious, 21); addStatus = "A"; } // check that the flag is a valid value if (!(addStatus[0] == 'A' || addStatus[0] == 'R' || addStatus[0] == 'M')) { // error, invalid value for status flag errPrinter.PrintError(ErrCat.Serious, 21); addStatus = "A"; } // add status flag to linker text record textRecord.Flag = addStatus[0]; // check number of M adjustments needed string mAdj = field[4].ToUpper(); // check that it is the correct length, should be 1 if (mAdj.Length != 1) { // error wrong length errPrinter.PrintError(ErrCat.Warning, 13); mAdj = "1"; } // check that it is valid hex int mAdjVal = 0; try { mAdjVal = Convert.ToInt32(mAdj, 16); } catch (FormatException) { // error, not valid hex errPrinter.PrintError(ErrCat.Warning, 14); mAdjVal = 1; } // if it's valid then it should be in the correct range // since one hex digit can only be 0-15 // add number of adjustments to the linker text record textRecord.Adjustments = mAdjVal; // check the program name string prgmName = field[5]; // check that the program name is in the symbol table if (mod.ModuleName != prgmName) { // error, program name at end of text record must match // program name of program being parsed throw new Error(ErrCat.Serious, 22); } if (!symb.ContainsSymbol(prgmName)) { // error, program name is not in symbol table throw new Error(ErrCat.Serious, 23); } mod.AddRecord(textRecord); }
/** * Parses a single linking record. * * @param rec the linking record to be parsed * @param mod the module this linking record will be a part of * * @refcode * OB2 * @errtest * @errmsg * EW.10, ES.09, ES.10, ES.11, ES.12, ES.13, ES.14, ES.15 * @author Mark Mathis * @creation May 19, 2011 * @modlog * @teststandard Andrew Buelow * @codestandard Mark Mathis */ public void ParseLink(string rec, Module mod) { string[] field = rec.Split(':'); Linking linkRecord = new Linking(); // check if record has the correct number of fields if (field.Length != 4) { // error, wrong number of fields errPrinter.PrintError(ErrCat.Serious, 9); } // check that Entry name is valid string entry = field[1]; /* Regular expression used to determine if all characters in the token are * letters or numbers. */ Regex alphaNumeric = new Regex(@"[^0-9a-zA-Z]"); if (2 <= entry.Length && entry.Length <= 32) { if (!(!alphaNumeric.IsMatch(entry) && char.IsLetter(entry[0]))) { // entry name is not a valid label errPrinter.PrintError(ErrCat.Serious, 10); } } else { // entry name is not the right length errPrinter.PrintError(ErrCat.Serious, 10); } // add entry name to linker linking record linkRecord.EntryName = entry; // get the location within the program string prgmLoc = field[2].ToUpper(); // check length, should be 4 digit hex number if (prgmLoc.Length != 4) { // error, wrong length errPrinter.PrintError(ErrCat.Warning, 10); } //check that it is valid hex int prgmLocVal = 0; try { prgmLocVal = Convert.ToInt32(prgmLoc, 16); } catch (FormatException) { // error, not valid hex throw new Error(ErrCat.Serious, 11); } // check that it is in the correct range if (prgmLocVal < 0 || prgmLocVal > 1023) { // error, must be between 0 and 1023 errPrinter.PrintError(ErrCat.Serious, 12); } // add location to linking header record linkRecord.Location = prgmLocVal; // make sure the program name is properly formatted // and in the symbol table string pgmName = field[3]; if (2 <= pgmName.Length && pgmName.Length <= 32) { if (!(!alphaNumeric.IsMatch(pgmName) && char.IsLetter(pgmName[0]))) { // program name is not a valid label throw new Error(ErrCat.Serious, 13); } } else { // program name is not the right length throw new Error(ErrCat.Serious, 13); } // check that program name is in symbol table if (mod.ModuleName != pgmName) { // error, program name at end of linking record must match program name // of program being parsed throw new Error(ErrCat.Serious, 14); } if (!symb.ContainsSymbol(pgmName)) { // error, program name not in the symbol table errPrinter.PrintError(ErrCat.Serious, 15); } // add entry to symbol table mod.AddRecord(linkRecord); }