added nonterm() and expand() routines, had a bash at some logic in parser() routine