Newsgroups: comp.compilers
From: gra...@maths.su.oz.au (Graham Matthews)
Date: Sat, 23 May 1992 05:40:38 GMT
Local: Sat, May 23 1992 1:40 am
Subject: Re: Operator precedence and Recursive Descent
(Tucker Taft) writes: There are numerous ways of doing this. I once wrote a one routine >There has been some discussion of the problem of "recursive plunge" when a >language has many levels of operator precedence. We found a neat trick >that solves this problem in the "lcc" compiler recently made available by >David Hanson. >It works best in recursive descent parsers because it is so easy to pass >additional parameters: > 1) Have exactly one function for parsing operator expressions > 2) Pass it the precedence at which to stop accumulating operators expression parser. I don't remember exact details (it was a while back) but from memory it worked something like this .. I had a table of operator precedences. The routine built a parse tree by re-ordering the parse tree if the just seen operator was of higher precedence than (I think) the root of the existing parse tree. If I remember rightly the re-ordering was very efficient as it always b) new_node = latest_operator b) new_root = old_root.operator So the whole rotuine worked like (initial parser tree = first operand) So for example say we have the expression a + b * c The routine builds the tree + Then the rotuine sees '* c' and re-orders the tree as follows, new_node = * new_root = + which is the required tree. As I remember it there were a few complications to the scheme (eg: graham You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||