home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / compiler / 1444 < prev    next >
Encoding:
Internet Message Format  |  1992-08-23  |  3.7 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!uakari.primate.wisc.edu!usenet.coe.montana.edu!ogicse!das-news.harvard.edu!spdcc!iecc!compilers-sender
  2. From: jrickard@eoe.co.uk (John Rickard)
  3. Newsgroups: comp.compilers
  4. Subject: Re: Generating LALR(1) Grammar from an arbitrary CFG.
  5. Keywords: LALR, parse, theory
  6. Message-ID: <92-08-144@comp.compilers>
  7. Date: 23 Aug 92 16:24:47 GMT
  8. References: <92-08-118@comp.compilers>
  9. Sender: compilers-sender@iecc.cambridge.ma.us
  10. Reply-To: jrickard@eoe.co.uk (John Rickard)
  11. Organization: Compilers Central
  12. Lines: 58
  13. Approved: compilers@iecc.cambridge.ma.us
  14.  
  15. kumar@ra.csc.ti.com (Sundeep Kumar) writes:
  16. : Is there a utility that accepts an abitrary CFG and either gives an
  17. : equivalent LALR(1) grammar or decides that the CFG has no equivalent
  18. : LALR(1) grammar ? Is this problem in general, solvable ?
  19.  
  20. No, it's not soluble.  (Which doesn't exclude the possibility of such a
  21. utility that works in the cases one's interested in.)
  22.  
  23. Sketch proof:
  24.  
  25. I assume the lemma: There is no algorithm to decide whether a CFG
  26. generates the language consisting of every word of its alphabet.  (This
  27. result can be found in books on languages and automata, and I give a very
  28. sketchy proof below.)
  29.  
  30. Given any language L on alphabet A with a CFG, take a context-free
  31. language M on a disjoint alphabet B such that M has no LALR(1) grammar.
  32. Consider the language N on the alphabet A U B consisting of all words S
  33. such that either discarding all letters in B from S yields a word in L or
  34. discarding all letters in A from S yields a word in M.  If L contains all
  35. words on A, then N contains all words on A U B and so N has a LALR(1)
  36. grammar; if L does not contain all words on A, then it is not hard to see
  37. that N does not have a LALR(1) grammar (since if it did then so would M).
  38. So if it were decidable whether N had a LALR(1) grammar, then it would be
  39. decidable whether L contained all words on A, which contradicts the lemma.
  40.  
  41. Very sketchy proof of lemma:
  42.  
  43. This uses the well-known fact that it is not decidable whether an
  44. arbitrary Post correspondence problem is soluble.  A Post correspondence
  45. problem is defined by a finite set of ordered pairs of words over a given
  46. alphabet; a solution is a finite non-empty sequence of pairs of words,
  47. each from the given set, such that the concatenation of the first word
  48. from each pair equals the concatenation of the second word from each pair.
  49. (For example, is there an English "sentence" with a word-for-word French
  50. translation that consists of the same letters in the same order, with only
  51. the positioning of the spaces different?)
  52.  
  53. Now given a Post correspondence problem, we add two characters "," and ":"
  54. to its alphabet and consider the language consisting of all words on the
  55. extended alphabet except those that are generated from a solution of the
  56. Post correspondence problem by concatenating (to use the terms of the
  57. example above): the English words, separated by commas; a colon; the
  58. reverse of the string formed by the French words, separated by commas.
  59. This language has a CFG, and it contains all words on its alphabet if and
  60. only if the Post correspondence problem is not soluble; this proves the
  61. lemma.  (Why does the language have a CFG?  Well, it's the union of these
  62. three languages, and it's not hard to find a CFG for each of them: (a)
  63. words not containing exactly one colon; (b) words containing exactly one
  64. colon that do not form palindromes if the commas are omitted; (c) words
  65. containing exactly one colon where the substrings between commas do not
  66. match up around the colon as English words and reversals of French
  67. translations.)
  68.  
  69. -- John Rickard
  70. -- 
  71. Send compilers articles to compilers@iecc.cambridge.ma.us or
  72. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  73.