Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parser Incompatibility (SICStus Parser and Other Parsers)

9 views
Skip to first unread message

Jan Burse

unread,
Jun 1, 2016, 11:42:11 AM6/1/16
to
Dear All,

Just found a critical test case for various Prolog
parsers. Background is some rework of the parenthesis
setting during writing.

GNU Prolog: Doesn't accept the test cases

?- X = ((+) + (+) = * + *), write_canonical(X), nl.
uncaught exception: error(syntax_error('user_input:13 (char:18)
current or previous operator needs brackets'),read_term/3)

?- X = ((+) + + = * + *), write_canonical(X), nl.
uncaught exception: error(syntax_error('user_input:14 (char:14)
current or previous operator needs brackets'),read_term/3)

?- X = (+ + + = * + *), write_canonical(X), nl.
uncaught exception: error(syntax_error('user_input:15 (char:12)
current or previous operator needs brackets'),read_term/3)

And then:

SICStus Prolog: Accepts the test cases, greedy parsing

?- X = ((+) + (+) = * + *), write_canonical(X), nl.
=(+(+,+),+(*,*))
X = ((+)+(+)=(*)+(*)) ?

?- X = ((+) + + = * + *), write_canonical(X), nl.
+(+,*(+(=),+(*)))
X = (+)+ + (=)* + (*) ?

X = (+ + + = * + *), write_canonical(X), nl.
*(+(+(+(=))),+(*))
X = + + + (=)* + (*) ?

Different from:

SWI-Prolog: Accepts the test cases, non-greedy parsing

?- X = ((+) + (+) = * + *), write_canonical(X), nl.
=(+(+,+),+(*,*))
X = ((+)+ (+)= (*)+ (*)).

?- X = ((+) + + = * + *), write_canonical(X), nl.
=(+(+,+),+(*,*))
X = ((+)+ (+)= (*)+ (*)).

?- X = (+ + + = * + *), write_canonical(X), nl.
=(+(+(+)),+(*,*))
X = (+ + (+)= (*)+ (*)).

Currently in Jekejeke Prolog:

Jekejeke Prolog: Parses as SICStus Prolog, but different writing

?- X = ((+) + (+) = * + *), write_canonical(X), nl.
=(+(+,+),+(*,*))
X = ((+)+(+)= * + *)

?- X = ((+) + + = * + *), write_canonical(X), nl.
+(+,*(+(=),+(*)))
X = (+)+ + = * + *

?- X = (+ + + = * + *), write_canonical(X), nl.
*(+(+(+(=))),+(*))
X = + + + = * + *

Discrepancies in parsing (Test Case 2+3):

SICStus/Jekejeke Prolog SWI-Prolog
+(+,*(+(=),+(*))) =(+(+,+),+(*,*))
*(+(+(+(=))),+(*)) =(+(+(+)),+(*,*))

Rereading the written output works both in SICStus Prolog and
Jekejeke Prolog. But my hypothesis for writing is currently:

- Non need to put parenthesis around an infix or
postfix operator atom, only check prefix
operators atoms (holds for greedy parsing?)

- Non need to put parenthesis around a prefix
operator atom if it further doesn't occur in
a left argument context of another operator
(holds for greedy parsing?)



Jan Burse

unread,
Jun 2, 2016, 8:05:14 AM6/2/16
to
SICStus Prolog is not always greedy,
here are more test case:

SICStus Prolog: first test case not greedy,
second test case greedy

?- X = (+ ; +), write_canonical(X), nl.
;(+,+)
X = ((+);(+)) ?

?- X = (+ ; + !), write_canonical(X), nl.
+(+(;),!)
X = + (;)+! ?

SWI-Prolog: Both not greedy

?- X = (+ ; +), write_canonical(X), nl.
;(+,+)
X = ((+); (+)).

X = (+ ; + !), write_canonical(X), nl.
;(+,+(!))
X = ((+);+!).

Jekejeke Prolog: Both greedy

?- X = (+;+), write_canonical(X), nl.
Error: Term missing.
X = (+;+), write_canonical(X), nl.
^
?- X = (+ ; + !), write_canonical(X), nl.
+(+(;),!)
X = +;+!

Jan Burse schrieb:
0 new messages