Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inline-declared variables #973

Open
ghaith opened this issue Sep 25, 2023 · 0 comments · May be fixed by #991
Open

Add support for inline-declared variables #973

ghaith opened this issue Sep 25, 2023 · 0 comments · May be fixed by #991

Comments

@ghaith
Copy link
Collaborator

ghaith commented Sep 25, 2023

Is your feature request related to a problem? Please describe.
As part of #947 it makes sense to support on the fly declaration of temporary variables for all languages

Describe the solution you'd like
In ST these variables would then have to be marked with a Pragma, and in general will behave as temp variable. They come into scope on the line they are declared in. And out of scope if their parent scope is also going out of scope (Control statements).

A declaration can look like this:

{inline} a := 1; //Declares an auto typed variable, the type is derived from the first annotation
{inline} b : DINT := 2; //Declares a DINT
@ghaith ghaith changed the title Add support for inlined variables Add support for inline-declared variables Sep 25, 2023
ghaith pushed a commit that referenced this issue Oct 18, 2023
Variables can be defined in the body using the syntax
```st
{def} VAR y : DINT := 0; (*Pragma to avoid confusion with var blocks *)
(*Pragma is optional once in body*)
VAR x := 0; (*Implicit type declaration to DINT*)
FOR VAR x := 0 TO 10 BEGIN
(*Implicit variable declaration as loop counter*)
END_FOR
```

Ref: #973
@ghaith ghaith linked a pull request Oct 18, 2023 that will close this issue
@ghaith ghaith linked a pull request Oct 18, 2023 that will close this issue
ghaith pushed a commit that referenced this issue Oct 24, 2023
Variables can be defined in the body using the syntax
```st
{def} VAR y : DINT := 0; (*Pragma to avoid confusion with var blocks *)
(*Pragma is optional once in body*)
VAR x := 0; (*Implicit type declaration to DINT*)
FOR VAR x := 0 TO 10 BEGIN
(*Implicit variable declaration as loop counter*)
END_FOR
```

Ref: #973
ghaith pushed a commit that referenced this issue Nov 10, 2023
Variables can be defined in the body using the syntax
```st
{def} VAR y : DINT := 0; (*Pragma to avoid confusion with var blocks *)
(*Pragma is optional once in body*)
VAR x := 0; (*Implicit type declaration to DINT*)
FOR VAR x := 0 TO 10 BEGIN
(*Implicit variable declaration as loop counter*)
END_FOR
```

Ref: #973
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant