Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!compilers-sender Newsgroups: comp.compilers Subject: Re: Dynamic Operators in Prolog Keywords: dynamic operators,LALR(1) parsing Message-ID: <3806@ima.ima.isc.com> Date: 26 Apr 89 17:15:41 GMT References: <3780@ima.ima.isc.com> Sender: compilers-sender@ima.ima.isc.com Reply-To: harvard!ogccse.ogc.edu!pase (Douglas M. Pase) Organization: Oregon Graduate Center, Beaverton, OR Lines: 35 Approved: compilers@ima.UUCP In article <3780@ima.ima.isc.com> jamesbk@saturn.ucsc.edu (James Kerr) writes: - I'm attempting to write an LALR parser for Prolog (using lex and yacc) -that permits dynamic operator definitions. The idea is to have lex return -a single token OP whenever it sees an atom that has been defined as an -operator. The grammar for the language then includes productions like - term : OP term - | term OP term - | ... (other stuff) Rather than use a LALR parser, a much simpler approach is to use an operator precedence parser, which can easily be modified on the fly. Prolog syntax is simple enough that the initial table need only have a few non-error entries. The operators would be hashed to come up with a table index. We explored this idea in a parsing class I taught, and concluded it was a simple and effective way to solve Prolog's parsing problems. It is perfectly reasonable to use lex to generate a lexical analyzer, even using an OP parser. However, in most cases it should be left up to the parser to decide whether a name is used as a functor or as an operator. The lexical analyzer is probably capable of doing it, but the OP parser is better suited to do so. (This way it would be easier to allow a name to be used as either a functor or an operator, as the context required.) -- Douglas M. Pase Department of Computer Science tektronix!ogccse!pase Oregon Graduate Center pase@cse.ogc.edu (CSNet) 19600 NW Von Neumann Dr. (503) 690-1121 x7303 Beaverton, OR 97006-1999 -- 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