home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / function / 1365 < prev    next >
Encoding:
Internet Message Format  |  1992-11-13  |  3.9 KB

  1. Path: sparky!uunet!mcsun!uknet!cam-eng!ptb
  2. From: ptb@eng.cam.ac.uk (P.T. Breuer)
  3. Newsgroups: comp.lang.functional
  4. Subject: Re: Functional Parsers
  5. Keywords: parsers
  6. Message-ID: <1992Nov13.123205.13725@eng.cam.ac.uk>
  7. Date: 13 Nov 92 12:32:05 GMT
  8. References: <1992Nov4.153220.8174@eng.cam.ac.uk> <1992Nov10.170123.107@eng.cam.ac.uk> <NVT8YHL@math.fu-berlin.de>
  9. Sender: ptb@uk.ac.cam.eng
  10. Organization: Cambridge University Engineering Department, England
  11. Lines: 73
  12. Nntp-Posting-Host: club.eng.cam.ac.uk
  13.  
  14. In article <NVT8YHL@math.fu-berlin.de> dww@inf.fu-berlin.de writes:
  15. >>Thanks to Debora Weber-Wulff for offering a test case.
  16. >>The language { a^n b^n | n>=0 } apparently definitely has no LL grammar
  17. >
  18. >No, Peter, the language I gave you was
  19. >{a^n b^n | n >=1} \cup [that's the LaTeX union operator] {a^n c^n | n >=1}
  20. >This is not LL because you have to get all the way down to the b's or
  21. >c's before you can decide which way you needed to go. In LR parsing,
  22. >we are constructing the reverse of a right-derivation, we shift a's
  23. >onto the stack until we see a b or a c, and they we *know* which
  24. >set of productions to use. 
  25.  
  26. Duh. Sorry Debora. I apologised to you privately for this very public
  27. mistake and misattribution of mine, and I'll do it again now.
  28.  
  29. I must have had my brain cell go on holiday that day. Yes, you did tell
  30. me that it was the union language that was the LR--LL example, and I
  31. unforgivably misread your statement.
  32.  
  33. However, the union is still expressible by top-down functional parsers:
  34.  
  35. S = AB $ | AC $
  36. AB = a AB b
  37.    | a b
  38. AC = a AC c
  39.    | a c
  40.  
  41. and always will be provided that the functional `union of two parsers'
  42. operator induces an equivalent union in the corresponding sets of
  43. accepted parses.
  44.  
  45. To be completely honest, that is not always the case. All the
  46. combinator semantics I know of induce a subset of the union operator
  47. in general. It just so happens that in this particular case, all the
  48. usual combinator semantics give spot-on results. The general `subset of the
  49. union' claim boils down to having to consider what happens with \bot,
  50. (and I'll be more specific in private correspondence).
  51.  
  52. >>it's the basis of my claim that LR(0) languages are expressible.
  53. >How about a proof including the time and space complexities of
  54. >your system? I so enjoyed the strangesucc function, which has proved
  55. >to me that, yes, it is nice to express things with backtracking and no,
  56. >I do not want my systems to use it, because I prefer termination to
  57. >stack overflow.
  58.  
  59. This is a good point. My  implementation (pre-cc) of functional parsers
  60. is in straight C and doesn't use garbage collection. Nevertheless, it
  61. can still blow the top off the C stack if it gets into a left recursive
  62. loop (i.e., if you give a left recursive spec). Even without an unending
  63. loop recursion, it can sometimes demand a lot of space. Each call from the
  64. combinator-kernel costs about 20 bytes, so a C stack of 64K can accommodate
  65. 3000 nested calls. You then have to prove that the parse spec gives rise to
  66. a parser that can never go more than 3K calls deep when evaluating a valid
  67. (or invalid) phrase of the language.
  68.  
  69. That's possible, though. If the language has the form 
  70.    A | B
  71. then you have to prove that it takes at most 3K-1 calls to decide A and
  72. at most 3K-1 calls to decide accept/reject by B, because it's going to
  73. cost one more call to do the `alt' combinator.
  74.  
  75. When it comes to recursive specs, then I'm afraid we're going to need
  76. expressions for how many calls it takes to decide all phrases of length n,
  77. or possibly all calls of length n starting with `a', etc., depending on
  78. the structure of the spec, but I hope that one can do it for most
  79. reasonable specs. I haven't sat down to work out a calculus - but my
  80. original `example' of a grammar that acted as an abstract
  81. interpretation of occam object code, accepting only terminating codes,
  82. showed that there is certainly no algorithmic method that can treat all the
  83. specs expressible by functional top-down parsers and give close-fitting
  84. results.
  85.  
  86. Peter
  87.