[fpc-devel] Declare variables inside the code

Hans-Peter Diettrich DrDiettrich1 at aol.com
Tue May 10 23:50:29 CEST 2011

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" .


More information about the fpc-devel mailing list