Newsgroups: | comp.compilers |
From: | reid@HASKELL.SYSTEMSZ.CS.YALE.EDU (Alastair Reid) |
Keywords: | syntax, design |
Organization: | Yale Haskell project |
References: | 95-04-193 95-05-066 |
Date: | Tue, 16 May 1995 21:43:20 GMT |
plong@perf.com (Paul Long) writes:
lutz@KaPRE.COM writes:
>schrod@iti.informatik.th-darmstadt.de (Joachim Schrod) writes:
>> [indentation syntax makes it hard to generate programs]
>
> [...]it's not clear to me that it would be any harder to
>generate N tabs than to generate block delimeters correctly. [...]
I assume he means that generating proper indention is not as easy as
generating a basically unindented program but with proper syntax. I can
see his point, but I agree with you. [...]
An alternative approach is to allow use of block delimiters (so
program generators are happy) but have the compiler insert them when
"required" by the indentation. This is used in the functional
language Haskell which lets you write (from section 1.5 of the Haskell
report):
size s = length (stkToLst s) where
stkToLst Empty = []
stkToLst (MkStack x s) = x:xs where xs = stkToLst
but turns it into:
; size s = length (stkToLst s) where
{stkToLst Empty = []
;stkToLst (MkStack x s) = x:xs where {xs = stkToLst
}};
I've been happily using Haskell for several years now - these layout
rules work pretty well. It's also good to be able to drop into the
explicit layout style occasionally - I guess this shows that the
layout rule isn't quite perfect?
Of course, it's not without its disadvantages
1) The lexer has to access part of the parse state to decide
when to insert tokens.
2) The language has to define the meaning of tab stops and forbid the
use of variable-width fonts.
3) The translation is pretty ugly.
(This is a red herring - no-one should ever need to see it.)
Alastair Reid
Yale Haskell Project
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.