/// <summary> /// Returns the index of the row where the data was place, just adds to end of list. /// </summary> /// <param name="name">String name of reserved word</param> /// <param name="code">Integer code of reserved word</param> /// <returns>index of the row where the data was placed</returns> public int Add(string name, int code) { ReservedWord reservedWord = new ReservedWord(name, code); ReserveTableData.Add(reservedWord); return(ReserveTableData.Count - 1); }
/// <summary> /// Returns the associated name if code is there, else an empty string /// </summary> /// <param name="code">Intger code of reserved word</param> /// <returns></returns> public string LookupCode(int code) { ReservedWord reservedWord = ReserveTableData.FirstOrDefault(x => x.Code == code); if (reservedWord == null) { return(""); } return(reservedWord.Name); }
/// <summary> /// Returns the code associated with name if name is in the table, else returns -1 /// </summary> /// <param name="name">String name of reserved word</param> /// <returns></returns> public int LookupName(string name) { ReservedWord reservedWord = ReserveTableData.FirstOrDefault(x => x.Name == name); if (reservedWord == null) { return(-1); } return(reservedWord.Code); }
/// <summary> /// Searches the table for the given code to test if it is valid. /// </summary> /// <param name="code">Integer code of reserved word</param> /// <returns>True if the code is valid, False if not.</returns> public bool isValidOpCode(int code) { ReservedWord reservedWord = ReserveTableData.FirstOrDefault(x => x.Code == code); if (reservedWord == null) { Console.WriteLine($"{code} is not a valid Op Code."); return(false); } return(true); }