예제 #1
0
파일: Parser.cs 프로젝트: arlm/MixEmul
        public static PreInstruction[] ParseSource(string[] sourceLines, ParsingStatus status)
        {
            status.LocationCounter = 0;
            int endLineNumber   = -1;
            var preInstructions = new List <PreInstruction>();

            for (int lineNumber = 0; lineNumber < sourceLines.Length; lineNumber++)
            {
                status.LineNumber = lineNumber;

                if (endLineNumber != -1 && !IsCommentLine(sourceLines[lineNumber]))
                {
                    status.ReportParsingWarning(LineSection.CommentField, 0, sourceLines[lineNumber].Length, "END has been parsed; line will be treated as comment");
                    preInstructions.Add(new ParsedSourceLine(lineNumber, sourceLines[lineNumber]));
                }
                else
                {
                    var parsedLine = ParseLine(sourceLines[lineNumber], status);
                    preInstructions.Add(parsedLine);
                    if (parsedLine.OpField == "END")
                    {
                        endLineNumber = preInstructions.Count - 1;
                    }
                }
            }

            if (endLineNumber == -1)
            {
                status.Findings.Add(new AssemblyError(int.MinValue, LineSection.CommentField, 0, 0, new ParsingError("END operation is mandatory but not included")));
            }
            else
            {
                // all symbols that are not yet defined at the end of the parsing process are treated as if "<symbolname> CON *" instructions were included just before the END instruction
                foreach (SymbolBase symbol in status.Symbols)
                {
                    if (!symbol.IsSymbolDefined)
                    {
                        symbol.SetValue(status.LocationCounter);

                        var parameters  = new LoaderInstructionParameters(new NumberValue(symbol.MemoryWordSign, symbol.MemoryWordMagnitude), 0);
                        var instruction = new PreInstruction(mLoaderInstructions["CON"], parameters);

                        preInstructions.Insert(endLineNumber, instruction);
                        status.LocationCounter++;
                        endLineNumber++;
                    }
                }
            }

            return(preInstructions.ToArray());
        }
예제 #2
0
파일: Parser.cs 프로젝트: arlm/MixEmul
        static void GetMixOrLoaderInstructionAndParameters(string opField, string addressField, ParsingStatus status, out InstructionBase instruction, out IInstructionParameters instructionParameters)
        {
            status.LineSection    = LineSection.AddressField;
            instructionParameters = null;

            instruction = mLoaderInstructions[opField];

            if (instruction != null)
            {
                instructionParameters = LoaderInstructionParameters.ParseAddressField(instruction, addressField, status);
            }
            else
            {
                instruction = mInstructionSet[opField];

                if (instruction != null)
                {
                    instructionParameters = MixInstructionParameters.ParseAddressField(instruction, addressField, status);
                    status.LocationCounter++;
                }
            }
        }