📄 xmlbifv02.java
字号:
/* Generated By:JavaCC: Do not edit this line. XMLBIFv02.java */
package Parsers.XMLBIFv02;
import InterchangeFormat.*;
import java.util.Vector;
import java.util.Enumeration;
/*
* Definition of the Interchange Format class and its
* variables. The IFBayesNet ifbn contains the
* parsed Bayesian network.
*/
public class XMLBIFv02 extends InterchangeFormat implements XMLBIFv02Constants {
IFBayesNet ifbn;
public IFBayesNet get_ifbn() { return(ifbn); }
String pcdata() throws ParseException {
StringBuffer p = new StringBuffer("");
Token t;
while (true) {
t = getToken(1);
if ((t.kind == 0) || (t.kind == SOT) || (t.kind == EOT)) break;
else { p.append(t.image); getNextToken(); }
}
return(p.toString());
}
void glob_heading() throws ParseException {
Token t;
while (true) {
t = getToken(1);
if (t.kind == 0) break;
else {
if (t.kind == SOT) {
getNextToken(); t = getToken(1);
if (t.kind == BIF) {
getNextToken(); t = getToken(1);
if (t.kind == CT) { getNextToken(); break; }
}
else { getNextToken(); }
}
else { getNextToken(); }
}
getNextToken();
}
}
/*
* THE INTERCHANGE FORMAT GRAMMAR STARTS HERE.
*/
/*
* Basic parsing function. First looks for a Network Declaration,
* then looks for an arbitrary number of VariableDeclaration or
* ProbabilityDeclaration non-terminals. The objects are
* in the vectors ifbn.pvs and ifbn.upfs.
*/
final public void CompilationUnit() throws ParseException {
IFProbabilityVariable pv;
IFProbabilityFunction upf;
OpenTag();
glob_heading();
NetworkDeclaration();
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case SOT:
;
break;
default:
jj_la1[0] = jj_gen;
break label_1;
}
jj_consume_token(SOT);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VARIABLE:
pv = VariableDeclaration();
ifbn.add(pv);
break;
case PROBABILITY:
upf = ProbabilityDeclaration();
ifbn.add(upf);
break;
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
jj_consume_token(EOT);
jj_consume_token(NETWORK);
jj_consume_token(CT);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case EOT:
jj_consume_token(EOT);
jj_consume_token(BIF);
jj_consume_token(CT);
break;
case 0:
jj_consume_token(0);
break;
default:
jj_la1[2] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
final public void OpenTag() throws ParseException {
jj_consume_token(OPENTAG);
}
/*
* Detect and initialize the network.
*/
final public void NetworkDeclaration() throws ParseException {
String s, ss;
Vector properties = new Vector();
jj_consume_token(SOT);
jj_consume_token(NETWORK);
jj_consume_token(CT);
jj_consume_token(SOT);
jj_consume_token(NAME);
s = getString();
jj_consume_token(EOT);
jj_consume_token(NAME);
jj_consume_token(CT);
label_2:
while (true) {
if (jj_2_1(2)) {
;
} else {
break label_2;
}
ss = Property();
properties.addElement(ss);
}
ifbn = new IFBayesNet(s, properties);
}
/*
* Detect a variable declaration.
*/
final public IFProbabilityVariable VariableDeclaration() throws ParseException {
String s;
IFProbabilityVariable pv;
jj_consume_token(VARIABLE);
jj_consume_token(CT);
s = ProbabilityVariableName();
ProbabilityVariableType();
pv = VariableContent(s);
jj_consume_token(EOT);
jj_consume_token(VARIABLE);
jj_consume_token(CT);
{if (true) return(pv);}
throw new Error("Missing return statement in function");
}
final public String ProbabilityVariableName() throws ParseException {
String s;
jj_consume_token(SOT);
jj_consume_token(NAME);
s = getString();
jj_consume_token(EOT);
jj_consume_token(NAME);
jj_consume_token(CT);
{if (true) return(s);}
throw new Error("Missing return statement in function");
}
final public void ProbabilityVariableType() throws ParseException {
String values[] = null;
jj_consume_token(SOT);
jj_consume_token(TYPE);
jj_consume_token(CT);
jj_consume_token(DISCRETE);
jj_consume_token(EOT);
jj_consume_token(TYPE);
jj_consume_token(CT);
}
final public IFProbabilityVariable VariableContent(String name) throws ParseException {
int i;
String s, v, svalues[];
Vector properties = new Vector();
Vector values = new Vector();
Enumeration e;
IFProbabilityVariable pv = new IFProbabilityVariable();
label_3:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case SOT:
;
break;
default:
jj_la1[3] = jj_gen;
break label_3;
}
if (jj_2_2(2)) {
s = Property();
properties.addElement(s);
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case SOT:
v = VariableValue();
values.addElement(v);
break;
default:
jj_la1[4] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
}
pv.set_name(name);
pv.set_properties(properties);
svalues = new String[ values.size() ];
for (e = values.elements(), i = 0; e.hasMoreElements(); i++)
svalues[i] = (String)(e.nextElement());
pv.set_values(svalues);
{if (true) return(pv);}
throw new Error("Missing return statement in function");
}
final public String VariableValue() throws ParseException {
String s;
jj_consume_token(SOT);
jj_consume_token(VALUE);
s = getString();
jj_consume_token(EOT);
jj_consume_token(VALUE);
jj_consume_token(CT);
{if (true) return(s);}
throw new Error("Missing return statement in function");
}
/*
* Detect a probability declaration.
*/
final public IFProbabilityFunction ProbabilityDeclaration() throws ParseException {
String vs[];
IFProbabilityFunction upf = new IFProbabilityFunction();
jj_consume_token(PROBABILITY);
jj_consume_token(CT);
ProbabilityContent(upf);
jj_consume_token(EOT);
jj_consume_token(PROBABILITY);
jj_consume_token(CT);
{if (true) return(upf);}
throw new Error("Missing return statement in function");
}
final public void ProbabilityContent(IFProbabilityFunction upf) throws ParseException {
int i, j;
double def[] = null;
double tab[] = null;
String s, vs[];
IFProbabilityEntry entry = null;
Enumeration e;
Vector fors = new Vector();
Vector givens = new Vector();
Vector properties = new Vector();
Vector entries = new Vector();
Vector defaults = new Vector();
Vector tables = new Vector();
label_4:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case SOT:
;
break;
default:
jj_la1[5] = jj_gen;
break label_4;
}
jj_consume_token(SOT);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case FOR:
s = ProbabilityFor();
fors.addElement(s);
break;
case GIVEN:
s = ProbabilityGiven();
givens.addElement(s);
break;
case SOT:
s = Property();
properties.addElement(s);
break;
case DEFAUL:
def = ProbabilityDefault();
defaults.addElement(def);
break;
case ENTRY:
entry = ProbabilityEntry();
entries.addElement(entry);
break;
case TABLE:
tab = ProbabilityTable();
tables.addElement(tab);
break;
default:
jj_la1[6] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
upf.set_properties(properties);
upf.set_defaults(defaults);
upf.set_entries(entries);
upf.set_tables(tables);
upf.set_conditional_index(fors.size());
vs = new String[ fors.size() + givens.size() ];
for (e = fors.elements(), i = 0; e.hasMoreElements(); i++)
vs[i] = (String)(e.nextElement());
for (e = givens.elements(), j = i; e.hasMoreElements(); j++)
vs[j] = (String)(e.nextElement());
upf.set_variables(vs);
}
final public String ProbabilityFor() throws ParseException {
String s;
jj_consume_token(FOR);
s = getString();
jj_consume_token(EOT);
jj_consume_token(FOR);
jj_consume_token(CT);
{if (true) return(s);}
throw new Error("Missing return statement in function");
}
final public String ProbabilityGiven() throws ParseException {
String s;
jj_consume_token(GIVEN);
s = getString();
jj_consume_token(EOT);
jj_consume_token(GIVEN);
jj_consume_token(CT);
{if (true) return(s);}
throw new Error("Missing return statement in function");
}
final public IFProbabilityEntry ProbabilityEntry() throws ParseException {
int i;
Enumeration e;
String variable_name, vs[];
Vector v_list = new Vector();
double d[];
jj_consume_token(ENTRY);
jj_consume_token(CT);
label_5:
while (true) {
if (jj_2_3(2)) {
;
} else {
break label_5;
}
jj_consume_token(SOT);
jj_consume_token(VALUE);
variable_name = getString();
jj_consume_token(EOT);
jj_consume_token(VALUE);
jj_consume_token(CT);
v_list.addElement(variable_name);
}
d = ProbabilityTable();
jj_consume_token(EOT);
jj_consume_token(ENTRY);
jj_consume_token(CT);
vs = new String[v_list.size()];
for (e=v_list.elements(), i=0; e.hasMoreElements(); i++)
vs[i] = (String)(e.nextElement());
{if (true) return( new IFProbabilityEntry(vs, d) );}
throw new Error("Missing return statement in function");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -