⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slparser.jj

📁 人工智能中Agent开发包。多 Agent 系统是处理自治 Agent 之间知识层的协作问题
💻 JJ
📖 第 1 页 / 共 2 页
字号:
           val.set(Codec.UNNAMEDPREFIX+"1", term2);
        }
    }	
  | s=String() {
      if ( (SLCodec.SET.equalsIgnoreCase(s)) || (SLCodec.SEQUENCE.equalsIgnoreCase(s))) 
         val = new AbsAggregate(s);  
      else 
         val = new AbsConcept(s);}
   (FunctionalTermParameters(val))?
 )
 {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;}
{
 t=<PARAMETERNAME> term=Term() {val.set(t.image.substring(1),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;}
}


AbsAgentAction ActionExpression() :
{ AbsAgentAction val=null; }
{ 
  LBrace() val=ActionExpression_NoBrace() RBrace()
  {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()
 )
 {return val;}
}

AbsPredicate Wff_NoBrace() :
{ AbsPredicate arg1, arg2, val=null; Token t; AbsTerm term; String s;
  AbsAgentAction act; 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> act=ActionExpression() 
   {val = new AbsPredicate(t.image); 
    try {
	   slotNames = curOntology.getSchema(t.image).getNames();
	   val.set(slotNames[0], act);
        } catch (Exception e) {
           val.set(Codec.UNNAMEDPREFIX+"0", act);
        }
   }
   (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>  {return unescape(t.image);}
 | t=<WORD>		{return t.image;}            
 | t=<STRING_LITERAL>	{return unescape(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> | ":"<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"])? > 
}


<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
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -