xsharp.eu • parentheses for arrays?
Page 1 of 1

parentheses for arrays?

Posted: Mon Oct 05, 2020 8:01 pm
by kevclark64
I'm wondering what the prospects are for being able to use parentheses for arrays in the Foxpro dialect. Right now, any code that is converted from FoxPro must have square brackets for arrays.

parentheses for arrays?

Posted: Tue Oct 06, 2020 6:04 am
by robert
Kevin,
We will try to add this support, but it is not as easy as you may think.
The compiler needs to distinguish between

Code: Select all

SomeFunction(1,2)
and

Code: Select all

SomeVariable(1,2)
and this needs "context" information, so if can only be done in a later phase in the compiler.
Wen the parser sees the parentheses it cannot decide what this will mean. After a lookup has shown that SomeFunction is a function and SomeVariable a variable then the compiler can resolve this.

With the

Code: Select all

SomeVariable[1,2]
syntax, this is much easier, since this is less ambiguous.

In FoxPro this work differently since FoxPro is not a real compiler. It converts this into a list of tokens and evaluates the expression at runtime and does a lookup.

Robert

parentheses for arrays?

Posted: Tue Oct 06, 2020 2:40 pm
by atlopes
Robert,

If the array is declared as a variable, and so an unambiguous context is provided to the compiler, would it be possible to support the parenthesized syntax for addressing the array's element?

parentheses for arrays?

Posted: Tue Oct 06, 2020 2:45 pm
by robert
Antonio
atlopes wrote:Robert,

If the array is declared as a variable, and so an unambiguous context is provided to the compiler, would it be possible to support the parenthesized syntax for addressing the array's element?
I checked how the Roslyn parser for VB does this, and it parses

Code: Select all

Foo(1,2)
as a "InvocationExpression"
and later when the binder detects that Foo is a local variable and not a function/method then it converts that to an ArrayAccessexpression.

We can probably do the same. We "just" need to make sure not to break anything else.

Robert