home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / compiler / 1524 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.8 KB

  1. Path: sparky!uunet!gatech!rutgers!faatcrl!iecc!compilers-sender
  2. From: jar@cheops.HQ.Ileaf.COM (Jim Roskind x5570)
  3. Newsgroups: comp.compilers
  4. Subject: Re: Parsing wars
  5. Keywords: parse, LR(1)
  6. Message-ID: <92-09-043@comp.compilers>
  7. Date: 5 Sep 92 16:54:36 GMT
  8. References: <92-09-006@comp.compilers>
  9. Sender: compilers-sender@iecc.cambridge.ma.us
  10. Reply-To: jar@cheops.HQ.Ileaf.COM (Jim Roskind x5570)
  11. Organization: Compilers Central
  12. Lines: 44
  13. Approved: compilers@iecc.cambridge.ma.us
  14.  
  15. dww@inf.fu-berlin.de writes:
  16. > The parsing is called shift-reduce parsing, and I thought I had understood
  17. > that. What happens on a reduction though is, instead of pushing the
  18. > nonterminal of the lhs of the reduced production onto a symbol stack and
  19. > digging through the goto table for the appropriate state to push onto the
  20. > state stack, the nonterminal is *prepended* to the input sequence of
  21. > tokens and parsing resumes as normal. The other actions, shift, accept and
  22. > error are as expected, an action shiftreduce combines the normal shift and
  23. > the strange reduce.
  24.  
  25. The conseqeunces of this extension are quite significant, and the
  26. resulting parser engine provides a much larger class of parsers than LR
  27. parsers.  Clearly all LR parsers are a subset of the above parsers, as
  28. doing the above "strange reduce" followed by a "shift" is identical to
  29. doing a classical LR engine "reduce."
  30.  
  31. To see the weirdness of this extension, it can be noted that you can build
  32. an N pass parser using the above mechanisms.  Certainly parsing is not
  33. restricted to Left to right, Right most derivation.  To see how to make an
  34. N pass (trivial) parser using the above engine, you simply have to note
  35. that a series of "strange reduces" (re: which put stuff back into the
  36. input queue) can be used at any point to "back up" into the current stack.
  37. To be fair about this, you have to provide trivial reductions that have a
  38. right hand side of length 1, and provided new non-terminal names for the
  39. "popped" entries on the stack.
  40.  
  41. Mind you, I have no real idea as to how to specify such parsers, or how to
  42. build the transition tables that I indicate can be built.  For a given
  43. grammar, the big loss is that there is no longer a cannonical parsing
  44. order, such as is specified with LR parsers.  If you restrict the
  45. transition table so that you must have a "shift" after every "strange
  46. reduce,", then you have exactly an LR parsing engine.
  47.  
  48. Oh well, it is interesting, but I'm not sure what the use is.  It would be
  49. more interesting if a clear class of parsers could be specified, and these
  50. parsers required the "strange reduce" to be implemented.  
  51.  
  52. Jim Roskind-   Author of a YACCable C++ grammar
  53. Independent Consultant
  54. (407)729-4348 or (617)290-4990 x5570
  55. jar@hq.ileaf.com or ...!uunet!leafusa!jar
  56. -- 
  57. Send compilers articles to compilers@iecc.cambridge.ma.us or
  58. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  59.