List of allowed keywords for UDT members naming

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

List of allowed keywords for UDT members naming

Postby TJF » Jan 04, 2013 22:29

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: 3207
Joined: Jul 28, 2005 14:45
Location: Germany

Re: List of allowed keywords for UDT members naming

Postby dkl » Jan 05, 2013 20:02

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: 3473
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: List of allowed keywords for UDT members naming

Postby TJF » Jan 06, 2013 19:47

Thank you!

Code: Select all

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

Re: List of allowed keywords for UDT members naming

Postby fxm » Jan 06, 2013 19:57

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

Postby 1000101 » Jan 07, 2013 23:59

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

Re: List of allowed keywords for UDT members naming

Postby dodicat » Jan 08, 2013 1:06

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

Re: List of allowed keywords for UDT members naming

Postby 1000101 » Jan 08, 2013 1:09

That's grandfathered in. ¬¸¬

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests