228 lines
4.9 KiB
Plaintext
228 lines
4.9 KiB
Plaintext
%parser
|
|
%namespace RFC1157
|
|
%start Mib
|
|
%symbol ObjectType {
|
|
object attrs;
|
|
public string help = "";
|
|
public ObjectType(object b) { attrs=b; }
|
|
}
|
|
%symbol Def {
|
|
public static System.Collections.Hashtable defs = new System.Collections.Hashtable(); // string->Def
|
|
Def parent = null;
|
|
uint ix = 0;
|
|
public string name;
|
|
public string help = "";
|
|
protected System.Collections.Hashtable names = new System.Collections.Hashtable(); // string->Def
|
|
public System.Collections.Hashtable nodes = new System.Collections.Hashtable(); // uint->Def
|
|
public Def this[string s] { get { return (Def)names[s]; }}
|
|
public Def this[uint k] { get { return (Def)nodes[k]; }}
|
|
public uint[] path { get { System.Collections.ArrayList a = new System.Collections.ArrayList();
|
|
for (Def d=this;d!=null;d=d.parent)
|
|
a.Add(d.ix);
|
|
uint[] r = new uint[a.Count];
|
|
for (int j=0;j<a.Count;j++)
|
|
r[j] = (uint)a[a.Count-j-1];
|
|
return r;
|
|
}}
|
|
public string Lookup(uint[] u,int p)
|
|
{
|
|
string s = name;
|
|
if (p>=u.Length)
|
|
return s;
|
|
Def m = this[u[p]];
|
|
if (m!=null)
|
|
return s+"."+m.Lookup(u,p+1);
|
|
while (p<u.Length)
|
|
s += "."+u[p++];
|
|
return s;
|
|
}
|
|
public string[] Kids()
|
|
{
|
|
string[] r = new string[names.Count];
|
|
int j=0;
|
|
System.Collections.IDictionaryEnumerator d = names.GetEnumerator();
|
|
while (d.MoveNext())
|
|
r[j++] = (string)d.Key;
|
|
return r;
|
|
}
|
|
public Def(string i,ObjectType t) {
|
|
name=i;
|
|
Def old = (Def)defs[name];
|
|
if (old!=null) {
|
|
nodes = old.nodes;
|
|
names = old.names;
|
|
parent = old.parent;
|
|
help = old.help;
|
|
ix = old.ix;
|
|
}
|
|
if (t!=null)
|
|
help = t.help;
|
|
defs[name]=this;
|
|
}
|
|
public Def(string i,ObjectType t,Oid e) : this(i,t)
|
|
{
|
|
string b;
|
|
Def p=null;
|
|
uint n = 0;
|
|
for (;e.head!=null;e=e.tail) {
|
|
// Console.WriteLine("Def "+e.head);
|
|
b = e.head.name;
|
|
n = e.head.val;
|
|
Def d = (Def)defs[b];
|
|
if (d==null) {
|
|
d = new Def(b,null);
|
|
d.parent = p;
|
|
if (b=="iso")
|
|
d.ix = (uint)1;
|
|
else if (n!=(uint)9999)
|
|
d.ix = (uint)n;
|
|
}
|
|
p = d;
|
|
}
|
|
parent = p;
|
|
ix = (uint)n;
|
|
p.nodes[n]=this;
|
|
p.names[i]=this;
|
|
}
|
|
}
|
|
%symbol Attrib {
|
|
public object val = null;
|
|
public Attrib(object o) { val=Fix(o); }
|
|
object Fix(object ob)
|
|
{
|
|
if (ob==null || !(ob is String))
|
|
return null;
|
|
string s = (string) ob;
|
|
string[] t = s.Split('\n');
|
|
string r = "";
|
|
for (int j=0;j<t.Length;j++)
|
|
r += t[j].Trim()+" ";
|
|
return r;
|
|
}
|
|
}
|
|
%symbol Attribs {
|
|
string help = "";
|
|
public Attribs tail;
|
|
public Attrib head;
|
|
public Attribs(Attrib h,Attribs t) {
|
|
if (h.val!=null)
|
|
help = (string) h.val;
|
|
else if (tail!=null)
|
|
help = tail.help;
|
|
head=h; tail=t; }
|
|
}
|
|
%symbol Oid {
|
|
public EnumItem head = null;
|
|
public Oid tail;
|
|
public Oid(EnumItem h,Oid t) {
|
|
// Console.WriteLine("Oid "+h);
|
|
head=h; tail=t; }
|
|
}
|
|
%symbol EnumItem {
|
|
public string name;
|
|
public uint val;
|
|
// public override string ToString() { return "EnumItem "+name+" "+val; }
|
|
public EnumItem(string n,uint v) { name=n; val=v;
|
|
// Console.WriteLine("Creating "+this);
|
|
}
|
|
}
|
|
Mib : TYPEID DEFINITIONS IS BEGIN Block END;
|
|
Block : Imports Exports Defs;
|
|
Defs : Def
|
|
| Defs Def
|
|
;
|
|
Def : TYPEID IS Asn Type
|
|
| TYPEID IS OBJECT
|
|
| ID:n ObjectType:t IS '{' Oid:e '}' %Def(n.id,t,e)
|
|
| ID TrapType IS UNSIGNED
|
|
| OBJECT MACRO IS BEGIN MacroBody END
|
|
;
|
|
Asn :
|
|
| '[' TYPEID UNSIGNED ']' TYPEID
|
|
;
|
|
ObjectType : OBJECT Attribs:b %ObjectType(b)
|
|
| OBJECT %ObjectType(null)
|
|
;
|
|
TrapType : TRAP Attribs
|
|
| TRAP
|
|
;
|
|
Attribs : Attrib:a %Attribs(a,null)
|
|
| Attribs:t Attrib:a %Attribs(a,t)
|
|
;
|
|
Type: TYPEID
|
|
| CONVENTION Attribs
|
|
| SEQUENCE '{' Sequence '}'
|
|
| SEQUENCE OF Type
|
|
| TYPEID '{' Enum '}'
|
|
| TYPEID Size
|
|
;
|
|
MacroBody : MacroEntry
|
|
| MacroBody MacroEntry
|
|
;
|
|
MacroEntry : TYPEID TYPEID IS MacroStuff
|
|
| TYPEID TYPEID IS ID '(' TYPEID TYPEID ')'
|
|
| TYPEID IS Values
|
|
;
|
|
MacroStuff : MacroBit
|
|
| MacroStuff MacroBit
|
|
;
|
|
MacroBit : STRING ID '(' TYPEID TYPEID ')'
|
|
| STRING TYPEID
|
|
;
|
|
Values : STRING
|
|
| Values OR STRING
|
|
;
|
|
Attrib: TYPEID STRING
|
|
| TYPEID ID
|
|
| MODULE
|
|
| DESCRIPTION STRING:s %Attrib(s)
|
|
| SYNTAX Type
|
|
| SYNTAX OBJECT
|
|
| TYPEID '{' Enum '}'
|
|
;
|
|
Imports : IMPORTS ImportList ';'
|
|
|
|
|
;
|
|
ImportList : IdList FROM TYPEID
|
|
| ImportList IdList FROM TYPEID
|
|
;
|
|
IdList : ImportId
|
|
| IdList ',' ImportId
|
|
;
|
|
Exports : EXPORTS IdList ';'
|
|
|
|
|
;
|
|
ImportId : ID
|
|
| OBJECT
|
|
| TYPEID
|
|
| CONVENTION
|
|
| TRAP
|
|
;
|
|
Size : '(' SIZE Range ')'
|
|
| Range
|
|
;
|
|
Range : '(' UNSIGNED TO UNSIGNED ')'
|
|
| '(' Alt ')'
|
|
;
|
|
Alt : UNSIGNED
|
|
| Alt OR UNSIGNED
|
|
;
|
|
Sequence : Entry
|
|
| Sequence ',' Entry
|
|
;
|
|
Entry : ID TYPEID
|
|
| ID TYPEID Size
|
|
| ID TYPEID '{' Enum '}'
|
|
| ID OBJECT
|
|
;
|
|
Enum : EnumItem
|
|
| Enum ',' EnumItem
|
|
;
|
|
EnumItem : ID:a '(' UNSIGNED:b ')' %EnumItem(a.id,b.val)
|
|
| ID:a %EnumItem(a.id,(uint)9999)
|
|
| UNSIGNED:a %EnumItem("INTEGER",a.val)
|
|
;
|
|
Oid : %Oid(null,null)
|
|
| EnumItem:a Oid:b %Oid(a,b)
|
|
;
|
|
|