Exemplo n.º 1
0
        /**
         * Parses the operation section of the line if it has a Directive.
         *
         * @param line current line to parse
         * @param interLine the line as a single line in the intermediate file
         * @param symb symbol table reference
         * @refcode DS2
         * @errtest
         *  N/A
         * @errmsg
         *  N/A
         * @author Mark Mathis
         * @creation April 9, 2011
         * @modlog
         *  - April  9, 2011 -  Mark - ParseDirective properly parses directives.
         *  - April  9, 2011 -  Mark - Uses new ParseLiteralOperand format.
         *  - April 12, 2011 - Jacob - Factor out operand parsing.
         *  - April 14, 2011 -  Mark - Moved into DirectiveParser class.
         *  - April 15, 2011 -  Mark - Factored out all parsing into separate methods.
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        public static void ParseDirective(ref string line, ref IntermediateLine interLine, ref SymbolTable symb)
        {
            Logger.Log("Parsing directive on line " + interLine.SourceLineNumber, "DirectiveParser");

            if (interLine.Directive.ToUpper() != "NOP")
            OperandParser.ParseOperand(ref line, ref interLine, ref symb, 16);

            // This will decide which directive is in this line and how it should
            // be handled by the parser.
            string currentDirective = interLine.Directive.ToUpper();
            switch (currentDirective)
            {
                case "START":
                    {
                        ParseStart(ref interLine, ref symb);
                    } break;
                case "RESET":
                    {
                        ParseReset(ref interLine, ref symb);
                    } break;
                case "EQU":
                    {
                        ParseEqu(ref interLine, ref symb);
                    } break;
                case "EQUE":
                    {
                         ParseEque(ref interLine, ref symb);
                    } break;
                case "ENTRY":
                    {
                        ParseEntry(ref interLine, ref symb);
                    } break;
                case "EXTRN":
                    {
                        ParseExtrn(ref interLine, ref symb);
                    } break;
                case "END":
                    {
                        ParseEnd(ref interLine, ref symb);
                    } break;
                case "DAT":
                    {
                        ParseDat(ref interLine, ref symb);
                    } break;
                case "ADC":
                    {
                        ParseAdc(ref interLine, ref symb);
                    } break;
                case "ADCE":
                    {
                        ParseAdce(ref interLine, ref symb);
                    } break;
                case "NOP":
                    {
                        interLine.NOPificate();
                        interLine.ProgramCounter = Parser.LC;
                        Parser.IncrementLocationCounter();
                    } break;
                default:
                    {
                    } break;
            }

            Logger.Log("Finished parsing directive on line " + interLine.SourceLineNumber, "DirectiveParser");
        }
Exemplo n.º 2
0
        /**
         * Parses the dat directive, ensuring that the operand has proper syntax
         * and is correctly assigned to the current word of memory.
         *
         * @param interLine the intermediate line to process
         * @param symb symbol table reference
         *
         * @refcode D8
         * @errtest
         *  N/A
         * @errmsg ES.14
         * @author Mark Mathis
         * @creation April 18, 2011
         * @modlog
         *  - April 19, 2011 - Jacob - Fixed padding on values.
         *  - April 24, 2011 -  Mark - Commented out the part that put the value of the dat
         *                              into the symbol table until that can be made clearer
         *                              by Al.
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        private static void ParseDat(ref IntermediateLine interLine, ref SymbolTable symb)
        {
            Logger.Log("Parsing DAT directive", "DirectiveParser");

            if (interLine.DirectiveLitOperand != OperandParser.Literal.NONE &&
                interLine.DirectiveLitOperand != OperandParser.Literal.EXPRESSION &&
                interLine.DirectiveLitOperand != OperandParser.Literal.NUMBER &&
                interLine.DirectiveLitOperand != OperandParser.Literal.UNKNOWN)
            {
                if (interLine.Label != null)
                {
                    if (!symb.ContainsSymbol(interLine.Label))
                    {
                        symb.AddSymbol(interLine.Label, Parser.LC, Usage.LABEL); //,interLine.DirectiveOperand);
                    }
                    else
                    {
                        Symbol datSym = symb.RemoveSymbol(interLine.Label);
                        datSym.lc = Parser.LC;
                        //datSym.val = interLine.DirectiveOperand;
                        symb.AddSymbol(datSym);
                    }
                }

                string val = Convert.ToString(Convert.ToInt32(interLine.DirectiveOperand, 16), 2);

                // assumed to be in correct representation; always pad to the left
                interLine.Bytecode = val.PadLeft(16, '0');
            }
            else if (interLine.DirectiveLitOperand == OperandParser.Literal.UNKNOWN)
            {
                // error: literal operand in improper format
                interLine.AddError(Errors.Category.Serious, 37);
            }
            else
            {
                // error: invalid operand type
                Logger.Log("ERROR: ES.14 encountered", "DirectiveParser");
                interLine.AddError(Errors.Category.Serious, 14);
                interLine.NOPificate();
            }

            // this should need to happen no matter what
            interLine.ProgramCounter = Parser.LC;
            Parser.IncrementLocationCounter();

            Logger.Log("Finished parsing DAT directive", "DirectiveParser");
        }