Related articles |
---|
Building C/C++ compilers sigurd@lerstad.com (Sigurd Lerstad) (2004-12-16) |
Re: Building C/C++ compilers vidar@hokstad.name (Vidar Hokstad) (2004-12-17) |
Re: Building C/C++ compilers robert@simpson190.fsnet.co.uk (Robert J. Simpson) (2004-12-17) |
Re: Building C/C++ compilers camille@bluegrass.net (David Lindauer) (2004-12-17) |
From: | "Sigurd Lerstad" <sigurd@lerstad.com> |
Newsgroups: | comp.compilers |
Date: | 16 Dec 2004 00:50:21 -0500 |
Organization: | Compilers Central |
Keywords: | C++, question |
Posted-Date: | 16 Dec 2004 00:50:21 EST |
Hello,
I'm trying to make a C/C++ compiler.
I'm using flex and bison, and I have the book "modern compiler
implementation in C".
Some have commented that this book uses a non-traditional
approach. Can someone be more specific why it's untraditional?
In the phase to produce Abstract Syntax Tree (AST) from the source. C/C++
has a difficult case that has an amiguity
g * h
this can mean declare a variable pointer to g named h, or the variable g
multiplied with h;
In the above mentioned book, Appel first builds a syntax tree and then does
semantic analysis, i.e. type checking etc.
but it seems to me that because of the above ambiguity, ast building and
semantic analysis must be performed at the same time ?
C++ makes it even more difficult, consider this example:
class myclass
{
int method()
{
g* h;
}
typedef int g;
}
Now, g is declared later in the source, which complicates things even more.
Does anyone have any pointers to me overcoming these two issues, also on the
light of using bison as the parser.
thanks,
--
Sigurd Lerstad
[Parsing C++ using a LALR parser is quite difficult. This has come up many
times before. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.