Skip to content
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

Unable to parse the specific macros #142

Open
DrXiao opened this issue Jul 18, 2024 · 1 comment
Open

Unable to parse the specific macros #142

DrXiao opened this issue Jul 18, 2024 · 1 comment

Comments

@DrXiao
Copy link
Collaborator

DrXiao commented Jul 18, 2024

With the discussion in the pull request (#140) , we found that shecc cannot deal with macros containing assignment and compound assignment operators.

Here are the examples:

#define MACRO1(variable, val) \
               variable = variable + val + 10
#define MACRO2(variable, val) \
               variable += val + 10

By GCC or Clang, the above macros will be expanded and perform the operations, but shecc cannot parse them correctly.

Therefore, the lexer/parser must be improved to handle macros like these examples.

@jserv
Copy link
Collaborator

jserv commented Jul 18, 2024

Comments from @ChAoSUnItY :

The compound assignment operators consist of a binary operator and the simple assignment operator. At present, there is no support for compound assignment operators.

The current situation is that read_body_assignment is failed to realize the macro variable and thus returns false since it's possibly not a local variable nor a global variable, which ultimately results in the parser failed to parse current variable and terminated at the operator.
 
Currently, it seems rather tricky to implement due to the technical debt of macro parsing design (we're not able to determine which syntax parsing we should use to parse macro parameter). Moreover, if we predict it's a lvalue (which in this case it should be) and we use read_lvalue function to parse the parameter, the function requires a non-null var_t, which is impossible because we haven't even parsed macro parameter's actual expression; if we predict it's an expression, we'll lose the target address of the lvalue.

This probably could be resolved after we implement tangle back to shecc since macro expansion would only happens in lexer and parser doesn't have to predict what parsing strategy should be used for the expanded macro parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants