Constructing formal expressions by regular grammar