code: function dfs(states, tokens) {
    let root = states[0].reduce((best, curr) => {
      if (best == null || curr.origin > best.origin) {
        return curr;
      }
      return best;
    }, null);
  
    if (root == null) {
      throw new SyntaxError(`Parsing error near '${tokens[0]}' `);
    }
    if (root.origin !== tokens.length) {
      throw new SyntaxError(`Parsing error near '${tokens[root.origin]}' `);
    }
  
    return {
      item    : root.rule,
      children: dfsHelper(states, root, 0, 0, tokens)
    };
  }
docs: Performs a depth-first search on the chart generated by {@link #earley()} in
  order to construct a parse tree, an example of which is shown below
  
  @example
  {
  item: <Rule sum -> [factor, '+', factor]>,
  children: [
  {     // first symbol - 'factor'
  item: <Rule factor -> [/\d+/]>,
  children: [
  '2'
  ]
  },
  '+',  // second symbol
  {     // third symbol - another 'factor'
  item: <Rule factor -> [/\d+/]>,
  children: [
  '3'
  ]
  }
  ]
  }
  
  @function dfs
  @memberof module:lib/parser
  @param {state[]} states - Set of lists of earley items
  @param {string[]} tokens - Input tokens to be parsed
  @return {object} Root node of the parse tree