Why is this expression illegal?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is this expression illegal?

Jeroen Koops
Hi List!

If this expressions is legal:

case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end.


... and this expression is legal:


<< case A of foo -> 1; bar -> 2 end >>. 


... then why is this expression illegal:


<< case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end >>.


(shell responds with "* 1: syntax error before: 'bor'")


Thanks,


--
Jeroen Koops

T: +31-6-55590300

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Why is this expression illegal?

Brujo Benavides-3
I believe that inline operators (like bor) are disallowed in binary constructions. See…

1> << 1 bor 16 >>.
* 1: syntax error before: 'bor'
1> << 1 band 16 >>.
* 1: syntax error before: 'band'
1> << (1 band 16) >>.
<<0>>

On 18 Jan 2019, at 11:04, Jeroen Koops <[hidden email]> wrote:

Hi List!

If this expressions is legal:

case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end.

... and this expression is legal:

<< case A of foo -> 1; bar -> 2 end >>. 

... then why is this expression illegal:

<< case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end >>.

(shell responds with "* 1: syntax error before: 'bor'")

Thanks,

--
Jeroen Koops

T: +31-6-55590300
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Why is this expression illegal?

Jachym Holecek
In reply to this post by Jeroen Koops
Hi Joeren,

My guess: allowing entirely arbitrary expression within binary constructor
syntax could lead to ambiguities with respect to `/` and `-` and `:` tokens
which have special meaning in this context? Therefore only select expression
forms are permitted, which are free of ambiguities, one of them being `( E )`
which in turn opens access to arbitrary expressions if one is a bit more explicit.

So this will work:

    4> << (case foo of foo -> 1; bar -> 2 end bor case foo of foo -> 8; bar -> 16 end) >>.
    <<"\t">>

The file `stdlib-3.4.4/src/erl_parse.yrl` has the mechanics of it (search for `binary`,
`bin_elements`, `bin_element`) though not the underlying reasoning.

HTH,
    -- Jachym

On Fri, Jan 18, 2019, at 15:04, Jeroen Koops wrote:
Hi List!

If this expressions is legal:

case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end.


... and this expression is legal:



<< case A of foo -> 1; bar -> 2 end >>. 


... then why is this expression illegal:



<< case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end >>.


(shell responds with "* 1: syntax error before: 'bor'")


Thanks,


--
Jeroen Koops

T: +31-6-55590300
_______________________________________________
erlang-questions mailing list


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Why is this expression illegal?

Jeroen Koops
Thanks Jachym and Brujo,

I did try 

<< (case foo of foo -> 1; bar -> 2 end) bor (case foo of foo -> 8; bar -> 16 end) >>.

which didn't work, but

<< (case foo of foo -> 1; bar -> 2 end bor case foo of foo -> 8; bar -> 16 end) >>.

indeed does work.



On Fri, Jan 18, 2019 at 3:19 PM Jáchym Holeček <[hidden email]> wrote:
Hi Joeren,

My guess: allowing entirely arbitrary expression within binary constructor
syntax could lead to ambiguities with respect to `/` and `-` and `:` tokens
which have special meaning in this context? Therefore only select expression
forms are permitted, which are free of ambiguities, one of them being `( E )`
which in turn opens access to arbitrary expressions if one is a bit more explicit.

So this will work:

    4> << (case foo of foo -> 1; bar -> 2 end bor case foo of foo -> 8; bar -> 16 end) >>.
    <<"\t">>

The file `stdlib-3.4.4/src/erl_parse.yrl` has the mechanics of it (search for `binary`,
`bin_elements`, `bin_element`) though not the underlying reasoning.

HTH,
    -- Jachym

On Fri, Jan 18, 2019, at 15:04, Jeroen Koops wrote:
Hi List!

If this expressions is legal:

case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end.


... and this expression is legal:



<< case A of foo -> 1; bar -> 2 end >>. 


... then why is this expression illegal:



<< case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end >>.


(shell responds with "* 1: syntax error before: 'bor'")


Thanks,


--
Jeroen Koops

T: +31-6-55590300
_______________________________________________
erlang-questions mailing list

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


--
Jeroen Koops

T: +31-6-55590300

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Why is this expression illegal?

dieter

Hi,

in

http://erlang.org/doc/programming_examples/bit_syntax.html#constructing-binaries-and-bitstrings

I found:

<quote>

As mentioned earlier, segments have the following general syntax:

Value:Size/TypeSpecifierList

When constructing binaries, Value and Size can be any Erlang expression. However, for syntactical reasons, both Value and Size must be enclosed in parenthesis if the expression consists of anything more than a single literal or a variable. The following gives a compiler syntax error:

<<X+1:8>>

This expression must be rewritten into the following, to be accepted by the compiler:

<<(X+1):8>>
</quote>

Seems to me that this condition makes live for the parser a bit easier.

kind regards,
Dieter

On 18.01.19 15:25, Jeroen Koops wrote:
Thanks Jachym and Brujo,

I did try 

<< (case foo of foo -> 1; bar -> 2 end) bor (case foo of foo -> 8; bar -> 16 end) >>.

which didn't work, but

<< (case foo of foo -> 1; bar -> 2 end bor case foo of foo -> 8; bar -> 16 end) >>.

indeed does work.



On Fri, Jan 18, 2019 at 3:19 PM Jáchym Holeček <[hidden email]> wrote:
Hi Joeren,

My guess: allowing entirely arbitrary expression within binary constructor
syntax could lead to ambiguities with respect to `/` and `-` and `:` tokens
which have special meaning in this context? Therefore only select expression
forms are permitted, which are free of ambiguities, one of them being `( E )`
which in turn opens access to arbitrary expressions if one is a bit more explicit.

So this will work:

    4> << (case foo of foo -> 1; bar -> 2 end bor case foo of foo -> 8; bar -> 16 end) >>.
    <<"\t">>

The file `stdlib-3.4.4/src/erl_parse.yrl` has the mechanics of it (search for `binary`,
`bin_elements`, `bin_element`) though not the underlying reasoning.

HTH,
    -- Jachym

On Fri, Jan 18, 2019, at 15:04, Jeroen Koops wrote:
Hi List!

If this expressions is legal:

case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end.


... and this expression is legal:



<< case A of foo -> 1; bar -> 2 end >>. 


... then why is this expression illegal:



<< case A of foo -> 1; bar -> 2 end bor case A of foo -> 8; bar -> 16 end >>.


(shell responds with "* 1: syntax error before: 'bor'")


Thanks,


--
Jeroen Koops

T: +31-6-55590300
_______________________________________________
erlang-questions mailing list

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


--
Jeroen Koops

T: +31-6-55590300

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions