Weird PostgreSQL expression parsing How is PostgreSQL parsing supposed to work?

rivet=# SELECT 1 IS NOT NULL::int + 2 IS NOT NULL::int;
 int4 
------
    1
(1 row)


But

rivet=# SELECT 1 IS NOT NULL::int + (2 IS NOT NULL)::int;
 ?column? 
----------
        2
(1 row)


This seems very unintuitive?

Is this a mistake? Can anyone help me understand what PostgreSQL is doing?
In the first example, you end up with 1 + 2 IS NOT NULL - which, it is not, 3 is certainly not null. 3 IS NOT NULL evaluates to true, casting it to an int makes it 1 again. Hopefully this makes it clearer:

testdb=# select 1 is not null;
 ?column? 
----------
 t
(1 row)

testdb=# select 1 is not null::int;
 int4 
------
    1
(1 row)

testdb=# select 1 is not null::int + 2;
 ?column? 
----------
        3
(1 row)

testdb=# select 1 is not null::int + 2 is not null;
 ?column? 
----------
 t
(1 row)

testdb=# select 1 is not null::int + 2 is not null::int;
 int4 
------
    1
(1 row)