Jan Burse
unread,Jun 1, 2016, 11:42:11 AM6/1/16You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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?)