#P3997. Super macros
Super macros
Problem Description
SuperHacker is a advanced Hacker. He often write GNU style macros to optimize the programs. One day pooorman gave him a batch of ugly style c code using nested ternary operator (? :), which makes the code difficult to comprehend.
Now SuperHacker turn to you for help, he have write a program to collect all the ugly code into a file, he send such file to you. Please write a utility to convert such file into a GNU C marcos header file.
Input
Input contains multiple valid (nested) c ternary operator expression. Each will be ended with a semicolon. There will be no empty expressions.
Output
For each case, generate a GNU C style macro function named with SuperHacker_functionn, n is the case num, which is started from 0. There should be a blank line between each case. Each case should be output as the Sample Output below.
Each line of the output should be indented well with tab(\t) as Sample output. The trailing line continuing symbol backslashs(\) macro end symbol '})' at the last line of a macro should be right aligned with tabs aligned. Each continuing symbol and macro end symbol '})' should be seperated with the code in such line with at least one tab indent. The tab symbol considered 8 word width.
To make the macro file includable, you should add some code to prevent multiple including at the begin and end of the output file, Same as the sample output below.
You should trim the redundancy parenthesis.
a? b: c;
((a)? b: c)?
(d): e;
( welcome_to_acm_icpc_online_judge ) ;
#ifndef MACROS_H
#define MACROS_H
#define SuperHacker_function0() \
({ int _r; \
if (a) \
_r = b; \
else \
_r = c; \
_r; })
#define SuperHacker_function1() \
({ int _r; \
if (a) \
{ \
if (b) \
_r = d; \
else \
_r = e; \
} \
else \
{ \
if (c) \
_r = d; \
else \
_r = e; \
} \
_r; })
#define SuperHacker_function2() \
({ int _r; \
_r = welcome_to_acm_icpc_online_judge; \
_r; })
#endif /* MACROS_H */