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

📄 jshop2.g

📁 SHOP2 一个人工智能里面关于任务分解和任务规划的系统。JSHOP2是其java版本。
💻 G
📖 第 1 页 / 共 2 页
字号:
          tn = domain.addPrimitiveTask(stn.getText().toLowerCase());          isPrimitive = true;        }    )    param = terml      {        //-- Create the object that represents this task atom.        retVal = new TaskAtom(                              new Predicate(tn,                                            vars.size(),                                            new TermList(param)),                              immediate,                              isPrimitive);      }  RP;//------------------------------- Logical precondition --------------//-- Logical Preconditionlp returns [LogicalPrecondition retVal]  {    //-- The logical expression associated with this logical precondition.    LogicalExpression lExp;    //-- The name of the function used in a :sort-by logical precondition.    String func = null;  }:  lExp = le    {      //-- Create the object that represents this logical precondition.      retVal = new LogicalPrecondition(lExp, false);    }|  LP FIRST lExp = le RP    {      //-- Create the object that represents this logical precondition.      retVal = new LogicalPrecondition(lExp, true);    }|  LP SORT vn:VARID (func = fid)? lExp = le RP    {      String s = vn.getText().toLowerCase();      //-- Add the variable to the variable list.      if (!vars.contains(s))        vars.add(s);      //-- If no function is specified, use '<' as the default function.      if (func == null || func.equals("StdLib.less"))        func = "new CompLess(" + vars.indexOf(s) + ")";      else if (func.equals("StdLib.more"))        func = "new CompMore(" + vars.indexOf(s) + ")";      else        func = "new " + func + "(" + vars.indexOf(s) + ")";      //-- Create the object that represents this logical precondition.      retVal = new LogicalPrecondition(lExp, func);    };//-- Logical Expressionle returns [LogicalExpression retVal]  {    //-- A Vector of conjuncts/disjuncts.    Vector<LogicalExpression> vec = new Vector<LogicalExpression>();    //-- The name of the function called in a call term.    String func;    //-- The current logical expression.    LogicalExpression lExp, lExp2;    //-- The logical atom, in case logical expression is an atomic one.    Predicate p;    //-- The argument list of the function call.    List param;    //-- The term a variable is assigned to in an assign term.    Term t;  }:  NIL    {      //-- Empty logical expression.      retVal = new LogicalExpressionNil();    }|  LP    (AND)?    (      lExp = le        {          //-- Add the current conjunct to the list of conjuncts.          vec.add(lExp);        }    )*    {      //-- If there are no conjuncts, return an empty logical expression.      if (vec.size() == 0)        retVal = new LogicalExpressionNil();      //-- If there is only one conjunct, return an atomic logical expression.      else if (vec.size() == 1)        retVal = vec.get(0);      //-- If there are more than one conjuncts, return a conjunction.      else        retVal = new LogicalExpressionConjunction(vec);    }  RP|  LP    OR    (      lExp = le        {          //-- Add the current disjunct to the list of disjuncts.          vec.add(lExp);        }    )+    {      //-- If there is only one disjunct, return an atomic logical expression.      if (vec.size() == 1)        retVal = vec.get(0);      //-- If there are more than one disjuncts, return a disjunction.      else        retVal = new LogicalExpressionDisjunction(vec);    }  RP|  LP NOT lExp = le RP    {      //-- A negative logical expression.      retVal = new LogicalExpressionNegation(lExp);    }|  LP IMPLY lExp = le lExp2 = le RP  {    //-- A logical implication.    //-- To hold the disjuncts of the disjunction equivalent to this logical    //-- implication.    Vector<LogicalExpression> disjunction = new Vector<LogicalExpression>();    //-- The first disjunct is the negation of the premise of the implication.    disjunction.add(new LogicalExpressionNegation(lExp));    //-- The second disjunct is the consequence of the implication.    disjunction.add(lExp2);    //-- Each implication is equivalent to the disjunction of the negation of    //-- its premise and its consequence.    retVal = new LogicalExpressionDisjunction(disjunction);  }|  p = la  {    //-- An atomic logical expression.    retVal = new LogicalExpressionAtomic(p);  }|  LP FORALL  (    (LP (VARID)*  RP)  |    NIL  ) lExp = le lExp2 = le RP  {    //-- A ForAll logical expression    retVal = new LogicalExpressionForAll(lExp, lExp2);  }|  LP ASSIGN vn:VARID t = term RP    {      String s = vn.getText().toLowerCase();      //-- Add the variable to the variable list.      if (!vars.contains(s))        vars.add(s);      //-- An assigment logical expression.      retVal = new LogicalExpressionAssignment(vars.indexOf(s), t);    }|  LP CALL func = fid param = terml RP    {      //-- If this function call is not one implemented in the standard      //-- library, add it to the list of user-defined external code calls.      if (!func.startsWith("StdLib."))      {        domain.addCalc(func);        func = domain.getName() + ".calculate" + func;      }      //-- A call logical expression.      retVal = new LogicalExpressionCall(new TermCall(param, func));    };//-- Logical Atomla returns [Predicate retVal]  {    //-- The argument list of the logical atom.    List l;  }:  LP pn:ID l = terml    {      //-- Add the constant symbol to the list of constant symbols in the      //-- domain.      int index = domain.addConstant(pn.getText().toLowerCase());      //-- Create the logical atom.      retVal = new Predicate(index, vars.size(), new TermList(l));    }  RP|  var:VARID    {      //-- Create the variable predicate (i.e., a predicate that is only a      //-- variable at compile time, but will be bound to a predicate at run      //-- time.      retVal = new Predicate(vars.indexOf(var.getText().toLowerCase()),                             vars.size());    };//------------------------------- Term ------------------------------//-- Term Listterml returns [List retVal] :  {    //-- A LinkedList to store the terms in the term list.    LinkedList<Term> list = new LinkedList<Term>();    //-- The current term.    Term tn;  }  (    tn = term      {        //-- Add the current term to the list of terms seen so far.        list.addFirst(tn);      }  )*  {    //-- Create the object that represents this term list.    retVal = List.MakeList(list);  };//-- Termterm returns [Term retVal]  {    //-- The name of the function called in a call term.    String func;    //-- The term list.    List list;    //-- The current term.    Term tn;    retVal = null;  }:  vn:VARID    {      //-- Add the variable symbol to the variable list.      if (!vars.contains(vn.getText().toLowerCase()))        vars.add(vn.getText().toLowerCase());      //-- Create the object that represents this variable symbol.      retVal = new TermVariable(vars.indexOf(vn.getText().toLowerCase()));    }|  in:ID    {      //-- Add the constant symbol to the list of constant symbols in the      //-- domain.      int index = domain.addConstant(in.getText().toLowerCase());      //-- Create the object that represents this constant symbol.      retVal = new TermConstant(index);    }|  num:NUM    {      //-- Create the object that represents this numerical term.      retVal = new TermNumber(Double.parseDouble(num.getText().toLowerCase()));    }|  LP list = terml    (      DOT tn = term        {          //-- Append the current term to the end of the term list.          retVal = new TermList(list.append(tn));        }    )?    {      //-- If retVal is not already created, create it as a list term.      if (retVal == null)        retVal = new TermList(list);    }  RP|  NIL    {      //-- Empty list term.      retVal = TermList.NIL;    }|  LP CALL func = fid list = terml RP    {      //-- If this function call is not one implemented in the standard      //-- library, add it to the list of user-defined external code calls.      if (!func.startsWith("StdLib."))      {        domain.addCalc(func);        func = domain.getName() + ".calculate" + func;      }      //-- Create the object that represents this call term.      retVal = new TermCall(list, func);    };//-- Function IDfid returns [String retVal] :  id:ID    {      retVal = id.getText();    }|  DIV    {      retVal = "StdLib.div";    }|  EQUAL    {      retVal = "StdLib.equal";    }|  LESS    {      retVal = "StdLib.less";    }|  LESSEQ    {      retVal = "StdLib.lessEq";    }|  MEMBER    {      retVal = "StdLib.member";    }|  MINUS    {      retVal = "StdLib.minus";    }|  MORE    {      retVal = "StdLib.more";    }|  MOREEQ    {      retVal = "StdLib.moreEq";    }|  MULT    {      retVal = "StdLib.mult";    }|  NOTEQ    {      retVal = "StdLib.notEq";    }|  PLUS    {      retVal = "StdLib.plus";    }|  POWER    {      retVal = "StdLib.power";    };//------------------------------- Lexer -----------------------------class JSHOP2Lexer extends Lexer;//------------------------------- Options ---------------------------options{  charVocabulary = '\0'..'\377';  exportVocab = JSHOP2;  testLiterals = false;  k = 4;  caseSensitive = false;  caseSensitiveLiterals = false;}//-- Keywordstokens{  AND            = "and";  ASSIGN         = "assign";  CALL           = "call";  DEFDOMAIN      = "defdomain";  DEFPROBLEM     = "defproblem";  DEFPROBLEMSET  = "def-problem-set";  FORALL         = "forall";  IMPLY          = "imply";  MEMBER         = "member";  NIL            = "nil";  NOT            = "not";  OR             = "or";  STDLIB         = "stdlib";}//-- Grammar TerminalsAXIOM       : ":-";DIV         : '/';DOT         : '.';EQUAL       : '=';LESS        : '<';LESSEQ      : "<=";LP          : '(';MINUS       : '-' WS;MORE        : '>';MOREEQ      : ">=";MULT        : '*';NOTEQ       : "!=";PLUS        : '+' WS;POWER       : '^';RP          : ')';FIRST       : ":first";IMMEDIATE   : ":immediate";METHOD      : ":method";OPERATOR    : ":operator";PROTECTION  : ":protection";SORT        : ":sort-by";UNORDERED   : ":unordered";//-- Whitespace (ignored)WS :  (    ' '  |    '\t'  |    '\f'  |    //-- Handle newlines    (      "\r\n"  //-- DOS    |      '\r'    //-- Macintosh    |      '\n'    //-- Unix    )      {        newline();      }  )  {    $setType(Token.SKIP);  };//-- Comments, LISP style (ignored)COMMENT :  ';' (~('\n' | '\r'))*  {    $setType(Token.SKIP);  };//-- IdentifierID  options  {    testLiterals = true;   //-- Keywords can't be used as identifiers  }:  ('a'..'z' | '_') ('a'..'z' | '-' | '_' | '?' | '!' | '0'..'9')*;//-- Operator nameOPID :  '!' ('a'..'z' | '-' | '_' | '?' | '!' | '0'..'9')*;//-- Variable symbol identifierVARID :  '?' ('a'..'z' | '-' | '_' | '?' | '!' | '0'..'9')*;//-- Numerical valueNUM :  ('-' | '+')? ('0'..'9')+ ('.' ('0' .. '9')+)? ('e' ('-' | '+')? ('0' .. '9')+ )?;

⌨️ 快捷键说明

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