trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
268 stars 13 forks source link

Without further ado segfault #597

Closed flexoron closed 1 week ago

flexoron commented 1 week ago

v2.56.14

?- op(1,xfy,&). op(1,fy,&). op(1,yf,&).
   true.
?- [user]. &(x). &(x,x). end_of_file.
   true.
?- [user]. (&x&)&x. end_of_file.
Warning: overwriting '&'/2
   true.
?- &(&(&(x)),x) = (&(&x))&x.
   true.
?- &(&(&(x)),x) = (& (&x))&x. % point-blank shot
Segmentation fault (core dumped)
$
flexoron commented 1 week ago
?- op(1,xfy,&). op(1,fy,&). op(1,yf,&).
?- [user]. &(x). &(x,x). end_of_file.
?- [user]. (&x&)&x. end_of_file.
Warning: overwriting '&'/2

?- &(&(&(x)),x) = (& (&x))&x.  % fixed
   true.
?- (& (&x))&x.
   true.

?- listing.
&x.
(& &x)&x.

?- &x.
   true.
?- (& &x)&x.
Segmentation fault (core dumped)
infradig commented 1 week ago

No longer crashes but a syntax error (incorrect):

$ tpl
?- op(1,xfy,&), op(1,fy,&), op(1,yf,&).
   true.
?- [user]. &(x). &(x,x). end_of_file.
   true.
?- [user]. (&x&)&x. end_of_file.
Warning: overwriting '&'/2
   true.
?- (&(&x))&x.
   true.
?- (& &x)&x.
Error: syntax error, missing operand to postfix, user:1
?- 

Odd since there is no postfix involved in parsing the query.

flexoron commented 1 week ago

Question: Do you think it's correct to overwrite other 'facts' in case of an error?

op(1,xfy,&), op(1,fy,&), op(1,yf,&).
[user]. &(x). &(x,x). end_of_file.
[user]. (&x&)&x. end_of_file.
[user]. (&x&)&y. end_of_file.

?- listing.
&x.
(& &x)&y.

?- [user]. (& &z)&y. end_of_file.
Error: syntax error, missing operand to postfix, user:1
Warning: overwriting '&'/1  % A Term Split ???
   true.
?- listing.
&y.   % Unexpected
(& &x)&y.
   true.
?- 
flexoron commented 1 week ago

v2.56.17

?- op(1,xfy,&), op(1,fy,&), op(1,yf,&).
?- [user]. (& &z)&y. end_of_file.
?- listing.
(& &z)&y.
   true.

?- [user]. (&&z)&y. end_of_file.
Error: syntax error, near 'z', operator expected, user:1
Error: syntax error, start of rule expected, user:1
   true.
?- listing.
(& &z)&y.
&y. % Unexpected
   true.

?- [user].
(&&z)&y.
Error: syntax error, near 'z', operator expected, user:1
   true.
?- listing.
   true. % Gone
?-