Re: expressions -- functions within function

"Dmitry A. Kazakov" <>
10 Mar 2007 21:34:59 -0500

          From comp.compilers

Related articles
expressions -- functions within function (Mr.E) (2007-03-08)
Re: expressions -- functions within function (Arthur J. O'Dwyer) (2007-03-08)
Re: expressions -- functions within function (Dmitry A. Kazakov) (2007-03-10)
| List of all articles for this month |

From: "Dmitry A. Kazakov" <>
Newsgroups: comp.compilers
Date: 10 Mar 2007 21:34:59 -0500
Organization: cbb software GmbH
References: 07-03-027
Keywords: parse
Posted-Date: 10 Mar 2007 21:34:59 EST

On 8 Mar 2007 09:40:37 -0500, Mr.E wrote:

> How would you insert a generic function into the precedence parser?
> Actually more specifically, is it possible to insert a representation
> of a generic function that has parameters that allows functions with
> formal parameters as arguments?

I am not sure what you mean. Do you mean parsing functional notation
f(x,y,z) of the object language or parsing the meta language functions like
preprocessor expansions / automatic templates instantiations?

The first case is quite easy. When you meet a left bracket in the infix
context you push a stub on the operation stack with the count of arguments
1 (= the function name expression f). Each following comma (or other
arguments separator) will flush the stack up to the stub and increment the
count. (Here you can check the comma type if you have many of and detect
unexpected commas.) The closing bracket will flush the stach and the stub
itself with the arguments, the count of is from the stub. It is flushed a
special operator "call". The result will be: "call" (f, x, y, z). The first
argument of "call" is the function expression.

Take care about the precedence of the left infix bracket because:

a.b (x, y) should become "call" ("." (a, b), x, y), but a+b(x,y) should
"+"(a, "call" (b,x,y))

You can find an elaborated application of this approach here:

For the second case, it really depends on the meta-language you have in
mind. Maybe you will come out with the operation and argument stacks
reused, maybe not.

Dmitry A. Kazakov

Post a followup to this message

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