-
Notifications
You must be signed in to change notification settings - Fork 17
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
Ignore casts when evaluating #defines #86
Comments
This looks very fixable. Probably requires dealing with casts in the expression parser though. @sMezaOrellana can you perhaps recommend the best way to add this to your parser? |
I will try to have a proper look in the coming days. def evaluate(self, context: Optional[dict[str, int]] = None) -> int:
"""Evaluates an expression using a Shunting-Yard implementation."""
...
while i < len(tmp_expression):
current_token = tmp_expression[i]
...
elif current_token == "sizeof":
if len(tmp_expression) < i + 3 or (tmp_expression[i + 1] != "(" or tmp_expression[i + 3] != ")"):
raise ExpressionParserError("Invalid sizeof operation")
self.queue.append(len(self.cstruct.resolve(tmp_expression[i + 2])))
i += 3
...
elif current_token == "(":
if i > 0:
previous_token = tmp_expression[i - 1]
if self.is_number(previous_token):
raise ExpressionParserError(
f"Parser expected sizeof or an arethmethic operator instead got: '{previous_token}'"
)
self.stack.append(current_token)
elif current_token == ")":
if i > 0:
previous_token = tmp_expression[i - 1]
if previous_token == "(":
raise ExpressionParserError(
f"Parser expected an expression, instead received empty parenthesis. Index: {i}"
)
...
while len(self.stack) != 0:
if self.stack[-1] == "(":
raise ExpressionParserError("Invalid expression")
self.evaluate_exp()
return self.queue[0] Take for example This could simply evaluate to 10. In practise a simple solution would be to change the case where Does cstruct implement casting? I hope this helps. And will look at this properly sometime this week. |
We don't really support casting, no. The new v4 (#35) should make this easier/possible, but it's not a feature as of yet. |
For example:
causes A, B and C to have string values like
"(A | B)"
instead of the numeric values.The text was updated successfully, but these errors were encountered: