public boolean evaluate(Term term) { return (term instanceof OpSymbol) && (((OpSymbol) term).getTextName().equals(";") || ((OpSymbol) term).getTextName().equals(",")); } };
OpSymbol opSymbol = new OpSymbol(name, textName, associativity, priority); if (opSymbol.isPostfix()) else if (opSymbol.isInfix()) operatorMap.put(opSymbol.getFixity(), opSymbol); if ((operatorMap != null) && opSymbol.isPrefix()) else if ((operatorMap != null) && (opSymbol.isPostfix() || opSymbol.isInfix()))
/** * Provides a copied clone of the symbol. The available symbols that a parser recognizes may be set up in a symbol * table. When an instance of a symbol is encountered it may be desireable to copy the symbol from the table. Using * this method an OpSymbol may act both as a template for symbols and as an individual instance of a symbols * occurance. * * @return A shallow copy of the symbol. */ public OpSymbol copySymbol() { try { return (OpSymbol) clone(); } catch (CloneNotSupportedException e) { throw new IllegalStateException( "Got a CloneNotSupportedException but clone is defined on OpSymbol and should not fail.", e); } }
/** * Reduces by rule 3. * * @throws SourceCodeException With an error location if the action cannot be performed because the input * sequence does not form a valid instance of the grammar. */ public void apply() throws SourceCodeException { // Consume from the state stack for the number of RHS symbols. for (int i = 0; i < NUM_SYMBOLS_RHS; i++) { stack.poll(); } // Attempt to consume an operator and a term in postfix order from the output stack. CandidateOpSymbol candidate = (CandidateOpSymbol) outputStack.poll(); Term t = outputStack.poll(); OpSymbol op = checkAndResolveToFixity(candidate, OpSymbol.Fixity.Post); // Clone the operator symbol from the operator table before adding the unique source code position and // argument for this symbol instance. op = op.copySymbol(); op.setSourceCodePosition(candidate.getSourceCodePosition()); op.setArguments(new Term[] { t }); outputStack.offer(op); } }
if (lastOp.isPostfix()) int comparison = lastOp.compareTo(nextOp); if (nextOp.isLeftAssociative()) else if (nextOp.isRightAssociative()) null, null, null, nextOp.getSourceCodePosition());
if (":-".equals(symbol.getTextName())) List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(1), Functor.class, ",", interner); return new Clause<Functor>((Functor) symbol.getArgument(0), flattenedArgs.toArray(new Functor[flattenedArgs.size()])); else if ("?-".equals(symbol.getTextName())) List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(0), Functor.class, ",", interner);
/** * Reduces by rule 3. * * @throws SourceCodeException With an error location if the action cannot be performed because the input * sequence does not form a valid instance of the grammar. */ public void apply() throws SourceCodeException { // Consume from the state stack for the number of RHS symbols. for (int i = 0; i < NUM_SYMBOLS_RHS; i++) { stack.poll(); } // Attempt to consume an operator and a term in postfix order from the output stack. CandidateOpSymbol candidate = (CandidateOpSymbol) outputStack.poll(); Term t = outputStack.poll(); OpSymbol op = checkAndResolveToFixity(candidate, OpSymbol.Fixity.Post); // Clone the operator symbol from the operator table before adding the unique source code position and // argument for this symbol instance. op = op.copySymbol(); op.setSourceCodePosition(candidate.getSourceCodePosition()); op.setArguments(new Term[] { t }); outputStack.offer(op); } }
if (lastOp.isPostfix()) int comparison = lastOp.compareTo(nextOp); if (nextOp.isLeftAssociative()) else if (nextOp.isRightAssociative()) null, null, null, nextOp.getSourceCodePosition());
if (":-".equals(symbol.getTextName())) List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(1), Functor.class, ",", interner); return new Clause<Functor>((Functor) symbol.getArgument(0), flattenedArgs.toArray(new Functor[flattenedArgs.size()])); else if ("?-".equals(symbol.getTextName())) List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(0), Functor.class, ",", interner);
/** * Reduces by rule 2. * * @throws SourceCodeException With an error location if the action cannot be performed because the input * sequence does not form a valid instance of the grammar. */ public void apply() throws SourceCodeException { // Consume from the state stack for the number of RHS symbols. for (int i = 0; i < NUM_SYMBOLS_RHS; i++) { stack.poll(); } // Attempt to consume a term and an operator in prefix order from the output stack. Term t = outputStack.poll(); CandidateOpSymbol candidate = (CandidateOpSymbol) outputStack.poll(); OpSymbol op = checkAndResolveToFixity(candidate, OpSymbol.Fixity.Pre); // Clone the operator symbol from the operator table before adding the unique source code position and // argument for this symbol instance. op = op.copySymbol(); op.setSourceCodePosition(candidate.getSourceCodePosition()); op.setArguments(new Term[] { t }); // Place the fully parsed, promoted operator back onto the output stack. outputStack.offer(op); } }
OpSymbol opSymbol = new OpSymbol(name, textName, associativity, priority); if (opSymbol.isPostfix()) else if (opSymbol.isInfix()) operatorMap.put(opSymbol.getFixity(), opSymbol); if ((operatorMap != null) && opSymbol.isPrefix()) else if ((operatorMap != null) && (opSymbol.isPostfix() || opSymbol.isInfix()))
/** * Provides a copied clone of the symbol. The available symbols that a parser recognizes may be set up in a symbol * table. When an instance of a symbol is encountered it may be desireable to copy the symbol from the table. Using * this method an OpSymbol may act both as a template for symbols and as an individual instance of a symbols * occurance. * * @return A shallow copy of the symbol. */ public OpSymbol copySymbol() { try { return (OpSymbol) clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException( "Got a CloneNotSupportedException but clone is defined on OpSymbol and should not fail.", e); } }
/** * Reduces by rule 2. * * @throws SourceCodeException With an error location if the action cannot be performed because the input * sequence does not form a valid instance of the grammar. */ public void apply() throws SourceCodeException { // Consume from the state stack for the number of RHS symbols. for (int i = 0; i < NUM_SYMBOLS_RHS; i++) { stack.poll(); } // Attempt to consume a term and an operator in prefix order from the output stack. Term t = outputStack.poll(); CandidateOpSymbol candidate = (CandidateOpSymbol) outputStack.poll(); OpSymbol op = checkAndResolveToFixity(candidate, OpSymbol.Fixity.Pre); // Clone the operator symbol from the operator table before adding the unique source code position and // argument for this symbol instance. op = op.copySymbol(); op.setSourceCodePosition(candidate.getSourceCodePosition()); op.setArguments(new Term[] { t }); // Place the fully parsed, promoted operator back onto the output stack. outputStack.offer(op); } }
/** * Reduces by rule 4. * * @throws SourceCodeException With an error location if the action cannot be performed because the input * sequence does not form a valid instance of the grammar. */ public void apply() throws SourceCodeException { // Consume from the state stack for the number of RHS symbols. for (int i = 0; i < NUM_SYMBOLS_RHS; i++) { stack.poll(); } // Attempt to consume a term, ann operator and a term in infix order from the output stack. Term t1 = outputStack.poll(); CandidateOpSymbol candidate = (CandidateOpSymbol) outputStack.poll(); Term t2 = outputStack.poll(); OpSymbol op = checkAndResolveToFixity(candidate, OpSymbol.Fixity.In); // Clone the operator symbol from the operator table before adding the unique source code position and // argument for this symbol instance. // Note that the order of the arguments is swapped here, because they come off the stack backwards. op = op.copySymbol(); op.setSourceCodePosition(candidate.getSourceCodePosition()); op.setArguments(new Term[] { t2, t1 }); outputStack.offer(op); } }
/** * Reduces by rule 4. * * @throws SourceCodeException With an error location if the action cannot be performed because the input * sequence does not form a valid instance of the grammar. */ public void apply() throws SourceCodeException { // Consume from the state stack for the number of RHS symbols. for (int i = 0; i < NUM_SYMBOLS_RHS; i++) { stack.poll(); } // Attempt to consume a term, ann operator and a term in infix order from the output stack. Term t1 = outputStack.poll(); CandidateOpSymbol candidate = (CandidateOpSymbol) outputStack.poll(); Term t2 = outputStack.poll(); OpSymbol op = checkAndResolveToFixity(candidate, OpSymbol.Fixity.In); // Clone the operator symbol from the operator table before adding the unique source code position and // argument for this symbol instance. // Note that the order of the arguments is swapped here, because they come off the stack backwards. op = op.copySymbol(); op.setSourceCodePosition(candidate.getSourceCodePosition()); op.setArguments(new Term[] { t2, t1 }); outputStack.offer(op); } }