|Two pass compiler for a language similar to Java email@example.com (=?ISO-8859-1?Q?Joan_Jes=FAs_Pujol_Espinar?=) (2004-09-03)|
|Re: Two pass compiler for a language similar to Java firstname.lastname@example.org (2004-09-07)|
|Re: Two pass compiler for a language similar to Java email@example.com (J.H.Jongejan) (2004-09-08)|
|Re: Two pass compiler for a language similar to Java firstname.lastname@example.org (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen) (2004-09-13)|
|Re: Two pass compiler for a language similar to Java email@example.com (2004-09-13)|
|Re: Two pass compiler for a language similar to Java firstname.lastname@example.org (Joan Pujol) (2004-09-13)|
|Re: Two pass compiler for a language similar to Java email@example.com (2004-09-13)|
|Re: Two pass compiler for a language similar to Java firstname.lastname@example.org (Chris Dollin) (2004-09-13)|
|Re: Two pass compiler for a language similar to Java email@example.com (2004-09-21)|
|From:||Chris Dollin <firstname.lastname@example.org>|
|Date:||13 Sep 2004 12:34:13 -0400|
|Posted-Date:||13 Sep 2004 12:34:13 EDT|
Kamal R. Prasad wrote:
> Joan Jesús Pujol Espinar <email@example.com> wrote
>> I'm doing a pseudocode language similar to Java (it is posible to use
>> things before are defined).
>> I know (or I think ;) ) that the best way to manage this is with two
>> pass using ASTs. And is the strategy that I'm using.
> A procedural language does require a 2-pass compiler.
Counterexample: Pascal. Also C, I believe.
>> But only for curiosity, it's possible to do the semantic analysis of my
>> language in a syntatic directed compiler with only one pass. The
>> strategy will be to put in the symbol table what you are waiting to get
>> and when you find the definition compare if what are you waiting is what
>> is defined... It's a lot more dificult, but it's posible, or there are
>> problems that I can't see?
> How will you identify errors in function parameters? A symbol table
> isn't the only one that needs to deal with yet-to-be-encountered
It depends on the details of his semantics, I think, and what the
geenrated code expects. If one finds a call
where both f and x are as-yet undeclared, you add to the symbol
f: SOMETYPE -> SOMEOTHERTYPE
Now when (say) you find
you know that SOMETYPE "must" be a type that 17 is a legal value
of, so you note
SOMETYPE:: oneof (small int, medium int, large int ...)
When you find
f( "hello, whirled" )
if the ... doesn't include String, you can flag an error (or
warning, depending on your code geenration strategy).
When you find the declaration of f, you check that the recorded
uses are consistent with the declaration.
>> A lot of thanks in advance and excuseme for my little english.
> If you want an interpreter -it makes sense to go in for a 1-pass
> compiler. Else, 2-pass is what one would use.
I don't see that whether or not it's an interpreter (whatever that
means) makes a difference. You can have 1-pass compilers for
interpretable code and for actual real true machine code, and you
can have >1-pass compilers for ditto, even when [if] the notion of
pass *is* well-defined.
What matters more than the number of passes, surely, is whether the
code "fits" (in space/time terms) into the budget, and whether it
is "clean" (expresses the solution well, is usefully [de]coupled,
is robust against change, etc).
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
Return to the
Search the comp.compilers archives again.