aarroyoc / scryer-playground

Web playground to try Scryer Prolog in your browser!
https://play.scryer.pl
BSD 3-Clause "New" or "Revised" License
10 stars 2 forks source link

Why can't Scryer Prolog parse this? #30

Open Jean-Luc-Picard-2021 opened 2 weeks ago

Jean-Luc-Picard-2021 commented 2 weeks ago

Why cant Scryer Prolog parse this?

scryer-prolog$ target/release/scryer-prolog -v
v0.9.4-165-g12a61cdf

scryer-prolog$ target/release/scryer-prolog

?- current_op(X, Y, *).
   X = 400, Y = yfx.

?- X = (* = *).
   error(syntax_error(incomplete_reduction),read_term/3:1).

On the other hand Trealla Prolog has no problem:

trealla$ ./tpl -v
Trealla Prolog (c) Infradig 2020-2024, v2.55.31

trealla$ ./tpl
?- current_op(X, Y, *).
   X = 400, Y = yfx.

?- X = (* = *).
   X = ((*)=(*)).

What LEX / YACC did they use?

triska commented 2 weeks ago

Trealla is too lenient. We have:

6.3.1.3 Atoms
...

An atom which is an operator shall not be the immediate
operand (3.120) of an operator. 

GNU Prolog also correctly raises a syntax error in this case.

Jean-Luc-Picard-2021 commented 2 weeks ago

Its not implemented by most Prolog systems. Mostlikely for performance reasons, since it would require an operator table lookup for each atom:

363495496-303738e9-03da-4c33-a925-a76d5b9a9c3e

triska commented 2 weeks ago

An issue for this is already filed for Tau Prolog: https://github.com/tau-prolog/tau-prolog/issues/286.

Jean-Luc-Picard-2021 commented 2 weeks ago

But Tau Prolog is dead now, or hibernating for more than 12 months already. So the more lenient behaviour has already been ossified in this Prolog system.

Another argument not in favor, it also makes parsing more non-monotonic, if you introduce the "shall" condition, because its a negative parsing condition.

$ target/release/scryer-prolog
?- X = (#\/ = #\/).
   X = (#\/ = #\/).

?- use_module(library(clpz)).
   true.

?- X = (#\/ = #\/).
   error(syntax_error(incomplete_reduction),read_term/3:1).

Maybe introducing more than rather less operator table dependencies in a grammar is always a mistake? A further use case is (!)/1 in TPTP syntax.