/** * 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 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); } }
/** * 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); } }
/** * 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); } }