Semicolon after single statement in if?

View: New views
9 Messages — Rating Filter:   Alert me  

Semicolon after single statement in if?

by Pippijn van Steenhoven :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

can anyone tell me whether a semicolon is allowed in:

  if (foo) then bar; <- here
  else baz;

As far as I can tell from the grammar, it is not allowed, but maybe I'm
missing something, again. Can anyone help me out here?

Regards,

--
Pippijn van Steenhoven


_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

signature.asc (204 bytes) Download Attachment

Re: Semicolon after single statement in if?

by Bill Page-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Pippijn,

I think what you wrote should not be allowed. Since ; is used to
separate statements, the second line should be a syntactical error.
Did you get a different result when you tried this?

Regards,
Bill Page.

2009/5/6 Pippijn van Steenhoven <pip88nl@...>:

> Hi,
>
> can anyone tell me whether a semicolon is allowed in:
>
>  if (foo) then bar; <- here
>  else baz;
>
> As far as I can tell from the grammar, it is not allowed, but maybe I'm
> missing something, again. Can anyone help me out here?
>
> Regards,
>
> --
> Pippijn van Steenhoven
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkoBvDIACgkQJc+zqGNdDgqHLgCgtTI+poEpF3ZN8HnXBQxClb/B
> zcQAn1NDAxMpwitRaMjbk9SKCGKLBH4Y
> =HnLU
> -----END PGP SIGNATURE-----

_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

Re: Semicolon after single statement in if?

by Pippijn van Steenhoven :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, May 06, 2009 at 04:11:59PM -0400, Bill Page wrote:
> Pippijn,
>
> I think what you wrote should not be allowed. Since ; is used to
> separate statements, the second line should be a syntactical error.
> Did you get a different result when you tried this?

  #include "aldor.as"
  #include "aldorio.as"
  import from MachineInteger;
  if (1 < 2) then stdout << "ok" << newline;
  else stdout << "not ok" << newline;

The current aldor compiler will compile this fine and print "ok".
Removing the ; from either of the two last lines will be fine. The only
thing it does not accept is ;; anywhere. The point why I am asking this
is that in libaldor (I think, or maybe it was libalgebra), there are
several places where "if (a) then b; else c;" occurs and I don't think
this is actually valid.

--
Pippijn van Steenhoven


_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

signature.asc (204 bytes) Download Attachment

Re: Semicolon after single statement in if?

by David Casperson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi folks,

I don't have definite proof that it is legal, but I seem to remember that

       x:=3 ; ++ post
              ++ document

is a legal expression, and consequently could be substituted for Y in

if Z then Y else other ;

If that is the case

        x:=3 ;

may reduce to an expression (that is followed by a list of zero
post-documents).

Does this help?

David
--
David Casperson,
UNBC

On Wed, May 06, 2009 at 04:11:59PM -0400, Bill Page wrote:
> Pippijn,
>
> I think what you wrote should not be allowed. Since ; is used to
> separate statements, the second line should be a syntactical error.
> Did you get a different result when you tried this?

  #include "aldor.as"
  #include "aldorio.as"
  import from MachineInteger;
  if (1 < 2) then stdout << "ok" << newline;
  else stdout << "not ok" << newline;

The current aldor compiler will compile this fine and print "ok".
Removing the ; from either of the two last lines will be fine. The only
thing it does not accept is ;; anywhere. The point why I am asking this
is that in libaldor (I think, or maybe it was libalgebra), there are
several places where "if (a) then b; else c;" occurs and I don't think
this is actually valid.

--
Pippijn van Steenhoven


_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

signature.asc (204 bytes) Download Attachment

Re: Semicolon after single statement in if?

by Ralf Hemmecke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 05/06/2009 10:47 PM, Pippijn van Steenhoven wrote:

> On Wed, May 06, 2009 at 04:11:59PM -0400, Bill Page wrote:
>> Pippijn,
>>
>> I think what you wrote should not be allowed. Since ; is used to
>> separate statements, the second line should be a syntactical error.
>> Did you get a different result when you tried this?
>
>   #include "aldor.as"
>   #include "aldorio.as"
>   import from MachineInteger;
>   if (1 < 2) then stdout << "ok" << newline;
>   else stdout << "not ok" << newline;
>
> The current aldor compiler will compile this fine and print "ok".

It looks strange. But I somehow think if the semi-colon is allowed that
should be fine.

> Removing the ; from either of the two last lines will be fine. The only
> thing it does not accept is ;; anywhere.

That ;; is not accepted is somewhat strange. If I look at the grammar,
it says:

Expression: enlist1a(Labeled, ";")

So if ever you find a place in you program where "Expression" is
appropriate, then also ;; should be appropriate.

Ralf

PS: BTW, you don't need (..) around 1 < 2.

_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

Re: Semicolon after single statement in if?

by Pippijn van Steenhoven :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, May 06, 2009 at 03:24:28PM -0700, David Casperson wrote:

