Re: Compiling expressions

"Dmitry A. Kazakov" <>
Sun, 30 Dec 2012 08:58:32 +0100

          From comp.compilers

Related articles
Compiling expressions (James Harris) (2012-12-29)
Re: Compiling expressions (glen herrmannsfeldt) (2012-12-29)
Re: Compiling expressions (Dmitry A. Kazakov) (2012-12-30)
Re: Compiling expressions (James Harris) (2013-01-02)
Re: Compiling expressions (James Harris) (2013-01-02)
Re: Compiling expressions ( (2013-01-03)
Re: Compiling expressions (2013-01-03)
Re: Compiling expressions (James Harris) (2013-01-03)
Re: Compiling expressions (James Harris) (2013-01-03)
[4 later articles]
| List of all articles for this month |

From: "Dmitry A. Kazakov" <>
Newsgroups: comp.compilers
Date: Sun, 30 Dec 2012 08:58:32 +0100
Organization: cbb software GmbH
References: 12-12-035
Keywords: parse
Posted-Date: 30 Dec 2012 16:38:58 EST

On Sat, 29 Dec 2012 05:11:16 -0800 (PST), James Harris wrote:

> Compiling expressions is turning out to be more 'interesting' than I
> anticipated! My requirements I believe to be fairly generic but they
> seem not to be supported by standard algorithms so it's not as simple
> as it might be. I thought I would post here as much out of interest as
> anything. I'm not after a prebuilt solution but would be interested to
> hear from other folks who have had similar issues to address. The
> requirements are:
> 1. Hand-written, not the output of a parser generator.
> 2. Efficient and without backtracking.
> 3. Precedences (and possibly associativities) defined in tables.
> 4. Output to be a tree structure.
> 5. Parenthesised subexpressions allowed.
> 6. Some operator families are *not* to associate with each other. See
> below.
> 7. Monadic prefix, dyadic infix and monadic postfix operators are all
> allowed.
> 8. Prefix and infix operators can use some same symbols (e.g. minus
> sign).

Here is an implementation with an explanation of the technique used:

I extended the method, which fairly old, towards non-associativity (#6),
advanced parenthesis (#5, keyed parameter associations), and split
association priorities into left-right pairs. But basically it is still the
same twin-stack method. Everything is table-driven, of course.

Dmitry A. Kazakov

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.