transforming output into a linked list of tokens