freebasic / fbc

FreeBASIC is a completely free, open-source, multi-platform BASIC compiler, with syntax similar to MS-QuickBASIC, that adds new features such as pointers, object orientation, unsigned data types, inline assembly, and many others.
https://www.freebasic.net
877 stars 137 forks source link

Parsing error with var-len arrays in UDT #355

Open mudhairless opened 2 years ago

mudhairless commented 2 years ago

Issue is present in both 32 and 64 bit compilers with versions 1.09.0, 1.08.1, and 1.07.3 known affected.

Error message from compiler: fbc-issue.bas(10) error 3: Expected End-of-Line, found '.' in 'redim test(0,0).array(0)'

I have only tested this on Windows but it should not differ between platforms.

type aType
    array(any) as integer
end type

dim test(any,any) as aType

redim test(0,0)

'doesnt work
redim test(0,0).array(0)

'works
redim (test(0,0).array)(0)
dkl commented 1 year ago

Some related information: This sounds to me like it's the classic redim parsing issue. Since it can be used to declare variables, there needed to be some differentiation between redim id(... and redim expression.... So I think redim test(0,0) looks like a variable declaration and the parser simply doesn't look-ahead far enough to see the .array(0) following behind it which could be used to indicate that it's actually an expression.

On the one hand, it doesn't have infinite look-ahead (if I remember correctly), on the other hand it can't really parse an expression it it's an array declaration, because the symbol isn't defined yet, (lower to upper) isn't valid in expressions, etc. It would be quite a challenge to try and work-around that. I remember using the extra parentheses as in redim (expression) to avoid the issue.