From: Dylan Evans Date: 2009-02-26T11:55:01+09:00 Subject: Re: Nexus Programming Language --0016e652f7145f1ff50463c97d57 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Feb 26, 2009 at 8:53 AM, Chad Perrin wrote: > On Wed, Feb 25, 2009 at 03:57:48PM +0900, Dylan Evans wrote: > > On Wed, Feb 25, 2009 at 8:30 AM, Chad Perrin > wrote: > > > > > > More than that -- and still relevant today -- parsers for Polish > notation > > > are generally more difficult to *write*. I know -- I've tried > designing > > > both Polish notation parsers and RPN parsers. In fact, Polish notation > > > parsers are more difficult to write for essentially the same reason > that > > > RPN parsers are slightly more efficient from the machine's point of > view. > > > > That's seems funny because bison uses RPN as an example. The syntax isn't > > complex and once you have tokens you just need to shift the values onto a > > stack and when an operator comes along you just apply it to the last two > > values then push the result. Or you can create a tree where each value > > becomes a node and the following operation the parent. > > I'm not sure how that "seems funny", considering you just confirmed some > of what I said -- that RPN parsers are easier to write than Polish > notation parsers. My mistake, i thought you were saying the opposite of that. None the less it sounds like a challenge. I guess the easiest way would be to read tokens into an array and then parse them as RPN, but that's not very elegant besides being a little harder. So i'll come back to using a tree, presumably were using ruby since this is a ruby list so i would choose to implement my branch nodes as Hashs of the form; { :op => '+', : lval => 7, :rval => 8 } There are two ways to do it from here, but in both you read the tokens creating a node if an operator is read or by populating it's values, the difference is whether you choose to evaluate a node when it's complete or the whole expression when it is finished. Is that more complex? I'm not really sure, i think i'll write it up when i finish work. -- The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum --0016e652f7145f1ff50463c97d57--