List of allowed keywords for UDT members naming

General FreeBASIC programming questions.
Post Reply
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

List of allowed keywords for UDT members naming

Post by TJF »

We can use FB keywords to name the members of an UDT, ie for variables like

Code: Select all

TYPE FB_DEFTOK
  TYPE AS FB_DEFTOK_TYPE
  prev AS FB_DEFTOK PTR
  NEXT AS FB_DEFTOK PTR
END TYPE
But some keywords are forbidden, like AS, UNION, ENUM, END, ...

Is there a list of all allowed (or forbidden) keywords in an UDT (or parameter list)?
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: List of allowed keywords for UDT members naming

Post by dkl »

For normal struct UDTs all identifiers are allowed including core keywords and quirk keywords, although due to the parsing ambiguity, if you want the parser to treat something as field identifier, you sometimes have to use the "AS TYPE id" multiple-declaration syntax instead of the normal "id AS TYPE" single-declaration one.

Code: Select all

type UDT
	'dim as integer    '' Parsed as DIM declaration, so the DIM is not the identifier
	as integer dim     '' but this works, DIM is the identifier

	'' ditto... we can even have a field called "as"
	as integer declare, static, as

	'' works thanks to the parser doing a look-ahead and finding the AS,
	'' indicating a field called "union" instead of a UNION block
	union as integer
end type

dim x as UDT
print x.dim, x.declare, x.static, x.as, x.union
In class UDTs, core keywords are not allowed as field names (probably due to parsing difficulties thanks to the implicit THIS field accesses from within method bodies), however quirk keywords are still allowed.

The few operator keywords (AND, OR, SHL, ...) are forbidden in both cases, although I think that wouldn't be necessary at least for struct UDTs.

For reference: src/compiler/symb-keyword.bas(27)
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: List of allowed keywords for UDT members naming

Post by TJF »

Thank you!

Code: Select all

TYPE unbeleavable
  AS BYTE AS
  BYTE AS BYTE
END TYPE
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: List of allowed keywords for UDT members naming

Post by fxm »

But only for non-derived UDT without member procedure!
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Re: List of allowed keywords for UDT members naming

Post by 1000101 »

It would probably be a good idea not to use any keywords as identifiers just to avoid confusion.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: List of allowed keywords for UDT members naming

Post by dodicat »

1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Re: List of allowed keywords for UDT members naming

Post by 1000101 »

That's grandfathered in. ¬¸¬
Post Reply