Re: Object Oriented Compiler Design Problem

"Juciê Dias Andrade" <jucie@uol.com.br>
13 Sep 1998 22:50:07 -0400

          From comp.compilers

Related articles
Object Oriented Compiler Design Problem mayurnaik@my-dejanews.com (1998-09-05)
Re: Object Oriented Compiler Design Problem qjackson@wave.home.com (Quinn Tyler Jackson) (1998-09-13)
Re: Object Oriented Compiler Design Problem qjackson@wave.home.com (Quinn Tyler Jackson) (1998-09-13)
Re: Object Oriented Compiler Design Problem dwight@pentasoft.com (1998-09-13)
Object Oriented Compiler Design Problem dboucher@locus.ca (Dominique Boucher) (1998-09-13)
Re: Object Oriented Compiler Design Problem brueni@ipass.net (Dennis Brueni) (1998-09-13)
Re: Object Oriented Compiler Design Problem mikee@cetasoft.cog (1998-09-13)
Re: Object Oriented Compiler Design Problem jucie@uol.com.br (Juciê Dias Andrade) (1998-09-13)
Re: Object Oriented Compiler Design Problem danwang+news@cs.princeton.edu (Daniel C. Wang) (1998-09-18)
| List of all articles for this month |

From: "Juciê Dias Andrade" <jucie@uol.com.br>
Newsgroups: comp.compilers
Date: 13 Sep 1998 22:50:07 -0400
Organization: Compilers Central
References: 98-09-019
Keywords: OOP, design

Mayur Naik wrote:
> I want a suitable Object Oriented Solution to this problem. I want to > avoid the solution using 'a union with a type field'.


You can do this:


                class symbol {
virtual bool canBeComputedAtCompileTime() const = 0;
//...
};


class variable : public symbol {
virtual bool canBeComputedAtCompileTime() const
{
return false;
}
//...
};


class constant : public symbol {
                                int val;
virtual bool canBeComputedAtCompileTime() const
{
return true;
}
                                // ...
                };




symbol* add(symbol *a, symbol *b)
{
if(
a->canBeComputedAtCompileTime() && b->canBeComputedAtCompileTime()
)
{
// I dont have to generate Intermediate Code
}
else
{
// I have to generate Intermediate Code
}
}




I hope it helps.




Jucie Dias Andrade
São Paulo - Brazil


(Excuse my poor English, that's not my native language. Need I a
compiler?)
--


Post a followup to this message

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