Exemplo n.º 1
0
        public uint[] Parse(string fileData)
        {
            Kernel = new List<uint>(KERNEL_SIZE);
            for (int i = 0; i < KERNEL_SIZE; i++) { Kernel.Add(0); }

            // First round to construct the label table
            Lexer.Lexer lexer = new Lexer.Lexer(fileData);

            while (lexer.HasNext())
            {
                try
                {
                    ParseInstruction(lexer, true);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error {e.Message} on line {LineNumber}");
                    throw;
                }
            }

            // reset the stuff after the first go round that found the label locations
            Kernel = new List<uint>(KERNEL_SIZE);
            for (int i = 0; i < KERNEL_SIZE; i++) { Kernel.Add(0); }
            lexer = new Lexer.Lexer(fileData);
            KernelIndex = 0;
            LineNumber = 1;

            while (lexer.HasNext())
            {
                ParseInstruction(lexer, false);
            }

            return Kernel.ToArray();
        }