POV-Ray : Newsgroups : povray.off-topic : Pointless but satisfying : Re: Pointless but satisfying Server Time
5 Sep 2024 19:26:42 EDT (-0400)
  Re: Pointless but satisfying  
From: Invisible
Date: 20 Jul 2009 04:11:14
Message: <4a6426a2$1@news.povray.org>
>>>> Haskell really is a PITA to parse. I mean, think about it:
>>>> - Whitespace is significant. (No context-free parsing here!)
>>>
>>> I don't think "context-free" means what you think it means. 
>>> Whitespace being significant isn't "context".
>>
>> Indentation is significant. To parse the next line, you must know how 
>> far the current line was indented. Hence, "context".
> 
> I don't think "context-free" means what you think it means.
> 
> That's like saying Pascal isn't context-free because you need to know 
> how many "begin" statements you're nested within.

No, you don't. You can totally parse the contents without knowing how 
deeply nested it is. The parsing rules don't change.

However, in Haskell, if I write

   foo = if x
           then y
           else z

that's different to

   foo =
     if x
       then y
       else z

To parse the "then" part, you *must* know how far the "if" part is 
indented. It's not possible to unambiguously parse without this 
information. (Consider nested if-expressions; here indentation is the 
only thing that makes the nesting unambiguous...)

> A grammar is context-free if none of the left side of the production 
> have terminal symbols in them.  (That's the technical definition, which 
> takes several paragraphs to explain in prose.)

Yeah. You'd have to know what a "production" is, for starters...

>> No, they can be used *before* they're defined. And they can be defined 
>> in a completely seperate source file too. Which makes me wonder how 
>> it's possible to parse an individual file at all... you'd need to 
>> potentially parse every module it imports to work out the operator 
>> precedences!
> 
> Could be! :-)  Sounds like a real bear to compile, but then, that's what 
> computers are for.

Well, you can totally tokenise the input without knowing anything about 
what user-defined operators exist. (There are rules about what 
characters you may use.) But it seems that you can't build a correct 
parse tree until you know the operator precedences, so...

Starting to see why Haskell is the only language powerful enough to 
implement a Haskell compiler, yes? ;-)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.