getToken method

TerminalNode? getToken(
  1. int ttype,
  2. int i
)
inherited

Implementation

TerminalNode? getToken(int ttype, int i) {
  if (children == null || i < 0 || i >= children!.length) {
    return null;
  }

  var j = -1; // what token with ttype have we found?
  for (var o in children!) {
    if (o is TerminalNode) {
      final tnode = o;
      final symbol = tnode.symbol;
      if (symbol.type == ttype) {
        j++;
        if (j == i) {
          return tnode;
        }
      }
    }
  }

  return null;
}