Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!think.com!mintaka!spdcc!iecc!compilers-sender From: boyland@aspen.berkeley.edu (John Boyland) Newsgroups: comp.compilers Subject: Re: Technical question about yacc and LALR parsers Keywords: parse, design Message-ID: <9104232230.AA18767@aspen.Berkeley.EDU> Date: 23 Apr 91 22:30:11 GMT References: <9104222013.AA09131@florida.HQ.Ileaf.COM> Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: boyland@aspen.berkeley.edu (John Boyland) Organization: Compilers Central Lines: 34 Approved: compilers@iecc.cambridge.ma.us In article <9104222013.AA09131@florida.HQ.Ileaf.COM>, jar@florida.HQ.Ileaf.COM (Jim Roskind x5570) writes: |> [...] A second |> example would would be (again verifiable by the parser generator) when a |> "grammar preprocessor" back-substituted some rules and in doing so, |> replicated the code actions. |> [...] |> |> Jim Roskind- Author of a YACCable C++ grammar |> jar@hq.ileaf.com or ...!uunet!leafusa!jar Unfortunately, grammar preprocessors (such as one I've developed), often have subtly different actions: For example: stmtlist : stmtlist ';' ? ';;' stmtlist { $$ = sequence($stmtlist'1,$stmtlist'2); } gets expanded into: stmtlist : stmtlist ';' DOUBLESEMI stmtlist { $$ = sequence($1,$4); } | stmtlist DOUBLESEMI stmtlist { $$ = sequence($1,$3); } (Duplicating rather than having a special optional-semicolon rule more often results in an LALR(1) grammar). Notice how the actions differ in where arguments are found. John Boyland boyland@sequoia.Berkeley.EDU -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.