parsing the file using stack