Re: Code generation from AST

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Sun, 11 Nov 2007 11:02:11 +0100

          From comp.compilers

Related articles
Code generation from AST lssilva@gmail.com (Lucas S. Silva) (2007-11-10)
Re: Code generation from AST mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2007-11-11)
Re: Code generation from AST DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-11-11)
| List of all articles for this month |

From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: Sun, 11 Nov 2007 11:02:11 +0100
Organization: cbb software GmbH
References: 07-11-033
Keywords: code
Posted-Date: 11 Nov 2007 12:40:27 EST

On Sat, 10 Nov 2007 23:09:57 +0100, Lucas S. Silva wrote:


> The algorithm I am using doesn't deal very well with recursive
> expression such as:
>
> a = f.g.h(a , x.y.o(1,2) )
>
> I am using the visitor to process the AST, so when I get to node f it
> could be a simple function call or a compound which have parameters
> that may also be a function call, an so on.
>
> Is there any good algorithm to deal with this type of situation? I am
> planning to use stack but I am not sure if it is the most appropriate
> method.


I make "." and "()" operations. The above becomes (depending on
priorities), the following tree:


"="
{ a,
      "()"
      { "." { "." { f, g }, h }, -- The first argument is f.g.h
          a, -- The second argument of "()"
          "()" -- The third argument of "()"
          { "." { "." { x, y }, o },
              1,
              2
} } }


Then "()" can be overloaded by "function call" and "array indexing", at
the semantics analysis stage you will decide what it is depending on the
first argument of. So if f.g.h renders to a function then "()" is a call.
When x.y.o is an array, then its "()" is indexing.


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


Post a followup to this message

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