com.singularsys.jep.misc.lineNumbering

## Class LineNumberingShuntingYard

- java.lang.Object
- - com.singularsys.jep.configurableparser.ShuntingYard
  - - com.singularsys.jep.misc.lineNumbering.LineNumberingShuntingYard

- All Implemented Interfaces:
    GrammarParser

      public class LineNumberingShuntingYard
      extends ShuntingYard

  Version of the shunting yard algorithm which sets lines numbers in the parse tree. By convention numbering starts from line 1 column 1. Must be used with the ConfigurableParser and LineNumberingNodeFactory.

      Jep jep = new Jep(
        new StandardConfigurableParser(),
        new LineNumberingNodeFactory(),
        new LineNumberingShuntingYard.LineNumberGrammarParserFactory());

  Since:
    3.4.0
  Author:
    rich
  See Also:
    `LineNumberingNodeFactory`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `LineNumberingShuntingYard.LineNumberGrammarParserFactory`

    - ### Nested classes/interfaces inherited from class com.singularsys.jep.configurableparser.ShuntingYard

      `ShuntingYard.PrefixRes, ShuntingYard.ShuntingYardGrammarParserFactory`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Stack<com.singularsys.jep.misc.lineNumbering.LineNumberingShuntingYard.Position>` | `posns` Stack to track positions when pushing and popping operators

    - ### Fields inherited from class com.singularsys.jep.configurableparser.ShuntingYard

      `DUMP, implicitMul, it, jep, matchers, nf, nodes, ops, sentinel`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LineNumberingShuntingYard(Jep jep, java.util.List<GrammarMatcher> gm)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Node` | `parseSubExpression()` Callback function used by GrammerMatchers
    `protected void` | `popOp()` Pops an operator off the Operator stack, and creates a new node.
    `protected void` | `prefix()` Matches identifies, numbers, prefix operators and plugged in grammar matchers.
    `protected void` | `pushOp(Operator op, Token tok)` The pushOp function is worth some explanation Say 1+2*3 is parsed.

    - ### Methods inherited from class com.singularsys.jep.configurableparser.ShuntingYard

      `compareOps, dumpState, expression, getIterator, parse, parsePrefixSuffix, prefixSuffix, prefixSuffixUnchecked, prefixUnchecked, setIterator`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### posns

          protected java.util.Stack<com.singularsys.jep.misc.lineNumbering.LineNumberingShuntingYard.Position> posns

      Stack to track positions when pushing and popping operators

  - ### Constructor Detail

    - #### LineNumberingShuntingYard

          public LineNumberingShuntingYard(Jep jep,
                                           java.util.List<GrammarMatcher> gm)

      Constructor
      Parameters:
        `jep` -
        `gm` -

  - ### Method Detail

    - #### parseSubExpression

          public Node parseSubExpression()
                                  throws ParseException

      Description copied from class: `ShuntingYard`
      Callback function used by GrammerMatchers
      Specified by:
        `parseSubExpression` in interface `GrammarParser`
      Overrides:
        `parseSubExpression` in class `ShuntingYard`
      Returns:
        node tree
      Throws:
        `ParseException` - if the input cannot be parsed

    - #### popOp

          protected void popOp()
                        throws ParseException

      Description copied from class: `ShuntingYard`
      Pops an operator off the Operator stack, and creates a new node. The children of the node are poped off the node stack and the result is pushed onto the node stack.
      Overrides:
        `popOp` in class `ShuntingYard`
      Throws:
        `ParseException`

    - #### prefix

          protected void prefix()
                         throws ParseException

      Description copied from class: `ShuntingYard`
      Matches identifies, numbers, prefix operators and plugged in grammar matchers. Wrapper function around the `ShuntingYard.prefixUnchecked()`
      Overrides:
        `prefix` in class `ShuntingYard`
      Throws:
        `ParseException` - if input fails to match or error construction node tree

    - #### pushOp

          protected void pushOp(Operator op,
                                Token tok)
                         throws ParseException

      Description copied from class: `ShuntingYard`
      The pushOp function is worth some explanation Say 1+2*3 is parsed. First + is pushed onto the stack, then * is pushed. For 1*2+3. * is pushed, when + is encountered * has tighter precedence so it and the top two elements from the node stack are popped, the result computed and pushed on the node stack. Special cases -1+2 [uminus,+],[1] -> [+],[-1] -> [+],[-1,2] -> [],[(-1)+2] -1^2 [uminus,^],[1] -> [uminus,^],[1] -> [uminus,^],[1,2] -> [uminus],[1^2] -> [],[-(1^2)] 1^-2 [^],[1] -> [^,uminus],[1] ->[^,uminus],[1,2] -> [^],[1,(-2)] ->[],[1^(-2)]
      Overrides:
        `pushOp` in class `ShuntingYard`
        `tok` - Token operator came from
      Throws:
        `ParseException`

Copyright © 2018 Singular Systems http://www.singularsys.com/jep