📄 slparser.jj
字号:
{return val;}
}
// artificial production, needed to avoid a bad warning from javacc
// val can be either an AbsConcept or an AbsAggregate
void FunctionalTermParameters(AbsConcept val) :
{ AbsTerm t; int slotNumber=0;}
{
( { String slotNames[] = null;
try {
slotNames = curOntology.getSchema(val.getTypeName()).getNames();
} catch (Exception e) {
}
}
(t=Term() {
try {
val.set(slotNames[slotNumber], t);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+slotNumber,t);
}
slotNumber++;
})+ )
| (Parameter(val))+
}
void Parameter(AbsConcept val) :
{ Token t; AbsTerm term; String slotName;}
{
// t.image.substring(1) allows to remove the leading ':' char
( t=<PARAMETERNAME> {slotName = t.image.substring(1);}
| t=<PARAMETERNAME_STRING> {slotName = unescape(t.image.substring(1));} )
term=Term() {val.set(slotName,term);}
}
AbsAgentAction ActionExpression_NoBrace() :
{ AbsAgentAction val=null; AbsTerm term1, term2; Token t;}
{
( t=<ACTION> term1=Term() term2=Term()
{ val = new AbsAgentAction(t.image);
try {
String slotNames[] = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], term1);
val.set(slotNames[1], toAbsAgentAction(term2));
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", term1);
val.set(Codec.UNNAMEDPREFIX+"1", toAbsAgentAction(term2));
}
}
| t=<ACTIONOPLL> {if (slType<2) throw new ParseException("NotFullSL_ActionOperatorExpression_NotParsable");} term1=ActionExpression() term2=ActionExpression()
{ val = new AbsAgentAction(t.image);
try {
String slotNames[] = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], term1);
val.set(slotNames[1], toAbsAgentAction(term2));
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", term1);
val.set(Codec.UNNAMEDPREFIX+"1", toAbsAgentAction(term2));
}
}
)
{ return val;}
}
AbsTerm ActionExpression() :
{ AbsTerm val=null; String s;}
{
( LBrace() val=ActionExpression_NoBrace() RBrace()
| s=MetaSymbol() { AbsVariable val1=new AbsVariable(); val1.setName(s); val1.setIsMetaTerm(true); val=val1;}
)
{return val;}
}
AbsPredicate Wff() :
{ AbsPredicate val=null; String s;}
{
( s=String() { val = new AbsPredicate(s);} // expands to true, false, PropositionSymbol
| LBrace() val=Wff_NoBrace() RBrace()
| s=MetaSymbol() { val=new AbsPredicate(s); val.setIsMetaFormula(true);}
)
{return val;}
}
AbsPredicate Wff_NoBrace() :
{ AbsPredicate arg1, arg2, val=null; Token t; AbsTerm term; String s;
String slotNames[]=null;}
{
( t=<UNARYLOGICALOP> {if (slType<1) throw new ParseException("NotFullSL_NotExpression_NotParsable_UseAtLeastSL1");} arg1=Wff()
{val = new AbsPredicate(t.image);
try {
slotNames = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], arg1);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", arg1);
}
}
| t=<BINARYLOGICALOP> {if (slType<1) throw new ParseException("NotFullSL_BinaryLogicalExpression_NotParsable_UseAtLeastSL1");} arg1=Wff() arg2=Wff()
{val = new AbsPredicate(t.image);
try {
slotNames = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], arg1);
val.set(slotNames[1], arg2);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", arg1);
val.set(Codec.UNNAMEDPREFIX+"1", arg2);
}
}
| t=<QUANTIFIER> {if (slType<2) throw new ParseException("NotFullSL_QuantifierExpression_NotParsable_UseAtLeastSL2"); AbsVariable var; }
var=Variable() arg1=Wff()
{val = new AbsPredicate(t.image);
try {
slotNames = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], var);
val.set(slotNames[1], arg1);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", var);
val.set(Codec.UNNAMEDPREFIX+"1", arg1);
}
}
| t=<MODALOP> {if (slType<2) throw new ParseException("NotFullSL_ModalOperatorExpression_NotParsable_UseAtLeastSL2");} term=Term() arg1=Wff()
{val = new AbsPredicate(t.image);
try {
slotNames = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], term);
val.set(slotNames[1], arg1);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", term);
val.set(Codec.UNNAMEDPREFIX+"1", arg1);
}
}
| t=<ACTIONOP> term=ActionExpression()
{val = new AbsPredicate(t.image);
try {
slotNames = curOntology.getSchema(t.image).getNames();
val.set(slotNames[0], term);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"0", term);
}
}
(arg1=Wff() {
try {
val.set(slotNames[1], arg1);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+"1", arg1);
}
})?
| s=String() {val = new AbsPredicate(s); int slotNumber=0;
try {
slotNames = curOntology.getSchema(s).getNames();
} catch (Exception e) {
}
} (term=Term()
{ try {
val.set(slotNames[slotNumber], term);
} catch (Exception e) {
val.set(Codec.UNNAMEDPREFIX+slotNumber, term);
}
slotNumber++; })+
)
{return val;}
}
AbsPrimitive Number():
{ Token t; AbsPrimitive val = null;}
{
( t = <INTEGER> { long value;
try {
val = AbsPrimitive.wrap(Long.parseLong(t.image));
} catch (NumberFormatException e) { //should never happen
e.printStackTrace();
val=AbsPrimitive.wrap(t.image);
}
}
| t = <HEXINTEGER> { val=AbsPrimitive.wrap(t.image); }
| t = <FLOATONE> { double d1;
try {
// J2ME incompatible d1=Double.parseDouble(t.image);
d1=(new Double(t.image)).doubleValue();
val=AbsPrimitive.wrap(d1);
} catch (NumberFormatException e) { //should never happen
e.printStackTrace();
val=AbsPrimitive.wrap(t.image);
}
}
| t = <FLOATTWO> { double d2;
try {
// J2ME incompatible d2=Double.parseDouble(t.image);
d2=(new Double(t.image)).doubleValue();
val=AbsPrimitive.wrap(d2);
} catch (NumberFormatException e) { //should never happen
e.printStackTrace();
val=AbsPrimitive.wrap(t.image);
}
}
)
{return val;}
}
/**
* <p> <code> String = WORD | STRING_LITERAL </code>
*/
String String() :
{ Token t;}
{
t=<WORD2> {return t.image;}
| t=<STRING_LITERAL2> {if ( (CaseInsensitiveString.equalsIgnoreCase(t.image,"\"true\""))
||(CaseInsensitiveString.equalsIgnoreCase(t.image,"\"false\"")) )
// in this case leading/trailing quotes must be left
// otherwise the value is confused with a boolean
return t.image;
else
return unescape(t.image);}
| t=<WORD> {return t.image;}
| t=<STRING_LITERAL> {if ( (CaseInsensitiveString.equalsIgnoreCase(t.image,"\"true\""))
||(CaseInsensitiveString.equalsIgnoreCase(t.image,"\"false\"")) )
// in this case leading/trailing quotes must be left
// otherwise the value is confused with a boolean
return t.image;
else
return unescape(t.image);}
}
/** This grammar rule is an extension to the FIPA SL Grammar. It is specific to the semantics framework.
It allows to represent a symbol which is not matched by any FIPA-SL token. **/
String MetaSymbol():
{ Token t;}
{
(t=<METASYMBOL> | t=<METASYMBOL2>)
{ if (!metaAllowed) throw new ParseException(META_EXCEPTION_MESSAGE); else return t.image;}
}
/* T O K E N D E F I N I T I O N */
<DEFAULT>
SKIP :
{
" "
| "\t"
| "\n"
| "\r"
}
<DEFAULT>
TOKEN:
{
< LBRACE : "(" > : OPERATORSTATE
| < RBRACE : ")" >
| < VARIABLE : "?" <WORD> | "?" <STRING_LITERAL> >
| < INTEGER : (["+","-"])? (["0"-"9"])+ >
| < HEXINTEGER : (["+","-"])? "0" ["x","X"] (["0"-"9" , "a"-"f" , "A"-"F"])+ >
| < FLOATONE : (["+","-"])? ((["0"-"9"])+ "." (["0"-"9"])* | (["0"-"9"])* "." (["0"-"9"])+)
(["e","E"] (["-","+"])? (["0"-"9"])+)? >
| < FLOATTWO : (["+","-"])? (["0"-"9"])+ ["e","E"] (["-","+"])? (["0"-"9"])+ >
| < WORD: (~["\u0000"-"\u0020","(",")","\"","#","0"-"9",":","-","?"])
(~["\u0000"-"\u0020","(",")","\""])* >
| < STRING_LITERAL:
"\""
( (~["\""]) | "\\\"" )*
"\""
>
| < PARAMETERNAME : ":"<WORD> >
| < PARAMETERNAME_STRING : ":"<STRING_LITERAL> >
| < DATETIME : (["0"-"9"]) (["0"-"9"]) (["0"-"9"]) (["0"-"9"])
(["0"-"9"]) (["0"-"9"]) (["0"-"9"]) (["0"-"9"]) ["t","T"]
(["0"-"9"]) (["0"-"9"]) (["0"-"9"]) (["0"-"9"])
(["0"-"9"]) (["0"-"9"]) (["0"-"9"]) (["0"-"9"]) (["0"-"9"]) (["a"-"z","A"-"Z"])? >
| <PREFIXBYTELENGTHENCODEDSTRING : "#" <INTEGER> "\"" >
{
String tmp = matchedToken.image.substring(1,matchedToken.image.length()-1);
int numBytes = Integer.parseInt(tmp);
if (numBytes < 0) {
throw new TokenMgrError("ERROR: PrefixByteLengthEncodedString with length < 0",
TokenMgrError.STATIC_LEXER_ERROR);
}
char[] bytes = new char[numBytes];
int i = 0;
while (numBytes-- > 0)
try {
bytes[i++] = input_stream.readChar();
}
catch (IOException e) {
System.out.println("IOException during PREFIXBYTELENGTHENCODEDSTRING");
throw new TokenMgrError(true, curLexState, input_stream.getEndLine(),
input_stream.getEndColumn(),input_stream.GetImage(),
curChar, TokenMgrError.LEXICAL_ERROR);
}
// If you want, you can add bytes to matchedToken.image here.
matchedToken.image = new String(bytes);
}
| <METASYMBOL : "??"<WORD> > //see javadoc of method MetaSymbol()
}
<OPERATORSTATE>
SKIP :
{
" "
| "\t"
| "\n"
| "\r"
}
<OPERATORSTATE>
TOKEN:
{
< LBRACE2 : "(" > : OPERATORSTATE
| < RBRACE2 : ")" > : DEFAULT
| < ACTION : "action" > : DEFAULT
| < REFERENTIALOP : "iota" | "any" | "all" > : DEFAULT
| < MODALOP : "B" | "U" | "PG" | "I" > : DEFAULT
| < ARITHMETICOP : "+" | "-" | "*" | "/" | "%" > : DEFAULT
| < ACTIONOP : "feasible" | "done" > : DEFAULT
| < ACTIONOPLL : "|" | ";" > : DEFAULT // action operator low level
| < UNARYLOGICALOP : "not" > : DEFAULT
| < BINARYLOGICALOP : "and" | "or" | "implies" | "equiv" > : DEFAULT
| < QUANTIFIER : "forall" | "exists" > : DEFAULT
| < WORD2: (~["\u0000"-"\u0020","(",")","\"","#","0"-"9",":","-","?"])
(~["\u0000"-"\u0020","(",")","\""])* > : DEFAULT
| < STRING_LITERAL2:
"\""
( (~["\""]) | "\\\"" )*
"\""
> :DEFAULT
| <METASYMBOL2 : "??"<WORD2> > : DEFAULT //see javadoc of method MetaSymbol()
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -