Exemplo n.º 1
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            if (text.Length == 0)
            {
                return(new NumberValue(0L));
            }

            // it can be either a literal value...
            var value = ValueSymbol.ParseValue(text, sectionCharIndex, status);

            if (value != null)
            {
                return(value);
            }

            // ... a literal constant...
            value = LiteralConstantSymbol.ParseValue(text, sectionCharIndex, status);
            if (value != null)
            {
                return(value);
            }

            // ... or an expression
            return(ExpressionValue.ParseValue(text, sectionCharIndex, status));
        }
Exemplo n.º 2
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            // an empty index is equal to 0
            if (text.Length == 0)
            {
                return(new NumberValue(0L));
            }

            // it can only be an index if it starts with a comma
            if (text[0] == TagCharacter)
            {
                // the actual fieldspec can be any expression...
                var expression = ExpressionValue.ParseValue(text.Substring(1), sectionCharIndex + 1, status);

                if (expression == null)
                {
                    return(null);
                }

                var value = expression.GetValue(status.LocationCounter);

                // ... as long as it is within the range of valid MIX byte values
                if (value >= MixByte.MinValue && value <= MixByte.MaxValue)
                {
                    return(expression);
                }

                status.ReportParsingError(sectionCharIndex, text.Length, "index value invalid");
            }

            return(null);
        }
Exemplo n.º 3
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            // an empty fieldspec means we use the default
            if (text.Length == 0)
            {
                return(new NumberValue(Default));
            }

            // it can only be a fieldspec if it starts and ends with brackets
            if (text.Length >= 2 && text[0] == TagCharacter && text[text.Length - 1] == ')')
            {
                // the actual fieldspec can be any expression...
                var expression = ExpressionValue.ParseValue(text.Substring(1, text.Length - 2), sectionCharIndex + 1, status);

                if (expression == null)
                {
                    return(null);
                }

                var value = expression.GetValue(status.LocationCounter);

                // ... as long as it is within the range of valid MIX byte values
                if (value >= MixByte.MinValue && value <= MixByte.MaxValue)
                {
                    return(expression);
                }

                status.ReportParsingError(sectionCharIndex, text.Length, "field value invalid");
            }

            return(null);
        }
Exemplo n.º 4
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            // split the text to parse in its W-value components
            var textParts    = text.Split(new char[] { ',' });
            int currentIndex = 0;

            var register = new FullWordRegister();
            var word     = new FullWord(0);

            // parse and apply each component to the word that contains the result
            foreach (string part in textParts)
            {
                // parse the address part...
                var braceIndex = part.IndexOf('(');
                var address    = ExpressionValue.ParseValue((braceIndex == -1) ? part : part.Substring(0, braceIndex), sectionCharIndex + currentIndex, status);
                if (address == null)
                {
                    return(null);
                }

                // ... and check if it is valid
                var addressSign      = address.GetSign(status.LocationCounter);
                var addressMagnitude = address.GetMagnitude(status.LocationCounter);
                if (addressMagnitude > register.MaxMagnitude)
                {
                    status.ReportParsingError(sectionCharIndex + currentIndex, (braceIndex == -1) ? part.Length : braceIndex, "W-value field value invalid");
                    return(null);
                }

                register.MagnitudeLongValue = addressMagnitude;
                register.Sign = addressSign;
                int fieldValue = FullWord.ByteCount;

                // if a fieldspec part is present...
                if (braceIndex >= 0)
                {
                    // ... parse its value...
                    var field = FPartValue.ParseValue(part.Substring(braceIndex), (sectionCharIndex + currentIndex) + braceIndex, status);
                    if (field == null)
                    {
                        return(null);
                    }

                    // ... and check if it is valid
                    if (field.GetValue(status.LocationCounter) != FPartValue.Default)
                    {
                        fieldValue = (int)field.GetValue(status.LocationCounter);
                    }
                }

                // use the fieldspec value to create and check an actual fieldspec
                var fieldSpec = new FieldSpec(fieldValue);
                if (!fieldSpec.IsValid)
                {
                    status.ReportParsingError((sectionCharIndex + currentIndex) + braceIndex, part.Length - braceIndex, "field must be a fieldspec");
                    return(null);
                }

                // apply the component to the word that will contain the end result
                WordField.LoadFromRegister(fieldSpec, register).ApplyToFullWord(word);
                currentIndex += part.Length + 1;
            }

            return(new NumberValue(word.Sign, word.MagnitudeLongValue));
        }