Determining the data type while reading in ints and chars from file

Hello,

I have a program which requires me to read in a tree from a file that comes in this form:

empty tree::= ()
tree::= empty tree | (integer tree tree)

An example of such a tree:

(5 (4(11(7()())(2()())() (8(4()(1()()))(13()())) )

I'm trying to figure out the best way to read in/store the numbers and parentheses. I'm thinking stacks might work, but then I have the problem of discerning between the integers and the parentheses when reading them in. So basically I want to know if there is a way to determine whether a value is an int or a char when reading it in.

Thanks for the help!


EDIT: Thinking about it a little more, I could just put my whole tree into a char stack. But the question still remains, how do I determine whether what I pop is a number or a parenthesis?

EDIT: Or maybe it should be a queue...sorry I'm still in the thinking process as you can see. But still, same question.
Last edited on
Last edited on
Thank You!
Topic archived. No new replies allowed.