Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Roger L Costello Newsgroups: comp.compilers Subject: Why no shift-shift conflicts? Date: Tue, 25 Jan 2022 21:58:21 +0000 Organization: Compilers Central Lines: 27 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-01-112@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="65898"; mail-complaints-to="abuse@iecc.com" Keywords: parse, yacc, LALR, comment Posted-Date: 26 Jan 2022 13:30:57 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Thread-Topic: Why no shift-shift conflicts? Thread-Index: AdgSNRwyAsTP0Hp6SJiU2P+Rns+MJw== Content-Language: en-US Xref: csiph.com comp.compilers:2869 Hello Compiler Experts! I have read that there are shift-reduce conflicts and reduce-reduce conflicts. It is my understanding that a "conflict" means the parser doesn't know which path to take. Consider this example rule from the Bison manual: compound: '{' declarations statements '}' | '{' statements '}' ; I look at that and think, "There is ambiguity. There are two possible paths to take. The parser doesn't know which path to take." That is, it looks to me like a shift-shift conflict. Why are there no shift-shift conflicts? /Roger [Sheesh, it's because that's how LR parsing works. The parser has a state machine and a stack. When it shifts, it puts the token on the stack and moves to the next state, and it's OK if that state might be part of more than one rule. It's only when it gets to the end of a rule and needs to reduce, i.e., pop the tokens for that rule off the stack, give them to the semantic routine, and push its result token on the stack, that the action has to correspond to a single rule. For more info I shamelessly recommend chapter 7 of flex&bison. -John]