> hi folks,
>
> I don't have definite proof that it is legal, but I seem to remember that
>
>       x:=3 ; ++ post
>              ++ document
>
> is a legal expression, and consequently could be substituted for Y in
>
> if Z then Y else other ;
>
> If that is the case
>
>        x:=3 ;
>
> may reduce to an expression (that is followed by a list of zero  
> post-documents).
>
> Does this help?
>
> David
> --
> David Casperson,
> UNBC
Hi,

x := 3; ++ post document

as far as I can tell from the grammar, this would be a

   CurlyContentA (Labelled): CurlyContentB (Labelled) ";" PostDocument

and not an expression. I don't see how a CurlyContents (which is what it
becomes in the end) can become an expression. However, what makes me
think is that the Aldor compiler actually uses this grammar and it
accepts the code, but why? How can it do that? Also, I can see reductions
from "x := 3;" to an AnyStatement but not to BalStatement, which is
required by "if". I am tired, so I will look again, tomorrow, maybe I can
find it.

--
Pippijn van Steenhoven


_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

signature.asc (204 bytes) Download Attachment

Re: Semicolon after single statement in if?

by Pippijn van Steenhoven :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, May 07, 2009 at 01:22:59AM +0200, Ralf Hemmecke wrote:

>> Removing the ; from either of the two last lines will be fine. The only
>> thing it does not accept is ;; anywhere.
>
> That ;; is not accepted is somewhat strange. If I look at the grammar,  
> it says:
>
> Expression: enlist1a(Labeled, ";")
>
> So if ever you find a place in you program where "Expression" is  
> appropriate, then also ;; should be appropriate.
I was wrong. The compiler actually does accept ;;, but not ;;;.
Try:

  a := 3; -- works
  a := 3;; -- works
  a := 3;;;
  .......^
  (Error) Cannot recover from earlier syntax errors.

My (educated, since this happens all the time in the compiler) guess is
that the lexer has hacks to recover from ;; but it kills only one ;, so
the third ; is still read. All these hacks are getting me quite pissed..
Lexing a float, for instance:

  float: integer '.' [ integer ]
       | '.' integer

now notice the operator '.' and the operator '..' in:

  2..3

this could be either of:

  2. . 3
  2. .3
  2 . .3
  2 .. 3

so there is code that takes care of this. I currently use a lookahead
character to decide this, so if I read a float "2.", I look whether the
next character is '.' and if so, push back the '.' into the stream and
return an integer. NAG-Aldor has some more code for this to decide
whether floats can exist in certain lexical contexts. Does the AUG have
anything on this?

--
Pippijn van Steenhoven


_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

signature.asc (204 bytes) Download Attachment

Re: Semicolon after single statement in if?

by Pippijn van Steenhoven :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, May 07, 2009 at 01:22:59AM +0200, Ralf Hemmecke wrote:
> Expression: enlist1a(Labeled, ";")
>
> So if ever you find a place in you program where "Expression" is  
> appropriate, then also ;; should be appropriate.

Forgot to say this: "Expression" is not valid at global scope. It is only
valid if parenthesised or bracketed, so:

  (a := 3;;;;;;)

works fine. Horrible, isn't it?

--
Pippijn van Steenhoven


_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org

signature.asc (204 bytes) Download Attachment

Re: Semicolon after single statement in if?

by Ralf Hemmecke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Lexing a float, for instance:
>
>   float: integer '.' [ integer ]
>        | '.' integer
>
> now notice the operator '.' and the operator '..' in:


>   2..3
>
> this could be either of:
>
>   2. . 3
>   2. .3
>   2 . .3
>   2 .. 3
>
> so there is code that takes care of this.

See AUG Section 22.2. "Tokens"

   The sequence of source characters is partitioned into tokens.
   The longest possible match is always used.

So '2..3' must mean '2 .. 3'.

Anyway, from the regular expressions for float appearing on page 243

[0-9]*`.'[0-9]+{[eE]{[+-]}[0-9]+}
[0-9]+`.'[0-9]*{[eE]{[+-]}[0-9]+}
[0-9]+[eE]{[+-]}[0-9]+
[0-9]+`r'[0-9A-Z]*`.'[0-9A-Z]+{e{[+-]}[0-9]+}
[0-9]+`r'[0-9A-Z]+`.'[0-9A-Z]*{e{[+-]}[0-9]+}
[0-9]+`r'[0-9A-Z]+`e'{[+-]}[0-9]+

I would happily remove the first line. Why would someone want .1 to be a
floating point number. It's much more readable if one writes 0.1, no?

BTW, the AUG also says

A  floating point literal may not
- begin with ".", unless the preceding token is a keyword other
   than ")", "|)", "]" or "}",
- contain ".", if the preceding token is ".",
- end with ".", if the following character is ".".

So your case is explicitly ruled out.

Ralf

_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org