Re: Dynamic Operators in Prolog

harvard!!pase (Douglas M. Pase)
26 Apr 89 17:15:41 GMT

          From comp.compilers

Related articles
Dynamic Operators in Prolog (1989-04-20)
Re: Dynamic Operators in Prolog harvard!!pase (1989-04-26)
Re: Dynamic Operators in Prolog (1989-04-26)
| List of all articles for this month |

From: harvard!!pase (Douglas M. Pase)
Newsgroups: comp.compilers
Keywords: dynamic operators,LALR(1) parsing
Date: 26 Apr 89 17:15:41 GMT
References: <>
Organization: Oregon Graduate Center, Beaverton, OR

In article <> (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 (CSNet) 19600 NW Von Neumann Dr.
(503) 690-1121 x7303 Beaverton, OR 97006-1999

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.