📄 jshop2parser.java
字号:
Token vn = null; //-- 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; if ((LA(1)==NIL)) { match(NIL); //-- Empty logical expression. retVal = new LogicalExpressionNil(); } else if ((LA(1)==LP) && (_tokenSet_8.member(LA(2)))) { match(LP); { switch ( LA(1)) { case AND: { match(AND); break; } case LP: case RP: case NIL: case VARID: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { _loop47: do { if ((_tokenSet_4.member(LA(1)))) { lExp=le(); //-- Add the current conjunct to the list of conjuncts. vec.add(lExp); } else { break _loop47; } } while (true); } //-- 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); match(RP); } else if ((LA(1)==LP) && (LA(2)==OR)) { match(LP); match(OR); { int _cnt49=0; _loop49: do { if ((_tokenSet_4.member(LA(1)))) { lExp=le(); //-- Add the current disjunct to the list of disjuncts. vec.add(lExp); } else { if ( _cnt49>=1 ) { break _loop49; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt49++; } while (true); } //-- 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); match(RP); } else if ((LA(1)==LP) && (LA(2)==NOT)) { match(LP); match(NOT); lExp=le(); match(RP); //-- A negative logical expression. retVal = new LogicalExpressionNegation(lExp); } else if ((LA(1)==LP) && (LA(2)==IMPLY)) { match(LP); match(IMPLY); lExp=le(); lExp2=le(); match(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); } else if ((LA(1)==LP||LA(1)==VARID) && (_tokenSet_9.member(LA(2)))) { p=la(); //-- An atomic logical expression. retVal = new LogicalExpressionAtomic(p); } else if ((LA(1)==LP) && (LA(2)==FORALL)) { match(LP); match(FORALL); { switch ( LA(1)) { case LP: { { match(LP); { _loop53: do { if ((LA(1)==VARID)) { match(VARID); } else { break _loop53; } } while (true); } match(RP); } break; } case NIL: { match(NIL); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } lExp=le(); lExp2=le(); match(RP); //-- A ForAll logical expression retVal = new LogicalExpressionForAll(lExp, lExp2); } else if ((LA(1)==LP) && (LA(2)==ASSIGN)) { match(LP); match(ASSIGN); vn = LT(1); match(VARID); t=term(); match(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); } else if ((LA(1)==LP) && (LA(2)==CALL)) { match(LP); match(CALL); func=fid(); param=terml(); match(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)); } else { throw new NoViableAltException(LT(1), getFilename()); } return retVal; } public final TaskAtom ta() throws RecognitionException, TokenStreamException { TaskAtom retVal; Token ctn = null; Token stn = null; //-- Whether or not this is an immediate task atom. boolean immediate = false; //-- Whether or not this is a primitive task atom. boolean isPrimitive; //-- The argument list of this task atom. List param; //-- The index of the head of this task atom. int tn; match(LP); { switch ( LA(1)) { case IMMEDIATE: { match(IMMEDIATE); //-- This is an immediate task. immediate = true; break; } case ID: case OPID: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1)) { case ID: { ctn = LT(1); match(ID); //-- Add this compound task to the list of compound tasks in the //-- domain. tn = domain.addCompoundTask(ctn.getText().toLowerCase()); isPrimitive = false; break; } case OPID: { stn = LT(1); match(OPID); //-- Add this primitive task to the list of primitive tasks in the //-- domain. tn = domain.addPrimitiveTask(stn.getText().toLowerCase()); isPrimitive = true; break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } param=terml(); //-- Create the object that represents this task atom. retVal = new TaskAtom( new Predicate(tn, vars.size(), new TermList(param)), immediate, isPrimitive); match(RP); return retVal; } public final String fid() throws RecognitionException, TokenStreamException { String retVal; Token id = null; switch ( LA(1)) { case ID: { id = LT(1); match(ID); retVal = id.getText(); break; } case DIV: { match(DIV); retVal = "StdLib.div"; break; } case EQUAL: { match(EQUAL); retVal = "StdLib.equal"; break; } case LESS: { match(LESS); retVal = "StdLib.less"; break; } case LESSEQ: { match(LESSEQ); retVal = "StdLib.lessEq"; break; } case MEMBER: { match(MEMBER); retVal = "StdLib.member"; break; } case MINUS: { match(MINUS); retVal = "StdLib.minus"; break; } case MORE: { match(MORE); retVal = "StdLib.more"; break; } case MOREEQ: { match(MOREEQ); retVal = "StdLib.moreEq"; break; } case MULT: { match(MULT); retVal = "StdLib.mult"; break; } case NOTEQ: { match(NOTEQ); retVal = "StdLib.notEq"; break; } case PLUS: { match(PLUS); retVal = "StdLib.plus"; break; } case POWER: { match(POWER); retVal = "StdLib.power"; break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } return retVal; } public static final String[] _tokenNames = { "<0>", "EOF", "<2>", "NULL_TREE_LOOKAHEAD", "LP", "\"defproblem\"", "ID", "RP", "\"nil\"", "\"defdomain\"", "METHOD", "OPERATOR", "OPID", "VARID", "PROTECTION", "\"forall\"", "AXIOM", "UNORDERED", "IMMEDIATE", "FIRST", "SORT", "\"and\"", "\"or\"", "\"not\"", "\"imply\"", "\"assign\"", "\"call\"", "NUM", "DOT", "DIV", "EQUAL", "LESS", "LESSEQ", "\"member\"", "MINUS", "MORE", "MOREEQ", "MULT", "NOTEQ", "PLUS", "POWER", "\"def-problem-set\"", "\"stdlib\"", "WS", "COMMENT" }; private static final long[] mk_tokenSet_0() { long[] data = { 131472L, 0L}; return data; } public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0()); private static final long[] mk_tokenSet_1() { long[] data = { 266304L, 0L}; return data; } public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1()); private static final long[] mk_tokenSet_2() { long[] data = { 8528L, 0L}; return data; } public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2()); private static final long[] mk_tokenSet_3() { long[] data = { 134226256L, 0L}; return data; } public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3()); private static final long[] mk_tokenSet_4() { long[] data = { 8464L, 0L}; return data; } public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4()); private static final long[] mk_tokenSet_5() { long[] data = { 132162000L, 0L}; return data; } public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5()); private static final long[] mk_tokenSet_6() { long[] data = { 402661840L, 0L}; return data; } public static final BitSet _tokenSet_6 = new BitSet(mk_tokenSet_6()); private static final long[] mk_tokenSet_7() { long[] data = { 8400L, 0L}; return data; } public static final BitSet _tokenSet_7 = new BitSet(mk_tokenSet_7()); private static final long[] mk_tokenSet_8() { long[] data = { 2105744L, 0L}; return data; } public static final BitSet _tokenSet_8 = new BitSet(mk_tokenSet_8()); private static final long[] mk_tokenSet_9() { long[] data = { 8656L, 0L}; return data; } public static final BitSet _tokenSet_9 = new BitSet(mk_tokenSet_9()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -