Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Semantics of goto

Semantics of goto 08 Aug 2008 07:57 #7400

I have a few questions regarding goto:

The standard says:

"It is not allowed to jump into a sequence of statements defined in a
compound statement (i.e. alt statement, while loop, for loop, if-else
statement, do- while loop and the interleave statement)."

Is it allowed to jump between the alternatives of an alt statement?

Consider the situation where a forward goto goes over a declaration,
i.e. like this:

control {
goto forward;

var integer i := 5;

forward:

... i ...
}

Does the standard say anything about i in this case, i.e. if the use of
i is a violation, or if it's OK to use it, but its value is unspecified,
or undefined?

Help would be much appreciated!

--
Regards,
Mike
The administrator has disabled public write access.

Semantics of goto 08 Aug 2008 08:35 #7401

Hello Michael,

Michael Sperber wrote:
> I have a few questions regarding goto:
>
> The standard says:
>
> "It is not allowed to jump into a sequence of statements defined in a
> compound statement (i.e. alt statement, while loop, for loop, if-else
> statement, do- while loop and the interleave statement)."
>
> Is it allowed to jump between the alternatives of an alt statement?
>
I think that would be a special case of the mentioned jump into an alt
statement.
So, no, I don't think so (and I don't think it makes much sense, either).

As far as I can remember, the goto was introduced into the language
after labeled break and continue statements (as in Java) were proposed
to be added to the standard, to allow breaking/continuing of nested
loops in a more straightforward way.
Its intention was never to allow to break the proper flow semantics of
structured programming.

> Consider the situation where a forward goto goes over a declaration,
> i.e. like this:
>
> control {
> goto forward;
>
> var integer i := 5;
>
> forward:
>
> ... i ...
> }
>
>
As far as I know, all variable declarations have to come at the
beginning of a block before any control statements (like goto).

Thus, you would need to modify your example to something like to be
allowed TTCN-3:

goto forward;
...
{
var integer i := 5;
...
label forward;
... i ...
}

However, since the variable declaration with initialization is simply
syntactic sugar for a declaration (which is not a statement in itself,
but only meta information about this scope for the compiler to be able
to check type-correctness) without initialization and an additional
assignment, I think the result of jumping over the assignment would be
that the variable still is declared, but (if it is not assigned after
the jump label) not initialized, leading to a runtime error, if it is
used as Rvalue.


> Does the standard say anything about i in this case, i.e. if the use of
> i is a violation, or if it's OK to use it, but its value is unspecified,
> or undefined?
>
I'm sure it does, somewhere.
> Help would be much appreciated!
>
>
Best regards,

Jacob Wieland

--
Jacob Wieland
Software Engineer

Testing Technologies IST GmbH
Michaelkirchstraße 17/18
10179 Berlin, Germany

Phone +49 30 726 19 19 34 Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Fax +49 30 726 19 19 20 Internet www.testingtech.com

UPCOMING EVENTS!

August 13, Free TTCN-3 Webinar, 5:00 pm CET
www.testingtech.com/services/ttcn3_webinar.php

August 28-29, Toolapalooza India
Cisco Systems, Inc, Bangalore, India
www.cisco.com

September 17-18, Ericsson PM&T Conference
Linköping, Sweden, Booth #8
www.ericsson.com

Geschäftsführung: Theofanis Vassiliou-Gioles, Stephan Pietsch
Handelsregister HRB 77805, Amtsgericht Charlottenburg
Ust ID Nr.: DE 813 143 070

This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
The administrator has disabled public write access.

Semantics of goto 08 Aug 2008 08:49 #7402

Thanks for the prompt answers!

Jacob Wieland <This email address is being protected from spambots. You need JavaScript enabled to view it.> writes:

> As far as I know, all variable declarations have to come at the
> beginning of a block before any control statements (like goto).

I don't see this restriction in the standard. The grammar has this:

171 StatementBlock ::= "{" [FunctionStatementOrDefList] "}"
172 FunctionStatementOrDefList ::= {FunctionStatementOrDef [SemiColon]}+
173 FunctionStatementOrDef ::= FunctionLocalDef |
FunctionLocalInst |
FunctionStatement
174 FunctionLocalInst ::= VarInstance | TimerInstance

(I agree it would make many things easier if the declarations would have
to come at the beginning.)

--
Regards,
Mike
The administrator has disabled public write access.

Semantics of goto 08 Aug 2008 08:53 #7403

Hello Michael,

This is stated in clause 5.3:

5.3 Ordering of language elements
Generally, the order in which declarations can be made is arbitrary. Inside a statement block, such as a function body or a branch of an if-else statement, all declarations (if any), shall be made at the beginning of the statement block only.

Best regards

Thomas

|
| Thomas Deiß |
| Nokia Siemens Networks |
| Heltorferstrasse 21, D-40472 Düsseldorf, Germany |
| Internal: 828 3584 |
| Mob: +49 151 5515 3584, tel: +49 211 9412 3584 |
| email: This email address is being protected from spambots. You need JavaScript enabled to view it. |
|


>
Original Message
>From: active_ttcn3 : mts stf133 ttcn version 3 - active
>members only [This email address is being protected from spambots. You need JavaScript enabled to view it.] On Behalf Of ext
>Michael Sperber
>Sent: Friday, 08. August 2008 10:49
>To: This email address is being protected from spambots. You need JavaScript enabled to view it.
>Subject: Re: Semantics of goto
>
>Thanks for the prompt answers!
>
>Jacob Wieland <This email address is being protected from spambots. You need JavaScript enabled to view it.> writes:
>
>> As far as I know, all variable declarations have to come at the
>> beginning of a block before any control statements (like goto).
>
>I don't see this restriction in the standard. The grammar has this:
>
>171 StatementBlock ::= "{" [FunctionStatementOrDefList] "}"
>172 FunctionStatementOrDefList ::= {FunctionStatementOrDef
>[SemiColon]}+
>173 FunctionStatementOrDef ::= FunctionLocalDef |
> FunctionLocalInst |
> FunctionStatement
>174 FunctionLocalInst ::= VarInstance | TimerInstance
>
>(I agree it would make many things easier if the declarations
>would have to come at the beginning.)
>
>--
>Regards,
>Mike
>
The administrator has disabled public write access.

Semantics of goto 09 Aug 2008 13:53 #7404

Thomas Deiss <This email address is being protected from spambots. You need JavaScript enabled to view it.> writes:

> This is stated in clause 5.3:
>
> 5.3 Ordering of language elements
> Generally, the order in which declarations can be made is
> arbitrary. Inside a statement block, such as a function body or a
> branch of an if-else statement, all declarations (if any), shall be
> made at the beginning of the statement block only.

Ah, I'd overlooked this. Thanks!

Any special reason this restriction isn't encoded in the grammar?

--
Regards,
Mike
The administrator has disabled public write access.

Semantics of goto 11 Aug 2008 07:29 #7405

Hi Mike,

I cannot recall any, most probably historic reason. I wrote a CR to bring this rule into the bnf as it really would increase clarity and should not be backward-incompatible as the restriction already exists.

BR, Gyorgy

>
Original Message
> From: active_ttcn3 : mts stf133 ttcn version 3 - active
> members only [This email address is being protected from spambots. You need JavaScript enabled to view it.] On Behalf Of Michael Sperber
> Sent: Saturday, 09 August, 2008 3:53 PM
> To: This email address is being protected from spambots. You need JavaScript enabled to view it.
> Subject: Re: Semantics of goto
>
> Thomas Deiss <This email address is being protected from spambots. You need JavaScript enabled to view it.> writes:
>
> > This is stated in clause 5.3:
> >
> > 5.3 Ordering of language elements
> > Generally, the order in which declarations can be made is
> arbitrary.
> > Inside a statement block, such as a function body or a branch of an
> > if-else statement, all declarations (if any), shall be made at the
> > beginning of the statement block only.
>
> Ah, I'd overlooked this. Thanks!
>
> Any special reason this restriction isn't encoded in the grammar?
>
> --
> Regards,
> Mike
>
The administrator has disabled public write access.
  • Page:
  • 1

FacebookTwitterGoogle BookmarksRedditNewsvineTechnoratiLinkedin