📄 parsemib.jjt
字号:
<MODULE_TOKEN> <MANDATORY_GROUPS_TOKEN> <LBRACE> (<IDENTIFIER> [<COMMA>])+ <RBRACE> | <GROUP_TOKEN> <IDENTIFIER> | <AUGMENTS_TOKEN> <LBRACE> <IDENTIFIER> <RBRACE> | <OBJECT_TOKEN> <IDENTIFIER> | <OBJECTS_TOKEN> <LBRACE> (<IDENTIFIER> [<COMMA>])+ <RBRACE> | <SYNTAX_TOKEN> (<OBJECT_TOKEN> <IDENTIFIER_TOKEN> | <OCTET_TOKEN> <STRING_TOKEN> [SizeDeclaration()] | TableSequenceOf() | GetTypeIdentifier() (SizeDeclaration() | <LBRACE> (<IDENTIFIER> <LPAREN> <INTEGER_LITERAL> <RPAREN> [<COMMA>])+ <RBRACE> )* ) | (<ACCESS_TOKEN> | <MAX_ACCESS_TOKEN> | <MIN_ACCESS_TOKEN>) GetAccessIdentifier() | IndexOfTable() | <ASSIGN> <LBRACE> ParentObjectIdentifier() IntegerOID() <RBRACE> )*) | IndexOfTable() | ( <OBJECT_TOKEN> <IDENTIFIER_TOKEN> <ASSIGN> <LBRACE> ParentObjectIdentifier() (MultipleOids())* [IntegerOID()] <RBRACE>))}// handle NOTIFICATION-TPYE// at this time it just mostly skips the info here// it would be easy to walk the trees later and output xml// for the trapsvoid Events() : {}{ // overSmsQueueThreshold NOTIFICATION-TYPE // STATUS current // OBJECTS { smsInQueue } // DESCRIPTION "The SMS queue has more messages than the configurable threshold. // This event will be sent on every poll until the messages fall below the threshold. // The number of sms currently in the queue is sent with the trap." // ::= { events 1 } // // or there could be something like this: // NOTIFICATIONS { coldStart, authenticationFailure } <IDENTIFIER> (<NOTIFICATION_TYPE_TOKEN> | <NOTIFICATION_GROUP_TOKEN>) (<STATUS> <IDENTIFIER> | <DESCRIPTION> <DESCRIPTOR_LITERAL> | <OBJECTS_TOKEN> <LBRACE> (<IDENTIFIER> [<COMMA>])+ <RBRACE> | <NOTIFICATIONS_TOKEN> <LBRACE> (<IDENTIFIER> [<COMMA>])+ <RBRACE> | <ASSIGN> <LBRACE> <IDENTIFIER> <INTEGER_LITERAL> <RBRACE>)*}// handle the TRAP-TYPE, this is just different enough from// NOTIFICATION-TYPE that I wanted to keep them separatevoid TrapType() : {}{// egpNeighborLoss TRAP-TYPE// ENTERPRISE snmp// VARIABLES { egpNeighAddr }// DESCRIPTION// "An egpNeighborLoss trap signifies that an EGP// neighbor for whom the sending protocol entity// was an EGP peer has been marked down and the// peer relationship no longer obtains."// ::= 5 <IDENTIFIER> <TRAP_TYPE_TOKEN> (<STATUS> <IDENTIFIER> | <DESCRIPTION> <DESCRIPTOR_LITERAL> | <ENTERPRISE_TOKEN> <IDENTIFIER> | <VARIABLES_TOKEN> <LBRACE> (<IDENTIFIER> [<COMMA>])+ <RBRACE> | <ASSIGN> [<LBRACE> <IDENTIFIER>] <INTEGER_LITERAL> [<RBRACE>])*}void TableSequenceOf() :{ Token t;}{ // The AST has to be marked with a table because the index // could be anything from 1 to N, rather than just "0" as with // other OIDS. So the index is saved symbolically. // This means that we have to recognize the following // in the MIB ASN.1 on 3 different declarations // 1) "SEQUENCE OF varTpe" - from table OID // 2) "INDEX { sysORIndex }" from the index OID // 3) "SEQUENCE {...} - has the OID with the index name first // and then mark each one in the AST to retrieve later. // // sysORTable OBJECT-TYPE // SYNTAX SEQUENCE OF SysOREntry // MAX-ACCESS not-accessible // STATUS current // DESCRIPTION // "The (conceptual) table listing the capabilities of the // local SNMPv2 entity acting in an agent role with respect to // various MIB modules. SNMPv2 entities having dynamically- // configurable support of MIB modules will have a // dynamically-varying number of conceptual rows." // ::= { system 9 } // // sysOREntry OBJECT-TYPE // SYNTAX SysOREntry // MAX-ACCESS not-accessible // STATUS current // DESCRIPTION // "An entry (conceptual row) in the sysORTable." // INDEX { sysORIndex } // ::= { sysORTable 1 } // // SysOREntry ::= SEQUENCE { // sysORIndex INTEGER, // sysORID OBJECT IDENTIFIER, // sysORDescr DisplayString, // sysORUpTime TimeStamp <SEQUENCE_TOKEN> <OF_TOKEN> t=<IDENTIFIER> { jjtThis.setName(t.image); }}void IndexOfTable() :{ Token t;}{ // Related to the table decl TableSequenceOf. // This will be the index of a tabel. // INDEX { sysORIndex } // INDEX { atIfIndex, atNetAddress } 2nd index TBD not handled correctly? <INDEX_TOKEN> <LBRACE> t=<IDENTIFIER> (<COMMA> <IDENTIFIER>)* <RBRACE>}// handle identifier :== identifiervoid Assignment() :{ Token t;}{ // quite a few different kinds of identifiers // RouterID ::= IpAddress // AutonomousType ::= OBJECT IDENTIFIER // Metric ::= INTEGER (1..'FFFF'h) // TruthValue ::= INTEGER { true (1), false (2) } // Status ::= INTEGER { enabled (1), disabled (2) } t=<IDENTIFIER> <ASSIGN> (GetTypeIdentifier() | <OBJECT_TOKEN> <IDENTIFIER_TOKEN>) [(<LPAREN> <INTEGER_LITERAL> "." "." <INTEGER_LITERAL> <RPAREN> | <LBRACE> (<IDENTIFIER> <LPAREN> <INTEGER_LITERAL> <RPAREN> [<COMMA>])+ <RBRACE>)] // save the subtype name from the first identifier just like // TextConvention() did // this makes a tree with the subtype in the parent and // the base type in the child. These are put in symbol tables // later so we can get to the right types and output base types // to XML. { jjtThis.setName(t.image); }}void SequenceOfVarsOrTextConvention() : {}{ // both start with identifier :== ObjectIdentifier() <ASSIGN> (SequenceOfVars() | TextConvention())}void SequenceOfVars() #TableOidVars : {}{ // SysOREntry ::= SEQUENCE { // sysORIndex INTEGER, // sysORID OBJECT IDENTIFIER, // sysORDescr DisplayString, // sysORUpTime TimeStamp, // ifDescr OCTET STRING, // tcpConnLocalPort INTEGER (0..65535), // ds1CircuitIdentifier DisplayString (SIZE (0..255)) // (<SEQUENCE_TOKEN> <LBRACE> (IdentifierInSequenceOfVars() ( <IDENTIFIER> ( SizeDeclaration() | <LPAREN> <INTEGER_LITERAL> "." "." <INTEGER_LITERAL> <RPAREN>)* | <OBJECT_IDENTITY> | <OBJECT_TYPE> | <OBJECT_TOKEN> <IDENTIFIER_TOKEN> | <OCTET_TOKEN> <STRING_TOKEN> [SizeDeclaration()]) (<COMMA>)* )+ <RBRACE>) { jjtThis.setName(lastObjectIdentifierToken.image); }}void TextConvention() : {}{ // The TEXTUAL-CONVENTION is different enough from the other declarations // that it merits it's own scanning, even though it does reuse tokens // that other declarations catch. Also, the base type of the declaration // must be saved in the AST and later in the symbol table. The base type // in the example below would be Integer32 and it will be associated with // QueueStates in the symbol table during AST walks. // // QueueStates ::= TEXTUAL-CONVENTION // DISPLAY-HINT "d" // SYNTAX Integer32 { pause(1), start(2) } // STATUS current // DESCRIPTION "The current state a queue is in." // // another way to declare a text convention is // DisplayString ::= OCTET STRING (SIZE (0..255)) <TEXTUAL_CONVENTION_TOKEN> ( <STATUS> <IDENTIFIER> | (<DESCRIPTION> | <REFERENCE_TOKEN>) <DESCRIPTOR_LITERAL> | <DISPLAY_HINT_TOKEN> <DESCRIPTOR_LITERAL> | <OBJECTS_TOKEN> <LBRACE> (<IDENTIFIER> [<COMMA>])+ <RBRACE> | <SYNTAX_TOKEN> (<OBJECT_TOKEN> <IDENTIFIER_TOKEN> | <OCTET_TOKEN> <STRING_TOKEN> [SizeDeclaration()] | GetTypeIdentifier() [( SizeDeclaration() | <LBRACE> (<IDENTIFIER> <LPAREN> <INTEGER_LITERAL> <RPAREN> [<COMMA>])+ <RBRACE> )] ) )+ | <OCTET_TOKEN> <STRING_TOKEN> [SizeDeclaration() | <LBRACE> (<IDENTIFIER> <LPAREN> <INTEGER_LITERAL> <RPAREN> [<COMMA>])+ <RBRACE>] { jjtThis.setName(lastObjectIdentifierToken.image); }}void IdentifierInSequenceOfVars() :{ Token t;}{ // called from SequenceOfVars() // mark each ast node in the sequence t=<IDENTIFIER> { jjtThis.setName(t.image); jjtThis.setIsOidInTable(true); }}void End() : {}{ <END>}void Expression() : {}{ Identifier()}void Identifier() :{ Token t;}{ t=<IDENTIFIER> { jjtThis.setName(t.image); }}void ObjectIdentifier() :{ Token t;}{ t=<IDENTIFIER> { jjtThis.setName(t.image); lastObjectIdentifierToken = t; }}void ParentObjectIdentifier() #Parent :{ Token t;}{ t=<IDENTIFIER> { jjtThis.setParentName(t.image); jjtThis.setName(lastObjectIdentifierToken.image); }}void ChildTextIdentifier() :{ Token t;}{ t=<IDENTIFIER> { jjtThis.setName(t.image); }}void ChildNumericIdentifier() :{ Token t;}{ t=<INTEGER_LITERAL> { jjtThis.setName(t.image); }}// handle the oids after "iso"// mgmt OBJECT IDENTIFIER ::= { iso org(3) dod(6) internet(1) mgmt(2) }void MultipleOids() : {}{ ChildTextIdentifier() <LPAREN> ChildNumericIdentifier() <RPAREN>}// handle// (SIZE (0..255))// (SIZE (0 | 8 | 11))// (SIZE (6))// (SIZE (1 | 4..85))// (1)void SizeDeclaration() : {}{ <LPAREN> ( <SIZE_TOKEN> <LPAREN> (<INTEGER_LITERAL> [ "." "." <INTEGER_LITERAL> ] [ "|" ])+ <RPAREN> | (<INTEGER_LITERAL> ["." "." <INTEGER_LITERAL>] [ "|" ])+ ) <RPAREN>}void Integer() : {}{ <INTEGER_LITERAL>}void IntegerOID() #PartialOID :{ Token t;}{ t = <INTEGER_LITERAL> { jjtThis.setName(t.image); }}// usually called after SYNTAX, e.g. SYNTAX Counter32// also for TextConvention and Assignment to get the child// node in the right place.void GetTypeIdentifier() :{ Token t;}{ t=<IDENTIFIER> { jjtThis.setName(t.image); }}// usually called after ACCESS, e.g. ACCESS read-writevoid GetAccessIdentifier() :{ Token t;}{ t=<IDENTIFIER> { jjtThis.setName(t.image); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -