-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
what syntax should we use for pointer types? #523
Comments
I think use of postfix Regarding the options with a postfix
Swift uses this approach for operators in general. I like this model in principle, assuming we apply it generally across the language, but some costs of doing so are discussed in #520.
This needs more exploration; it's not clear to me what constraints we need to apply to the precedence rules in order for this to be meaningful and parseable in linear time. For example, do we need postfix
I think this is problematic:
I think this is problematic:
|
To add a touch of nuance to my stance here... I think we should, for now, assume that we can have one of the first two options (either through a very cautious application of #520 or through more specialized precedence rules as suggested in the second point). And we should work at implementing #520 to understand how well that works, and if problems emerge, try implementing the next thing. But to the other question, I'd not anchor on which specific pointer-like type (or semantic set) this syntax ends up referring to. As we refine and delineate the different semantics we want, we should point the familiar syntax of What do folks think about this path forward? Any major concerns? |
As an alternative, have we considered using prefix It makes the parsing nice and simple, without requiring whitespace-sensitivity, and it matches existing languages. Sorry if this has already been considered and rejected -- I just wanted to check, since I didn't see it here. |
Pointers and arrays should probably be considered together if you're proposing different fixity;
Note Go keeps the same call syntax ( |
Yes, I agree that we should consider pointer and array types together. Personally, I like Go's syntax here: it exactly matches how you read these types, and also has the advantage that multidimensional arrays keep their sizes in the same order as C++. (That is, |
The irony here is Go's syntax makes me more sympathetic to post-fix That is to say, OTOH I would definitely avoid D's syntax. At a glance it's a syntax which is similar to C++, and superficially compatible, but just different enough to cause programming errors by C++ developers who don't realize the order swapped. |
If |
So we conclude from this that we don't want a postfix operator for declaring array types (assuming we want to specify array bounds as part of the syntax). Prefix array modifiers work better with a prefix pointer modifier to avoid needing parenthesis to disambiguate the order. Or we could do other array syntaxes. |
I've tried to capture the various options for different pointer syntaxes in this doc. |
One thing that hasn't been discussed yet is avoiding |
Should have said -- or any other syntax that is fundamentally different in its tradeoffs by not trying to use basic nesting to establish the dimensionality. |
After the open discussion today, both Richard and I were pretty happy with one specific outcome here, curious if anyone sees a problem here. High level result:
Some related things:
|
I think we wanted I don't see how the parenthesis in
This just seems super dangerous and hard to diagnose. |
I would suggest not nesting for multidimensional arrays....
I find this much less surprising than without paretheses.
Maybe. Talking with @mconst it seemed significantly less surprising than w/o the parentheses. But really, all of this is just thoughts to factor into future discussions, not something we should try to sort out now. |
Given that we've switched from In an attempt to demonstrate that this is unambiguous, I think the following local syntactic rule does the right thing in all cases (at least given our current set of grammar productions):
This does rely on there being no binary operators that can syntactically accept |
AFAICT that would mean Yacc can't parse it at all, and Bison can parse it only in its GLR mode, which sounds liable to add a good deal of unwelcome complexity:
|
I think in #520 we're coming up with reasonably robust ideas for disambiguating this that won't hit the parsing challenges raised here by @geoffromer and @zygoloid so for now I'd like to suggest we resolve this for now with my proposed guidance above:
For arrays, I would suggest continuing to write Marking as closed as I think this is a workable state that at least Richard and I were comfortable with in discussion and we've not heard serious concerns with (other than making sure the parsing strategy doesn't go down the expensive paths of GLR and other things -- we're definitely going to invest in avoiding that!). That said, if there is outstanding confusion here or anyone really disagrees with my read on things, please re-open! |
FWIW, this doc is not publicly accessible. |
Here's a publically accessible mirror |
C and C++ use prefix
*
for dereference, infix*
for multiplication, and use syntax that superficially resembles using postfix*
for forming pointer types (although it's actually a prefix*
applied to a declarator).From a comment by @josh11b in #520 (comment):
The text was updated successfully, but these errors were encountered: