home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / compiler / 2244 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.9 KB

  1. Path: sparky!uunet!spool.mu.edu!uwm.edu!ogicse!decwrl!world!iecc!compilers-sender
  2. From: tchannon@black.demon.co.uk (Tim Channon)
  3. Newsgroups: comp.compilers
  4. Subject: Re: Recursive descent parsing is better than LL(1)
  5. Keywords: LL(1), parse
  6. Message-ID: <93-01-172@comp.compilers>
  7. Date: 23 Jan 93 22:43:00 GMT
  8. Article-I.D.: comp.93-01-172
  9. References: <93-01-122@comp.compilers> <93-01-160@comp.compilers>
  10. Sender: compilers-sender@iecc.cambridge.ma.us
  11. Reply-To: tchannon@black.demon.co.uk (Tim Channon)
  12. Organization: Compilers Central
  13. Lines: 61
  14. Approved: compilers@iecc.cambridge.ma.us
  15.  
  16. > I present a simple contra-example:
  17. > Consider the language defined by the next CFG:
  18. > S -> A
  19. > S -> B
  20. > A -> `x' A `y'
  21. > A -> `a'
  22. > B -> `x' B `z'
  23. > B -> `b'
  24. > SID uses elimination of left recursion, factorisation and substitution to
  25. > search for a better grammar.
  26.  
  27. I assume it is a matter of what you ask SID and by the time you are at S
  28. it is too late to branch or is it.
  29.  
  30. Is this a valid LL(1) solution? (diagnostics are too large to post but all
  31.                 is well)
  32.  
  33. S    =  'x' {   'x'
  34.               | 'a'
  35.               | 'b'
  36.             }
  37.             ('y' | 'z')
  38.       | 'a'
  39.       | 'b'.
  40.       
  41. producing this exact output
  42.  
  43.     IF (sym = XSym) THEN
  44.       Get;
  45.       WHILE (sym = XSym) OR
  46.             (sym = ASym) OR
  47.             (sym = BSym) DO
  48.         IF (sym = XSym) THEN
  49.           Get;
  50.         ELSIF (sym = ASym) THEN
  51.           Get;
  52.         ELSE
  53.           Get;
  54.         END;
  55.       END;
  56.       IF (sym = YSym) THEN
  57.         Get;
  58.       ELSIF (sym = ZSym) THEN
  59.         Get;
  60.       ELSE Error(11);
  61.       END;
  62.     ELSIF (sym = ASym) THEN
  63.       Get;
  64.     ELSIF (sym = BSym) THEN
  65.       Get;
  66.     ELSE Error(12);
  67.     END;
  68.  
  69.   TC. 
  70.     E-mail: tchannon@black.demon.co.uk or tchannon@cix.compulink.co.uk
  71. -- 
  72. Send compilers articles to compilers@iecc.cambridge.ma.us or
  73. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  74.