parentheses for arrays?

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

parentheses for arrays?

Post 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.
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

parentheses for arrays?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
atlopes
Posts: 83
Joined: Sat Sep 07, 2019 11:43 am
Location: Portugal

parentheses for arrays?

Post 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?
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

parentheses for arrays?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply