Cleaned up array handling and reduced code by generalising. Only issue remaining is sorting precedence with parenthesis and getting array ids to print correctly in the read and assign statements :/