import re


def get_nt_seq(ptrn_wrds, nt_list, implied_nt=None):
    """
    @param ptrn_wrds: [string] - list of tokens of pattern string of an 
    instruction (result of split() on pattern string)
    
    @param nt_list: [string] - list of strings which are names of NTs that
    we look for in the pattern
    
    @param implied_nt: string - name of an NT which is prepended to the
    output list this NT is implied and doesn't appear in the instruction's 
    pattern (e.g. OSZ_NONTERM) 

    @return: a list of strings which are names of NTs from nt_list that 
    were found in ptrn_wrds first NT is implied default NT (for EOSZ for
    example it's OSZ_NONTERM)
    """
    seq = []
    if implied_nt:
        seq.append(implied_nt)
         
    for w in ptrn_wrds:
        no_brackets = re.sub('[(][)]', '',w)
        if no_brackets in nt_list:
            seq.append(no_brackets)
    return seq