Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!compilers-sender From: nigelh@uvicctr.UVic.ca.UUCP (R. Nigel Horspool) Newsgroups: comp.compilers Subject: Re: Dynamic Operators in Prolog Message-ID: <653@uvicctr.UVic.ca.UUCP> Date: 26 Apr 89 15:30:49 GMT References: <3780@ima.ima.isc.com> Sender: compilers-sender@ima.ima.isc.com Reply-To: nigelh@uvicctr.UVic.ca.UUCP (R. Nigel Horspool) Organization: University of Victoria, Victoria B.C. Canada Lines: 29 Approved: compilers@ima.UUCP I have managed to implement a parser for Prolog and its dynamically-defined operators using lex & yacc, but it is extremely messy. Since all the shift-reduce conflicts are resolved at parser-creation time, there are only two possible approaches. 1. Construct a grammar where all possible precedence levels for the operators are pre-defined. (But typical Prologs allow 255 or more precedence levels.) 2. Have semantic actions attached to production rules that look up the operator precedences and associativities. The semantic actions then select a shift action or a reduce action by telling the lexer to insert extra symbols into the input. The extra symbols subsequently cause the parse to follow either a shift path or a reduce path. I implemented #2, but this simple idea has a lot of complications. I will happily e-mail a short paper giving the full details to anyone who requests it. R. Nigel Horspool nigelh@csr.uvic.ca, nigelh@uvunix.bitnet -- Send compilers articles to compilers@ima.isc.com or, perhaps, Levine@YALE.EDU Plausible paths are { decvax | harvard | yale | bbn}!ima Please send responses to the originator of the message -- I cannot forward mail accidentally sent back to compilers. Meta-mail to ima!compilers-request