Learning algorithm and related code for tier-based strictly local languages