Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!198.186.194.250.MISMATCH!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!nerds-end From: torbenm@diku.dk (Torben Ægidius Mogensen) Newsgroups: comp.compilers Subject: Re: how to parse this? Date: Tue, 01 Feb 2011 13:35:34 +0100 Organization: SunSITE.dk - Supporting Open source Lines: 40 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <11-02-002@comp.compilers> References: <11-01-095@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: gal.iecc.com 1296583611 82879 64.57.183.58 (1 Feb 2011 18:06:51 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Tue, 1 Feb 2011 18:06:51 +0000 (UTC) Keywords: parse, yacc Posted-Date: 01 Feb 2011 13:06:50 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:976 nojb writes: > Hi, > > My language has function applications like ML, i.e. f g h means f > applied to two parameters g and h. But the rule > > exp: IDENT list(exp) > > in Yacc will parse this as f (g h). How can I fix this? You can either fix it by post-processing the parse tree, or you can write the production using explicit left-recursion: exp: application application: IDENT exp | application exp If applications are really ML-like, they don't need to start with an identifier, so you should rather have something like exp: exp exp which, however, is ambiguous. You can fix this by adding a %prec declaration or by dividing expressions into simple and complex expressions and only allowing simple expressions as arguments to function applications, i.e., exp: exp simple | simple simple: IDENT | LPAR exp RPAR | ... where LPAR and RPAR are the token names for parentheses. Torben