|functional programming language compiler using ANTLR? firstname.lastname@example.org (2003-01-12)|
|Re: functional programming language compiler using ANTLR? email@example.com (Joachim Durchholz) (2003-01-17)|
|From:||Joachim Durchholz <firstname.lastname@example.org>|
|Date:||17 Jan 2003 20:00:18 -0500|
|Posted-Date:||17 Jan 2003 20:00:18 EST|
> [I don't know any reason that parsing a functional language would be
> different from parsing an imperative one.
This is indeed the case. However, the grammars of functional
languages tend to be easier than those for imperative languages. I see
two possible influences in that direction:
1) Many (not all) functional languages are defined as a core language
plus a set of rules to translate the full language into core language
constructs. This tends to regularize the syntax and semantics of the
2) In functional languages, top-down LL parsing can be expressed very
elegantly and simply. IOW at least the first draft of a new functional
language tends to be LL(1).
> The code generation would be quite different, of course. -John]
Some things remain the same. Others differ vastly.
FPL implementations with a VM tend to be greatly different. For example,
there exist functional VMs that do graph reduction (this makes it more
efficient to interpret certain ubiquitous functional idioms).
Tail call optimization is mandatory. Loops in a functional program are
written as linear recursion (even if the programmer is not aware of
it), and linear recursion takes linear stack space without that
optimization, constant stack space with it.
Functional languages are almost unusable unless they support first-order
functions (i.e. functions constructed during run-time, either by
substituting functions into other functions, or by partly evaluating
them with a known parameters). Making this efficient is one of the
principal tasks of implementing a functional language.
Generating machine code is very similar. At the machine level, a
functional language moves data between registers and memory just like an
ordinary imperative language, and the issues are the same.
A functional compiler can optimize much more aggressively than an
imperative one. A subroutine call will not clobber any variables, and
there's no need to worry about aliases. This makes data-flow-based
optimizations much more simple.
I'm pretty sure that are other notable aspects. This is just what comes
off the top of my head.
Return to the
Search the comp.compilers archives again.