r/Compilers • u/Caspianrz • 22d ago
Using dot as universal member access
I've been designing and implementing my own programming language for about two years now.
In my previous experience with programming languages, I've noticed that different operators are commonly used for member access depending on the kind of entity being accessed:
structure.member
pointer->member
namespace::memberThis is a pretty common approach in several widely used languages.
Over the past year, however, I decided to remove the -> operator from my language. Similar to Rust, I allow implicit pointer dereferencing during member access. So, whenever the compiler encounters a member access expression (base, member), it first checks the type/category of base. If it's a pointer, it dereferences it before resolving the member.
Now I'm working on namespace support, and I'm wondering whether I can apply the same idea here: check what `base` resolves to, and if it's neither a pointer nor a structure/object, treat it as a namespace and resolve the member within it.
Essentially, I'm considering using . as a universal member access operator:
object.merember
pointer.member
namespace.memberMy questions are:
- Am I overlooking any semantic or syntactic issues with this approach?
- Are there any good reasons to keep separate operators for object, pointer, and namespace access?
- Is implicit pointer dereferencing during member access a good design choice, or could it introduce problems as the language evolves?
I'd appreciate insights from people who have designed or implemented programming languages, particularly regarding name resolution and type checking.
