implement parsing algorithm