示例#1
0
        private void AddAssemblerDirectiveToken(List <Token> tokens, string str, EnumAssemblerDirectives assemblerDirective)
        {
            Token tkn = new Token(str);

            tkn.AddProperty(EnumTokenProperties.TokenType, (Int64)EnumTokenTypes.AssemblerDirective);
            tkn.AddProperty(EnumTokenProperties.AssemblerDirective, (Int64)assemblerDirective);
            tokens.Add(tkn);
        }
示例#2
0
        private void AddAddressRegisterToken(List <Token> tokens, string str, EnumRegisters registerEnum)
        {
            Token tkn = new Token(str);

            tkn.AddProperty(EnumTokenProperties.TokenType, (Int64)EnumTokenTypes.AddressRegister);
            tkn.AddProperty(EnumTokenProperties.RegisterNumber, (Int64)registerEnum);
            tokens.Add(tkn);
        }
示例#3
0
        public void AddInstructionToken(List <Token> tokens, string str, EnumInstructions instructionEnum, EnumInstructionSizes instructionSize = EnumInstructionSizes.Long)
        {
            Token tkn = new Token(str);

            tkn.AddProperty(EnumTokenProperties.TokenType, (Int64)EnumTokenTypes.Instruction);
            tkn.AddProperty(EnumTokenProperties.RealInstruction, (Int64)instructionEnum);
            tkn.AddProperty(EnumTokenProperties.InstructionSize, (Int64)instructionSize);
            tokens.Add(tkn);
        }
示例#4
0
        public bool ResolveLabels()
        {
            //Resolves labels on the Token File.
            //Loop through all token lines and replace instances of label tokens with respective immediate tokens

            for (int i = 0; i < File.Count; i++)
            {
                int index = File[i].ReturnLabelIndex();
                if (index >= 0)
                {
                    string labelText      = File[i].Tokens[index].Text;
                    Int64  replaceLiteral = 0;
                    if (LabelTable.ContainsKey(labelText))
                    {
                        replaceLiteral = LabelTable[labelText];
                    }
                    else
                    {
                        throw new FoundUnexpectedToken(File[i].Tokens[index].DeepCopy(), "Could not find label in label table");
                        return(false);
                    }
                    Token replacement = new Token((int)EnumTokenTypes.Immediate, "$" + replaceLiteral.ToString());
                    replacement.AddProperty(EnumTokenProperties.ImmediateValue, replaceLiteral);
                    File[i].Tokens[index] = replacement;
                }
                continue;
            }

            return(true);
        }
示例#5
0
        /// <summary>
        /// This loops through every unit in the string and determines if each one is a label, immediate, instruction etc.
        /// </summary>
        /// <returns></returns>
        private bool SimpleKeywordParse(string[] units, ref Token[] tokens)
        {
            tokens = new Token[units.Length];
            for (int i = 0; i < units.Length; i++)
            {
                Token temp = null;
                if (YKeywords.IsKeyword(units[i], ref temp))
                {
                    //First, check if the string is an existing keyword.
                    //If not, it will be a label, immediate, or an address register with offset
                    tokens[i] = temp;
                }
                else
                {
                    //The first instruction can also be a label
                    if (units[i].EndsWith(':'))
                    {
                        //label
                        tokens[i] = new Token((int)EnumTokenTypes.Label, units[i]);
                        continue;
                    }

                    if (units[i].StartsWith('$'))
                    {
                        //Can be an immediate, or an address register with offset
                        Int64 ImmediateVal = 0;
                        if (units[i].Contains("("))
                        {
                            //Address register with offset, error if no immediate!
                            int j = units[i].IndexOf("(");
                            ImmediateVal = MathConversion.ParseImmediate(units[i].Substring(0, j - 1));
                            units[i]     = units[i].Substring(j);
                            if (YKeywords.IsKeyword(units[i], ref temp))
                            {
                                temp.AddProperty(EnumTokenProperties.ImmediateValue, ImmediateVal); //ImmediateValue holds the offset!
                                tokens[i] = temp;
                                continue;
                            }
                        }

                        ImmediateVal = MathConversion.ParseImmediate(units[i]);
                        tokens[i]    = new Token((int)EnumTokenTypes.Immediate, units[i]);
                        tokens[i].AddProperty(EnumTokenProperties.ImmediateValue, ImmediateVal);
                        continue;
                    }

                    tokens[i] = new Token((int)EnumTokenTypes.Unkown, units[i]);
                    continue;
                }
            }
            return(true);
        }