implemented the main LR parsing algorithm