operator precedence

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

operator precedence

curmudgeon

Is there a reason why sqlite doesn’t follow the c convention?

e.g. & and | have equal precedence in sqlite.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: operator precedence

Clemens Ladisch
x wrote:
> Is there a reason why sqlite doesn’t follow the c convention?

Yes.  That reason is named "ISO/IEC 9075", but commonly called
"the SQL standard".


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: operator precedence

J Decker
In reply to this post by curmudgeon
On Sun, Jun 25, 2017 at 11:11 AM, x <[hidden email]> wrote:

>
> Is there a reason why sqlite doesn’t follow the c convention?
>
> e.g. & and | have equal precedence in sqlite.
>

I'd blame it on Postgresql operator precedence;  but then it also doesn't
seem to have bitwise & and | just logical.

https://www.postgresql.org/docs/devel/static/sql-syntax-lexical.html#sql-precedence

http://en.cppreference.com/w/c/language/operator_precedence


> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: operator precedence

J Decker
In reply to this post by Clemens Ladisch
Mysql has bitwise & before |

https://dev.mysql.com/doc/refman/5.7/en/operator-precedence.html

TSQL (MSSQL) has them equal.
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/operator-precedence-transact-sql

Oracle doesn't have bitwise & and |
https://docs.oracle.com/cd/A87860_01/doc/server.817/a85397/operator.htm

SQL Standard
http://web.cecs.pdx.edu/~len/sql1999.pdf
doesn't seem to have math operators... and the precedence tables are
described in longhand without a simple table....
DateTimes have math operators

"Operations on numbers are performed according to the normal rules of
arithmetic, within implementation-defined limits, except as provided for in
Subclause 6.26, ‘‘’’."

'normal rules of arithmetic' how vague

https://en.wikipedia.org/wiki/Order_of_operations#Programming_languages
(a separate section on rules of programming langauges)
also on this page ...

   - In the United States, the acronym *PEMDAS* is common. It stands for *P*
   arentheses, *E*xponents, *M*ultiplication, *D*ivision, *A*ddition, *S*
   ubtraction.

"Most common in the UK, India and Australia[11]
<https://en.wikipedia.org/wiki/Order_of_operations#cite_note-12> are
*BODMAS* meaning "B"rackets, "O"f or "O"rder, "D"ivision, "M"ultiplication,
"A"ddition and "S"ubtraction. Nigeria and some other West African countries
also use *BODMAS*. Similarly in the UK, *BIDMAS* is used, standing for
"B"rackets, "I"ndices, "D"ivision, "M"ultiplication, "A"ddition and
"S"ubtraction."

which doesn't account for & or | operations... so...
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: operator precedence

Simon Slavin-3


On 25 Jun 2017, at 7:59pm, J Decker <[hidden email]> wrote:

> SQL Standard
> http://web.cecs.pdx.edu/~len/sql1999.pdf
> doesn't seem to have math operators... and the precedence tables are
> described in longhand without a simple table....
> DateTimes have math operators
>
> "Operations on numbers are performed according to the normal rules of
> arithmetic, within implementation-defined limits, except as provided for in
> Subclause 6.26, ‘‘’’."

Which comes from SQL-92 which comes from SQL-89, almost unchanged.  However, & and | were not considered numeric operators at that point, so they didn’t figure into statements about the precedence of numeric operators.

BIDMAS (excuse me, I’m British) does apply, and it’s implemented in SQLite.  Of course, bitwise operators don’t feature in it because BIDMAS is for numbers and not bitwise operators.

My personal answer to the original question is "history".  C wasn’t the huge juggernaut back in 1989 that it is now.  A programmer could work their whole life without seeing a line of C code.  So there was no instinct to build C rules into everything else.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: operator precedence

curmudgeon
Thanks for the replies. I noticed a while back that when I compiled using the 64 bit compiler (I’m using c++ builder 10.1 which I think is clang) it gave warnings when || and && were mixed but not bracketed. Was worried I had missed something.

From: Simon Slavin<mailto:[hidden email]>
Sent: 25 June 2017 20:14
To: SQLite mailing list<mailto:[hidden email]>
Subject: Re: [sqlite] operator precedence



On 25 Jun 2017, at 7:59pm, J Decker <[hidden email]> wrote:

> SQL Standard
> http://web.cecs.pdx.edu/~len/sql1999.pdf
> doesn't seem to have math operators... and the precedence tables are
> described in longhand without a simple table....
> DateTimes have math operators
>
> "Operations on numbers are performed according to the normal rules of
> arithmetic, within implementation-defined limits, except as provided for in
> Subclause 6.26, ‘‘’’."

Which comes from SQL-92 which comes from SQL-89, almost unchanged.  However, & and | were not considered numeric operators at that point, so they didn’t figure into statements about the precedence of numeric operators.

BIDMAS (excuse me, I’m British) does apply, and it’s implemented in SQLite.  Of course, bitwise operators don’t feature in it because BIDMAS is for numbers and not bitwise operators.

My personal answer to the original question is "history".  C wasn’t the huge juggernaut back in 1989 that it is now.  A programmer could work their whole life without seeing a line of C code.  So there was no instinct to build C rules into everything else.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...