Subject: operators and brackets

From: Wolf Guddat <[email-masked]>
Date: Mon, 20 Sep 93 11:36:18 MESZ

Hi everybody,

I've got a problem in using operators.
I defined my ADT XPR_NUMBER, with inout-functions as usual.
After that i defined a lot of binary operators. 
Testing them all alone shows no errors, but when i try to build more
complex expression they produce a "parser syntax error"

/***** This is how i defined the *****/
define function xpr_nn_mult (language="c", returntype=XPR_NUMBER, trusted=t
			    ) 
			    arg is (XPR_NUMBER, XPR_NUMBER) 
			    as "/user/sonst/wfguddat/XPR2PG/num_op.o"\g
define function xpr_nn_quot (language="c", returntype=XPR_NUMBER, trusted=t
			    ) 
			    arg is (XPR_NUMBER, XPR_NUMBER) 
			    as "/user/sonst/wfguddat/XPR2PG/num_op.o"\g
define function xpr_nn_add  (language="c", returntype=XPR_NUMBER, trusted=t
			    ) 
			    arg is (XPR_NUMBER, XPR_NUMBER) 
			    as "/user/sonst/wfguddat/XPR2PG/num_op.o"\g
define function xpr_nn_sub  (language="c", returntype=XPR_NUMBER, trusted=t
			    )
                            arg is (XPR_NUMBER, XPR_NUMBER)
                            as "/user/sonst/wfguddat/XPR2PG/num_op.o"\g
define operator * (arg1 = XPR_NUMBER, 
		   arg2 = XPR_NUMBER, 
		   procedure = xpr_nn_mult)\g
define operator / (arg1 = XPR_NUMBER, 
                   arg2 = XPR_NUMBER, 
                   procedure = xpr_nn_quot)\g
define operator ++ (arg1 = XPR_NUMBER, 
		    arg2 = XPR_NUMBER, 
		    procedure = xpr_nn_add)\g

define operator -- (arg1 = XPR_NUMBER, 
		    arg2 = XPR_NUMBER, 
		    procedure = xpr_nn_sub)\g

/***** This are the commands which produce an error *****/
create N (n=XPR_NUMBER)/g
append N (n = "3.0"::XPR_NUMBER ++ "2.0"::XPR_NUMBER / "5.0"::XPR_NUMBER)\g
append N (n = "3.0"::XPR_NUMBER -- "2.0"::XPR_NUMBER ++ "5.0"::XPR_NUMBER)\g

    The second append produces the following monitor error-statement:

    *
    Query sent to backend is "append N (n = "3.0"::XPR_NUMBER -- "2.0"::XPR_NUMBER ++ "5.0"::XPR_NUMBER)"
    WARN:Sep 20 10:46:01:parser: syntax error at or near "++"
   
But if i put the first operation into brackets the message disappears:

append N (n = ("3.0"::XPR_NUMBER -- "2.0"::XPR_NUMBER) ++ "5.0"::XPR_NUMBER)\g

My Question is: Why is the first append OK and the second not? Do I always
                have to use selfdefined operators with brackets?

Thanks for all help. Wolf

****************************************************
**                                                **
** Wolf Guddat, [email-masked] **
**                                                **
**       University of Erlangen/Nuernberg         **
**                     Germany                    **
**                                                **
**     Postgres 4.1, DECstation, ULTRIX 4.3       **
**                                                **
****************************************************