From: Robert Klemme Date: 2004-09-15T20:24:50+09:00 Subject: Re: Recursive Objects (Arrays) in Ruby "Wandering Mango" schrieb im Newsbeitrag news:slrnckegn0.q4u.drxpxbxx@octothorpe.local... > On 2004-09-14, Robert Klemme wrote: > > > > "Wandering Mango" schrieb im Newsbeitrag > > news:ci5q1d$a9b@odah37.prod.google.com... > >> As a disclaimer, I'm new to object-oriented programming and to Ruby; so > >> I'm not sure if I'm even describing this problem correctly. Here goes: > >> > >> I have an object called "formula" which has properties .string (the > >> original formula), .leftSub, .rightSub (left and right subformula of > >> the original formula) and .characterType (an array identifying each > >> character in .string as being a particular type - e.g., number, letter, > >> and so on). > > > > Assaph answered your problem question, but I'd like to raise another > > question: this looks like an expression tree - possible as outcome of a > > parse stage. It seems to me that the more appropriate storage would be > > (besides the original string) a sequence of tokens per node. > > Thank you. Your analysis is quite perceptive: that is excatly where I > am headed. I'm parsing the original string into substrings, and then > doing the same to them until I get to atomic strings. But if there > is a better way to do this, I'm more than willing to entertain it - > could you tell me a litle bit more about what "a sequence of tokens > per node" is? I googled the phrase, but am not exactly sure what > I am looking for. Thank you. You should probably use a parser generator such as http://raa.ruby-lang.org/project/racc/ and http://raa.ruby-lang.org/project/ruby-yacc/ You'll finde more on the RAA here: http://raa.ruby-lang.org/search.rhtml?search=parser (look out for parser generators). You can find more with Google: http://www.google.com/search?q=%22parser+generator%22+ruby If you search for "parsing theory" you'll find quite some resources on the matter. The classical book about the issue is this: http://www.amazon.com/exec/obidos/tg/detail/-/0201101947 Kind regards robert