DCPU16_ASM.Assembler.Parser.Parse C# (CSharp) Метод

Parse() публичный Метод

public Parse ( string lines ) : ushort[]
lines string
Результат ushort[]
        public ushort[] Parse(string[] lines)
        {
            try
            {
                this.machineCode.Clear();
                this.labelReferences.Clear();
                this.MessageOuput = string.Empty;

                foreach (var line in lines)
                {
                    LineCounter++;

                    var currentLine = line.Trim();

                    if (currentLine.Length < 1 || line[0] == ';')
                    {
                        continue;
                    }

                    currentLine = this.RemoveLineComments(line);

                    if (currentLine.Trim().Length < 1)
                    {
                        continue;
                    }

                    this.AssembleLine(currentLine);
                }

                this.SetLabelAddressReferences();
                SetDataFieldLabelAddressReferences();

                var count = 1;

                foreach (var code in this.machineCode)
                {
                    this.AddMessage(string.Format("{0:X4} ", code));
                    count++;
                }
				
				this.MessageOuput = this.MessageOuput.Substring(0, this.MessageOuput.Length - 2);
				
                return this.machineCode.ToArray();
            }
            catch (Exception ex)
            {
                this.AddMessageLine(string.Format("Line {0}: {1}",LineCounter, ex.Message));
                return null;
            }
        }

Usage Example

Пример #1
0
		public void WhenParserCalledWithCommentOnlyDoesNotGenerateInstructionSet()
		{
			Parser parser = new Parser ();
			
			ushort[] instructionSet = parser.Parse (new string[]{"; Try some basic stuff"});
			
			Assert.IsNull (instructionSet);
		}
All Usage Examples Of DCPU16_ASM.Assembler.Parser::Parse