Expression in op def gives spurious syntax error

This forum is to report technical problems with Rel.
Post Reply
HughDarwen
Posts: 124
Joined: Sat May 24, 2008 4:49 pm

Expression in op def gives spurious syntax error

Post by HughDarwen »

A certain UPDATE command works fine in DBrowser. When I parameterise it in an operator definition, such that literals are replaced by parameter names, I get an error message that seems to be spurious. I found that enclosing the WHERE condition in parens fixed the problem. Below is an example, copied-and-pasted from DBrowser's output panel. Relvar rv is declared and an update command is given successfully. Then comes the operator definition that is rejected, followed by the revised operator definition that works.

Hugh Darwen

var rv base init(rel{tup{x 1, y 'a'}}) key{x} ;
Ok.

update rv where x = 1 ( y := 'b' );
NOTICE: Updated 1 tuple.
Ok.

operator sety (xp integer, yp char); update rv where x = xp ( y := yp ); end operator;
ERROR: Encountered ":=" at line 1, column 65.
Was expecting one of:     "AND" ...     "COMPOSE" ...     "DIVIDEBY" ...     "D_UNION" ...     "GROUP" ...     "IN" ...     "INTERSECT" ...     "JOIN" ...     "MATCHING" ...     "MINUS" ...     "NOT" ...     "ORDER" ...     "OR" ...     "RENAME" ...     "SEMIJOIN" ...     "SEMIMINUS" ...     "UNGROUP" ...     "UNION" ...     "UNWRAP" ...     "WHERE" ...     "WRAP" ...     "XOR" ...     ")" ...     "{" ...     "," ...     "=" ...     ">" ...     "<" ...     "<=" ...     ">=" ...     "<>" ...     "+" ...     "-" ...     "*" ...     "/" ...     "[" ...     "||" ...     "*" ...     "/" ...     "+" ...     "-" ...     "||" ...     "{" ...     "RENAME" ...     "WRAP" ...     "UNWRAP" ...     "GROUP" ...     "UNGROUP" ...     "DIVIDEBY" ...     "UNION" ...     "D_UNION" ...     "INTERSECT" ...     "MINUS" ...     "JOIN" ...     "COMPOSE" ...     "SEMIJOIN" ...     "MATCHING" ...     "SEMIMINUS" ...     "NOT" ...     "=" ...     "<>" ...     ">=" ...     "<=" ...     ">" ...     "<" ...     "IN" ...     "AND" ...     "XOR" ...     "OR" ...     "WHERE" ...     "ORDER" ...     "[" ...     "[" ...     

operator sety (xp integer, yp char); update rv where (x = xp) ( y := yp ); end operator;
Ok.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Expression in op def gives spurious syntax error

Post by Dave »

V1 syntax had some ambiguities around UPDATE -- this appears to be an example of it.

It doesn't appear in Rel in the forthcoming version 1.0.10 update, which implements V2 syntax.
HughDarwen
Posts: 124
Joined: Sat May 24, 2008 4:49 pm

Re: Expression in op def gives spurious syntax error

Post by HughDarwen »

If you are suggesting that our Tutorial D V1 syntax was unsound, then I'm glad we fixed it in V2 by introducing a colon to separate the <attribute assign>s from the WHERE clause. I suppose a name followed by an opening paren can be taken for the start of an operator invocation, which might explain the objection to the presence of := inside the parens, but I thought that would be addressed by name scoping.

Hugh
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Expression in op def gives spurious syntax error

Post by Dave »

In any place where an operator invocation can occur, the parser will assume an identifier followed by an opening parenthesis is an operator invocation -- but in the V1 syntax UPDATE that might not be what the user intended. As you've pointed out, this ambiguity can be resolved by examining the identifier to see whether it's an operator name or not. I wouldn't consider it a grammatical unsoundness; I consider it my own laziness! :roll: I avoided the slightly awkward programming this disambiguation required and left it to the user. Fortunately, V2 syntax has eliminated the need to endure my laziness. :mrgreen:
Post Reply