If you plan to allow the input to something complicated consider using something like flex http://flex.sourceforge.net/ for the parsing.