[fpc-devel] Declare variables inside the code
kingbizugo at gmail.com
kingbizugo at gmail.com
Tue May 10 23:32:11 CEST 2011
Em 10/05/2011 18:50, Hans-Peter Diettrich escreveu:
> kingbizugo at gmail.com schrieb:
>> *I have been playing on other languages sometimes and I see some
>> features that speed-up a lot the code creating. I'm posting here one,
>> I want to see what you think about it.
>> *
>> *Good:* fast algorithm testings, code creating
>> *Bad?:* not a standard of the pascal language
>>
>> /*method* MyMethod;
>> *var* A, B: Integer;
>> *begin
>> *
>> { Simple sample of a variable inside the method begin/end near to a
>> for-loop }
>> *var* I: Integer;
>> *for* I := a *to* b *do*...
>>
>> { Or even }
>> *for* *var* J: Integer := a *to* b *do*...
>> { This is normal on languages like C++ and Java }
>>
>> /*/end;/
>> *
>> *What do you think about*?
>
> This could be made compatible with the FPC handling of Body, where
> e.g. a program or a procedure body is a Body, parsed by
> tcgprocinfo.parse_body().
>
> The only required parser modification had to treat a For statement as
> a Body, with an (optional) specialized Var section at its begin, and a
> Statement after Do.
>
>
> But this solution would look strange to C coders, which expect
> variable declarations *after* the begin of an block, while Pascal
> expects local variables declared *before* the begin of an block. OTOH
> I don't think that it would be a big deal to allow for Pascal
> declarations also at the begin of an block. The syntax would look like:
>
> Block = "BEGIN" [Declarations] {Statement} "END" .
>
> DoDi
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
This already help, but what about declaring also after some code?
I like on Java/C++/PHP that I can create a for-loop that creates the
counter... sample on PHP:
for(var; condition; step) for($var=0; $var<1000; $var += 1)
This syntaxe is possible on C++, Java (its not equal, but its something
very close).
I would like to be able this:
[ some code after begin ]
DoSomething;
var I: Integer;
for I := 0 to 1000 do
DoAnotherThing(I);
[ inside the code ]
More information about the fpc-devel
mailing list