PARAMETERS, LOCAL DATA & CREATE STATEMENT
This resolves #113 (closed). Currently only LOCAL DATA
section is implemented for now, I'll implement PARAMETERS
later, you can review and test the code in the meantime.
Example:
DATA:
x is number
PROCEDURE:
sub-procedure foo
LOCAL DATA:
i is number
PROCEDURE:
incr i
display "FOO " i crlf
end sub-procedure
sub-procedure bar
LOCAL DATA:
i is text
PROCEDURE:
join i and "-" in i
display "BAR " i crlf
end sub-procedure
for x from 0 to 10 step 1 do
call foo
call bar
repeat
Output:
FOO 1
BAR -
FOO 2
BAR --
FOO 3
BAR ---
FOO 4
BAR ----
FOO 5
BAR -----
FOO 6
BAR ------
FOO 7
BAR -------
FOO 8
BAR --------
FOO 9
BAR ---------
FOO 10
BAR ----------
All the variable declaration statements where merged to only one if to reduce duplicated code.
We store in which subprocedure a variable was declared and when we expect some variable we search it in the current subprocedure and main variables. The function variable_type
handles this.
To keep the variable values persistent, we fix the C++ identifier based on the subprocedure (for example, LVAR_SUBPR_FOO_VAR_I
) and declare it as a global variable.
The PROCEDURE:
label is optional if the subprocedure only has procedure statements. This was implemented with the in_procedure_section
function.