Esempio n. 1
0
        public ImportsFrom(Symbol last, ISymbolEnumerator symbols)
        {
            Symbol previous = last;
            Symbol current;

            while ((current = symbols.NextSymbol()) != Symbol.From)
            {
                if (current == Symbol.EOL)
                {
                    continue;
                }

                if (current == Symbol.Comma)
                {
                    previous.AssertIsValidIdentifier();
                    _types.Add(previous.ToString());
                }

                previous = current;
            }

            previous.AssertIsValidIdentifier();
            _types.Add(previous.ToString());

            _module = symbols.NextSymbol().ToString().ToUpperInvariant(); // module names are uppercase
        }
Esempio n. 2
0
        public ImportsFrom(Symbol last, ISymbolEnumerator symbols)
        {
            Symbol previous = last;
            Symbol current;
            while ((current = symbols.NextSymbol()) != Symbol.From)
            {
                if (current == Symbol.EOL) 
                {
                    continue;
                }
                
                if (current == Symbol.Comma)
                {
                    previous.AssertIsValidIdentifier();
                    _types.Add(previous.ToString());
                }
                
                previous = current;
            }

            previous.AssertIsValidIdentifier();
            _types.Add(previous.ToString());

            _module = symbols.NextSymbol().ToString().ToUpperInvariant(); // module names are uppercase
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an <see cref="Imports"/> instance.
        /// </summary>
        /// <param name="lexer"></param>
        public Imports(IModule module, ISymbolEnumerator symbols)
        {
            _module = module;

            Symbol current;

            while ((current = symbols.NextSymbol()) != Symbol.Semicolon)
            {
                if (current == Symbol.EOL)
                {
                    continue;
                }

                ImportsFrom imports = new ImportsFrom(current, symbols);

                this.Add(imports);
            }
        }
Esempio n. 4
0
        private void ParseEntities(ISymbolEnumerator symbols)
        {
            Symbol     temp   = symbols.NextNonEOLSymbol();
            SymbolList buffer = new SymbolList();

            while (temp != Symbol.End)
            {
                if (temp == Symbol.Assign)
                {
                    ParseEntity(buffer, symbols);
                    buffer.Clear();
                    // skip linebreaks behind an entity
                    temp = symbols.NextNonEOLSymbol();
                }
                else
                {
                    buffer.Add(temp);
                    temp = symbols.NextSymbol();
                }
            }
        }
Esempio n. 5
0
        public MibModule(ISymbolEnumerator symbols)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException("lexer");
            }

            Symbol temp = symbols.NextNonEOLSymbol();

            temp.AssertIsValidIdentifier();
            _name = temp.ToString().ToUpperInvariant(); // all module names are uppercase

            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Definitions);

            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Assign);

            temp = symbols.NextSymbol();
            temp.Expect(Symbol.Begin);

            temp = symbols.NextNonEOLSymbol();
            if (temp == Symbol.Imports)
            {
                _imports = ParseDependents(symbols);
            }
            else if (temp == Symbol.Exports)
            {
                _exports = ParseExports(symbols);
            }
            else
            {
                symbols.PutBack(temp);
            }

            ParseEntities(symbols);
        }
Esempio n. 6
0
        public Exports(IModule module, ISymbolEnumerator s)
        {
            _module = module;

            Symbol previous = null;
            Symbol current;

            do
            {
                current = s.NextSymbol();

                if (current == Symbol.EOL)
                {
                    continue;
                }
                else if (((current == Symbol.Comma) || (current == Symbol.Semicolon)) && (previous != null))
                {
                    previous.AssertIsValidIdentifier();
                    _types.Add(previous.ToString());
                }

                previous = current;
            }while (current != Symbol.Semicolon);
        }
Esempio n. 7
0
        public MibModule(ISymbolEnumerator symbols)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException("lexer");
            }

            Symbol temp = symbols.NextNonEOLSymbol();
            temp.AssertIsValidIdentifier();
            _name = temp.ToString().ToUpperInvariant(); // all module names are uppercase
            
            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Definitions);
            
            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Assign);
            
            temp = symbols.NextSymbol();
            temp.Expect(Symbol.Begin);
            
            temp = symbols.NextNonEOLSymbol();
            if (temp == Symbol.Imports)
            {
                _imports = ParseDependents(symbols);
            }
            else if (temp == Symbol.Exports)
            {
                _exports = ParseExports(symbols);
            }
            else
            {
                symbols.PutBack(temp);
            }

            ParseEntities(symbols);
        }
Esempio n. 8
0
        public Exports(IModule module, ISymbolEnumerator s)
        {
            _module = module;

            Symbol previous = null;
            Symbol current;
            do
            {
                current = s.NextSymbol();

                if (current == Symbol.EOL)
                {
                    continue;
                }
                else if (((current == Symbol.Comma) || (current == Symbol.Semicolon)) && (previous != null))
                {
                    previous.AssertIsValidIdentifier();
                    _types.Add(previous.ToString());
                }

                previous = current;
            }
            while (current != Symbol.Semicolon);
        }
Esempio n. 9
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");
        }
Esempio n. 10
0
        private void ParseEntity(SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            if ((preAssignSymbols == null) || (preAssignSymbols.Count == 0))
            {
                Symbol s = symbols.NextSymbol();
                if (s != null)
                {
                    s.Assert(false, "Invalid Entity declaration");
                }
                else
                {
                    throw new MibException("Invalid Entity declaration");
                }
            }

            // check for a valid identifier
            preAssignSymbols[0].AssertIsValidIdentifier();

            if (preAssignSymbols.Count == 1)
            {
                // its a typedef
                _tokens.Add(Lexer.ParseBasicTypeDef(this, preAssignSymbols[0].ToString(), symbols, isMacroSyntax: false));
                return;
            }

            ISymbolEnumerator preAssignSymbolsEnumerator = preAssignSymbols.GetSymbolEnumerator();

            preAssignSymbolsEnumerator.NextNonEOLSymbol(); // returns identifier
            Symbol type = preAssignSymbolsEnumerator.NextNonEOLSymbol();

            // parse declarations
            if (type == Symbol.Object)
            {
                Symbol next = preAssignSymbolsEnumerator.NextNonEOLSymbol();

                if (next == Symbol.Identifier)
                {
                    _tokens.Add(new OidValueAssignment(this, preAssignSymbols, symbols));
                    return;
                }
                else if (next != null)
                {
                    preAssignSymbolsEnumerator.PutBack(next);
                }
            }
            if (type == Symbol.ModuleIdentity)
            {
                _tokens.Add(new ModuleIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectType)
            {
                _tokens.Add(new ObjectType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectGroup)
            {
                _tokens.Add(new ObjectGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationGroup)
            {
                _tokens.Add(new NotificationGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ModuleCompliance)
            {
                _tokens.Add(new ModuleCompliance(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationType)
            {
                _tokens.Add(new NotificationType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectIdentity)
            {
                _tokens.Add(new ObjectIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.Macro)
            {
                _tokens.Add(new Macro(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.TrapType)
            {
                _tokens.Add(new TrapType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.AgentCapabilities)
            {
                _tokens.Add(new AgentCapabilities(this, preAssignSymbols, symbols));
                return;
            }

            preAssignSymbols[1].Assert(false, "Unknown/Invalid declaration");
        }
Esempio n. 11
0
        private void ParseEntity(SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            if ((preAssignSymbols == null) || (preAssignSymbols.Count == 0))
            {
                Symbol s = symbols.NextSymbol();
                if (s != null)
                {
                    s.Assert(false, "Invalid Entitiy declaration");
                }
                else
                {
                    throw new MibException("Invalid Entitiy declaration");
                }
            }

            // check for a valid identifier
            preAssignSymbols[0].AssertIsValidIdentifier();
            
            if (preAssignSymbols.Count == 1)
            {
                // its a typedef
                _tokens.Add(Lexer.ParseBasicTypeDef(this, preAssignSymbols[0].ToString(), symbols, isMacroSyntax: false));
                return;
            }

            ISymbolEnumerator preAssignSymbolsEnumerator = preAssignSymbols.GetSymbolEnumerator();
            preAssignSymbolsEnumerator.NextNonEOLSymbol(); // returns identifier
            Symbol type = preAssignSymbolsEnumerator.NextNonEOLSymbol();

            // parse declarations
            if (type == Symbol.Object)
            {
                Symbol next = preAssignSymbolsEnumerator.NextNonEOLSymbol();

                if (next == Symbol.Identifier)
                {
                    _tokens.Add(new OidValueAssignment(this, preAssignSymbols, symbols));
                    return;
                }
                else if (next != null)
                {
                    preAssignSymbolsEnumerator.PutBack(next);
                }
            }
            if (type == Symbol.ModuleIdentity)
            {
                _tokens.Add(new ModuleIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectType)
            {
                _tokens.Add(new ObjectType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectGroup)
            {
                _tokens.Add(new ObjectGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationGroup)
            {
                _tokens.Add(new NotificationGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ModuleCompliance)
            {
                _tokens.Add(new ModuleCompliance(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationType)
            {
                _tokens.Add(new NotificationType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectIdentity)
            {
                _tokens.Add(new ObjectIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.Macro)
            {
                _tokens.Add(new Macro(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.TrapType)
            {
                _tokens.Add(new TrapType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.AgentCapabilities)
            {
                _tokens.Add(new AgentCapabilities(this, preAssignSymbols, symbols));
                return;
            }

            preAssignSymbols[1].Assert(false, "Unknown/Invalid declaration");
        }
Esempio n. 12
0
        private void ParseEntities(ISymbolEnumerator symbols)
        {
            Symbol     temp   = symbols.NextNonEOLSymbol();
            SymbolList buffer = new SymbolList();

            while (temp != Symbol.End)
            {
                if (temp == Symbol.Assign)
                {
                    ParseEntity(buffer, symbols);
                    buffer.Clear();
                    // skip linebreaks behind an entity
                    temp = symbols.NextNonEOLSymbol();
                }
                else
                {
                    buffer.Add(temp);
                    temp = symbols.NextSymbol();
                }
            }
        }
Esempio n. 13
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");
        }