Example #1
0
        /// <summary>
        /// Creates an <see cref="IntegerType"/> instance.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="name"></param>
        /// <param name="enumerator"></param>
        public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Types?t = GetExactType(type);

            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            _isEnumeration = false;

            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.OpenBracket)
            {
                _isEnumeration = true;
                symbols.PutBack(current);
                _map = Lexer.DecodeEnumerations(symbols);
            }
            else if (current == Symbol.OpenParentheses)
            {
                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
Example #2
0
        /// <summary>
        /// Creates an <see cref="IntegerType"/> instance.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="name"></param>
        /// <param name="enumerator"></param>
        public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base (module, name)
        {
            Types? t = GetExactType(type);
            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            _isEnumeration = false;

            Symbol current = symbols.NextNonEOLSymbol();
            if (current == Symbol.OpenBracket)
            {
                _isEnumeration = true;
                symbols.PutBack(current);
                _map = Lexer.DecodeEnumerations(symbols);
            }
            else if (current == Symbol.OpenParentheses)
            {
                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
Example #3
0
 static Constants()
 {
     GraphWidthValueRange         = new InclusiveValueRange <int>(67, 1);
     GraphLengthValueRange        = new InclusiveValueRange <int>(32, 1);
     ObstaclesPercentValueRange   = new InclusiveValueRange <int>(99, 0);
     AlgorithmDelayTimeValueRange = new InclusiveValueRange <int>(35, 0);
     GraphParamsValueRanges       = new ValueRanges <int>(GraphWidthValueRange, GraphLengthValueRange);
 }
Example #4
0
 static Constants()
 {
     ScaleValueRange              = new InclusiveValueRange <double>(2.5, 0.1);
     GraphWidthValueRange         = new InclusiveValueRange <int>(150, 1);
     GraphLengthValueRange        = new InclusiveValueRange <int>(75, 1);
     GraphParamsValueRanges       = new ValueRanges <int>(GraphWidthValueRange, GraphLengthValueRange);
     ObstaclesPercentValueRange   = new InclusiveValueRange <double>(99, 0);
     AlgorithmDelayTimeValueRange = new InclusiveValueRange <double>(35, 0);
     OffsetValueRange             = new InclusiveValueRange <double>(-1000, 1000);
 }
Example #5
0
 public OctetStringType(IModule module, string name, ISymbolEnumerator symbols)
     : base(module, name)
 {
     Symbol current = symbols.NextNonEOLSymbol();
     if (current == Symbol.OpenParentheses)
     {
         symbols.PutBack(current);
         _size = Lexer.DecodeRanges(symbols);
         current.Assert(_size.IsSizeDeclaration, "SIZE keyword is required for ranges of octet string!");
     }
     else
     {
         symbols.PutBack(current);
         _size   = new ValueRanges(isSizeDecl: true);
     }
 }
        public OctetStringType(IModule module, string name, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.OpenParentheses)
            {
                symbols.PutBack(current);
                _size = Lexer.DecodeRanges(symbols);
                current.Assert(_size.IsSizeDeclaration, "SIZE keyword is required for ranges of octet string!");
            }
            else
            {
                symbols.PutBack(current);
                _size = new ValueRanges(isSizeDecl: true);
            }
        }
Example #7
0
 static Constants()
 {
     DistanceBetweenVerticesValueRange = new InclusiveValueRange <double>(70, 0);
     ZoomValueRange            = new InclusiveValueRange <double>(1000, 0);
     OpacityValueRange         = new InclusiveValueRange <double>(1, 0);
     AngleValueRange           = new InclusiveValueRange <double>(360, 0);
     ObstaclePercentValueRange = new InclusiveValueRange <double>(99, 0);
     AlgorithmDelayValueRange  = new InclusiveValueRange <double>(35, 0);
     GraphWidthValueRange      = new InclusiveValueRange <int>(25, 1);
     GraphLengthValueRange     = GraphWidthValueRange;
     GraphHeightValueRange     = GraphLengthValueRange;
     GraphParamsValueRanges    = new ValueRanges <int>(
         GraphWidthValueRange,
         GraphLengthValueRange,
         GraphHeightValueRange
         );
 }
Example #8
0
        public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Types? t = GetExactType(type);
            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            Symbol current = symbols.NextNonEOLSymbol();
            if (current == Symbol.OpenParentheses)
            {
                current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values

                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
        private static IEnumerable <IRestriction> CreateRestrictions(ValueRanges ranges)
        {
            List <IRestriction> result = new List <IRestriction>();

            if (ranges != null)
            {
                foreach (ValueRange range in ranges)
                {
                    if (!range.End.HasValue)
                    {
                        result.Add(new IsEqualRestriction(range.Start));
                    }
                    else
                    {
                        result.Add(new IsInRangeRestriction(range.Start, range.End.Value));
                    }
                }
            }

            return(result);
        }
Example #10
0
        private static IEnumerable<IRestriction> CreateRestrictions(ValueRanges ranges)
        {
            List<IRestriction> result = new List<IRestriction>();

            if (ranges != null)
            {
                foreach (ValueRange range in ranges)
                {
                    if (!range.End.HasValue)
                    {
                        result.Add(new IsEqualRestriction(range.Start));
                    }
                    else
                    {
                        result.Add(new IsInRangeRestriction(range.Start, range.End.Value));
                    }
                }
            }

            return result;
        }
Example #11
0
        public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Types?t = GetExactType(type);

            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.OpenParentheses)
            {
                current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values

                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
Example #12
0
        /// <summary>
        /// Creates an <see cref="TypeAssignment" />.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
        public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
        {
            _module = module;
            _name   = name;

            SymbolList typeSymbols = new SymbolList();

            typeSymbols.Add(type);

            Symbol current = symbols.NextSymbol();

            while (current != Symbol.EOL)
            {
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                    break;
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                    break;
                }

                typeSymbols.Add(current);
                current = symbols.NextSymbol();
            }

            _type = typeSymbols.Join(" ");

            if ((_ranges == null) && (_map == null))
            {
                current = symbols.NextNonEOLSymbol();
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                }
                else if (current != null)
                {
                    symbols.PutBack(current);
                }
            }

            if (isMacroSyntax)
            {
                // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
                return;
            }

            // outside macro Syntax clause we  wait for two consecutive linebreaks with a following valid identifier as end condition
            Symbol previous     = current;
            Symbol veryPrevious = null;

            while ((current = symbols.NextSymbol()) != null)
            {
                if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
                {
                    symbols.PutBack(current);
                    return;
                }

                veryPrevious = previous;
                previous     = current;
            }

            previous.Assert(false, "end of file reached");
        }
Example #13
0
        public static ValueRanges DecodeRanges(ISymbolEnumerator symbols)
        {
            ValueRanges result = new ValueRanges();

            Symbol startSymbol = symbols.NextNonEOLSymbol();
            Symbol current = startSymbol;
            current.Expect(Symbol.OpenParentheses);

            while (current != Symbol.CloseParentheses)
            {
                Symbol value1Symbol = symbols.NextNonEOLSymbol();

                if ((value1Symbol == Symbol.Size) && !result.IsSizeDeclaration)
                {
                    result.IsSizeDeclaration = true;
                    symbols.NextNonEOLSymbol().Expect(Symbol.OpenParentheses);
                    continue;
                }

                // check for valid number
                Int64? value1 = DecodeNumber(value1Symbol);
                if (!value1.HasValue)
                {
                    value1Symbol.Assert(false, "Invalid range declaration!");                    
                }

                // process next symbol
                ValueRange range;
                current = symbols.NextNonEOLSymbol();

                if (current == Symbol.DoubleDot)
                {
                    // its a continous range
                    Symbol value2Symbol = symbols.NextNonEOLSymbol();
                    Int64? value2 = DecodeNumber(value2Symbol);
                    value2Symbol.Assert(value2.HasValue && (value2.Value >= value1.Value), "Invalid range declaration!");

                    if (value2.Value == value1.Value)
                    {
                        range = new ValueRange(value1.Value, null);
                    }
                    else
                    {
                        range = new ValueRange(value1.Value, value2.Value);
                    }

                    current = symbols.NextNonEOLSymbol();
                }
                else
                {
                    // its a single number
                    range = new ValueRange(value1.Value, null);
                }

                // validate range
                if (result.IsSizeDeclaration)
                {
                    value1Symbol.Assert(range.Start >= 0, "Invalid range declaration! Size must be greater than 0");
                }

                result.Add(range);
                
                // check next symbol
                current.Expect(Symbol.Pipe, Symbol.CloseParentheses);
            }

            if (result.IsSizeDeclaration)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);
            }

            // validate ranges in between
            for (int i=0; i<result.Count; i++)
            {
                for (int k=i+1; k<result.Count; k++)
                {
                    startSymbol.Assert(!result[i].IntersectsWith(result[k]), "Invalid range declaration! Overlapping of ranges!");
                }
            }

            return result;
        }
Example #14
0
        /// <summary>
        /// Creates an <see cref="TypeAssignment" />.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
        public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
        {
            _module = module;
            _name   = name;

            SymbolList typeSymbols = new SymbolList();
            typeSymbols.Add(type);

            Symbol current = symbols.NextSymbol();
            while (current != Symbol.EOL)
            {
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                    break;
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                    break;
                }

                typeSymbols.Add(current);
                current = symbols.NextSymbol();
            }

            _type = typeSymbols.Join(" ");

            if ((_ranges == null) && (_map == null))
            {
                current = symbols.NextNonEOLSymbol();
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                }
                else if (current != null)
                {
                    symbols.PutBack(current);
                }
            }

            if (isMacroSyntax)
            {
                // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
                return;
            }

            // outside macro Syntax clause we  wait for two consecutive linebreaks with a following valid identifier as end condition         
            Symbol previous = current;
            Symbol veryPrevious = null;

            while ((current = symbols.NextSymbol()) != null)
            {
                if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
                {
                    symbols.PutBack(current);
                    return;
                }

                veryPrevious = previous;
                previous = current;
            }
            
            previous.Assert(false, "end of file reached");
        }