-
Notifications
You must be signed in to change notification settings - Fork 260
parsing '*' fails due to a confusion between postfix and infix operator #50
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
Comments
Looks like |
As @gregmarr says, done -- see latest commit (sorry, forgot to reference this issue). Thanks! Yes, this is intentional and I'll write up a design note about it... in short, there is a tension between two things:
So if we want to have both, we have a few choices, including:
(*) for now please grant this for the sake of discussion... briefly, this follows from declaration syntax mirroring use syntax and as I promised in the talk, I'll write it up soon |
Examples like `f<a+a>` should be parsed as an _expression_ first (if it can be an expression, it is), and then if that fails parsed as an _id-expression_ The original comment was correct about the production order, so put that back to how it was Added a regression test case
The commit 1943783 changes the parse order, assuming that if a template argument can be parsed as an expression it is an expression. But note that this does not work in all cases. This example here
cannot be parsed without type information on Having the parser depend on type information is a nightmare, of course. It requires a complex parser, and it prevents order-independent parsing (i.e., it requires forward declarations to work properly). IMHO we should change the template syntax to prevent that anomaly. If we would use, e.g., |
Hi! You closed the PR but I hadn't replied to all your good questions yet. Here are answers to the other two questions. Q: Parse ambiguity of
|
I just noticed your reply while I was writing my longer one:
No, Cpp2 never does name lookup to guide parsing, I agree with you that that's a bad thing (see above). In Cpp2, that code greedily parses In Cpp2, to call
Yes, but see (*) above... I'm open to that as a last resort if nothing else works, but I think(?) what's there now is a good resolution (see the final "Note these complications don't arise in C#, even though C# also uses |
Examples like `f<a+a>` should be parsed as an _expression_ first (if it can be an expression, it is), and then if that fails parsed as an _id-expression_ The original comment was correct about the production order, so put that back to how it was Added a regression test case
The parser eagerly turns
*
into postfix operators, which is not always correct. Consider the example below:It fails to compile in cppfront with an error message (
missing ';'
). The error goes away when adding a space in front of the*
because the parser then does not recognize it as postfix operator. But insisting on a whitespace in front on a binary operator seems questionable, it is a significant deviation from regular C++.In general the postfix
*
and&
operators are problematic, as they create an ambiguity with binary*
and&
. Resolving that requires either an LR(2) parser or a lot of lexer magic to recognize these as postfix operators. Having them as prefix operators would be easier.There are also other ambiguities in the grammar, some of them probably fixable (e.g.,
template-argument -> expression | id-expression
, but if the expression is an identifier the parser cannot distinguish these cases), some of them probably unfixable without major changes to the language (e.g., template syntax, there the parser cannot parsea<b,c>d
correctly without knowing ifa
is a template or not). I am not sure if it makes sense to open bugs for all of them. If you want I can report them, of course, but I do not want to spam the issue tracker with problems if you only consider the syntax experimental anyway. (On the other hand it is probably useful to know if the suggested syntax works or not).The text was updated successfully, but these errors were encountered: