0
  1. Instead of saying "Rightmost derivation in reverse", why don't they say "Leftmost reduction"? Do they mean the same thing? It is extremely confusing for me to read.

  2. What is a closure set, and how does it play a part in the parsing process? Every set of lecture notes I find on the internet assumes I already know what it is and what it does.

user3251270
  • 107
  • 1
  • 8
  • Questions are free; if you have two questions then ask two. Don't stuff two questions in one. That way it's unclear whether both are already answered. – MSalters May 27 '14 at 18:35
  • "Rightmost derivation in reverse" doesn't mean that you reverse the order of the strings or the scan. A derivation goes from the start symbol to the sentence; a parse starts with the sentence and ends up with the start symbol. So to parse is to undo the derivation (or do it backwards, if you like), but every transformation step still involves the right-most non-terminal. As @MSalters suggests, split your questions and I'll answer that specific question. – rici May 28 '14 at 03:54

1 Answers1

0

To answer the second question, a "closure set" is part of the parser constructions process, and is used to identify "states" that exist for the parser. Once the states have been identified and the parser has been constructed, the closure sets play no further part -- that is, they play no part in the actual parsing process.

A "closure set" it a set of partial parse items that is constructed by closure from one or more initial partial parse items. Each unique closure set maps to a single state. The rule for closure set construction is: If the set contains an item of the form 'X → α _ A β' and the grammar contains a rule of the form 'A → δ', add the item 'A → _ δ' to the itemset. For any given item set, you need to compute the closure by repeatedly adding items until no more can be added. Also this ignores lookahead (relevant for LR(k) construction, but not for LALR(1) or SLR(1) construction).

Once you've determined all the distinct closure sets that are reachable for the grammar, you assign each set a unique "state" symbol (usually just an integer), which are the tokens that will be manipulated on the parser stack at runtime when parsing an input. The closure set information is not used for parsing at all, though knowing it may be useful to debug a misbehaving parser for an incorrectly specified grammar.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226