Related articles |
---|
Good practical language and OS agnostic text? compilers@is-not-my.name (2012-04-17) |
Re: Good practical language and OS agnostic text? ulimakesacompiler@googlemail.com (Uli Kusterer) (2012-04-21) |
Re: Good practical language and OS agnostic text? cr88192@hotmail.com (BGB) (2012-04-21) |
Re: Recursive descent parsing and optimization, was Good practical lan bc@freeuk.com (BartC) (2012-04-22) |
Re: Recursive descent parsing and optimization, was Good practical lan mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2012-04-22) |
Re: Recursive descent parsing and optimization, was Good practical lan cr88192@hotmail.com (BGB) (2012-04-22) |
Re: Recursive descent parsing and optimization, was Good practical lan bartc@freeuk.com (Bartc) (2012-04-23) |
From: | "Bartc" <bartc@freeuk.com> |
Newsgroups: | comp.compilers |
Date: | Mon, 23 Apr 2012 10:59:20 +0100 |
Organization: | virginmedia.com |
References: | 12-04-019 12-04-056 12-04-060 12-04-066 12-04-069 |
Keywords: | parse, comment |
Posted-Date: | 24 Apr 2012 11:55:46 EDT |
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> On Sun, 22 Apr 2012 12:51:44 +0100, BartC wrote:
>> Or rather two: readfactor(priority), and readterm(). Readfactor() deals
>> with
>> the binary operators linking successive terms, while readterm() does all
>> the real work (since my syntax doesn't distinguish between expressions
>> and
>> statements, that's quite a big workload).
>
> Actually operations have two priorities; left and right. When left < right
> you have left to right association. When right > left, it becomes right to
> left.
>
> Some operators may have these priorities sufficiently different. For
> example the assignment operator. If your unlucky languages allows it, then
> A+B = C+D better be A+(B=(C+D)). That would require the following order of
> partial priorities:
My scheme doesn't work tidily when some operators have right-to-left
association.
Fortunately I only have two such operators, assignment and power (:= and
**), and some extra logic takes care of that. At least, the results are what
you would expect.
However, when I do something like A+B+:=C+D, then I might need a bit more
logic to deal with that, to avoid parentheses..
--
Bartc
[We theory weenies would use an operator precedence parser. It'd be
about 12 lines of code and a tiny lookup table, and can easily handle
arbitrary precedence and associativity. See the Wikipedia article for
details and pseudocode. The original Ritchie C compiler used recursive
descent for most of the language, and operator precedence for the
expressions. It was two passes and fit in 24K bytes of RAM. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.