Parenthesis calculator for C/C++ expressions operator precedence

谁说我不能喝 提交于 2020-01-02 10:17:52

问题


After porting some obfuscated C code into C++ (namely Fairy-Max chess engine by Harm Geert Muller), I get lots of warnings similar to these:

suggest parentheses around comparison in operand of '&' [-Werror=parentheses]

suggest parentheses around '+' in operand of '&'

While turning off the warnings is not an option, the solution is to add parenthesis in expressions according to the operator precedence.

For example:

if(z&S&&!ab&K==INF&d>2&v>V&v<Beta){

needs to be transformed into this:

if((z&S) && ((!ab)&(K==INF)&(d>2)&(v>V)&(v<Beta))) {

But doing this manually is quite time-consuming.

I tried to use this deobfuscation tool, which uses clang-format internally, but it does not add parenthesis into expressions...

Question

Is there a tool (preferably online) that can take a C/C++ expression as an input and return a warnings-free equivalent expression as an output?


回答1:


Geordi can do it.

I've long wanted a web version, but last time I tried to get Geordi working on my VPS I failed miserably due to Haskell dependency gubbins. May give it another go one day.

Meanwhile, you can log onto Freenode IRC and /msg geordi --precedence *p->data (for example). You'll get a private message tab open up with the result (e.g. *(p->data)). Feel free to keep sending --precedence <expression> requests in that tab.



来源:https://stackoverflow.com/questions/56424972/parenthesis-calculator-for-c-c-expressions-operator-precedence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!