Skip to content

Fail to parse expression inside parenthesis for post increment/decrement #118

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mingodad opened this issue Jul 26, 2023 · 1 comment
Closed

Comments

@mingodad
Copy link

Here is a sample test to show the problem:

int fib(int n)
{
    if(n < 2) return 1;
    return fib(n-2)+fib(n-1);
}

int addOneFirst(int &n)
{
	return ++(n);
}

int addOneAfter(int &n)
{
	return (n)++;
}

int minusOneFirst(int &n)
{
	return --(n);
}

int minusOneAfter(int &n)
{
	return (n)--;
}

Output:

test.cpp:14:14: expected an expression
	return (n)++;
	            ^
test.cpp:24:14: expected an expression
	return (n)--;
	            ^
@robertoraggi
Copy link
Owner

@mingodad this looks like an ambiguity between nested expressions and prefixes of C-style casts. I will push a temporary workaround to resolve these kind of parse conflicts until we have the type checker running during parsing. Thanks for the report.

robertoraggi added a commit that referenced this issue Aug 12, 2023
Also, removed old test cases that are not needed anymore.
@robertoraggi robertoraggi linked a pull request Aug 12, 2023 that will close this issue
robertoraggi added a commit that referenced this issue Aug 13, 2023
Also, removed old test cases that are not needed anymore.
robertoraggi added a commit that referenced this issue Aug 14, 2023
This is a temporary workaround to accept a larger subset of
increments expressions.
robertoraggi added a commit that referenced this issue Aug 14, 2023
This is a temporary workaround to accept a larger subset of
increments expressions.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants