Learnt a lot about gdb, there is some weird bug where when the function lval_num is called it is setting the type to some random gibberish, this in turn is causing a seg fault when reaching the print part of the program. Weird.