Here is a more complete example.
Needs["SymbolicC`"]
ClearAll[fun, $opsPatt];
$opsPatt =
Alternatives @@ {Minus, PreDecrement, Decrement, PreIncrement,
Increment, Greater, Less, GreaterEqual, LessEqual, Equal, Unequal,
Mod, Divide, Times, Subtract, Plus, BitShiftLeft, BitShiftRight,
BitAnd, BitXor, BitOr, And, Or, Not};
$head = Alternatives @@ {char, int, float, double, void};
SetAttributes[fun, HoldAll];
fun[code_] := Hold[code] //. {
(head : $opsPatt)[x_, y_] :> COperator[head, {x, y}],
HoldPattern[Set[x_, (head_: $head)[y_]]] :>
CDeclare[head, CAssign[x, y]],
HoldPattern[Set[lhs_, rhs_]] :> CAssign[lhs, rhs],
(*standardmathoperator[x___]\[RuleDelayed]CStandardMathOperator[
x],HoldPattern[RuleDelayed][test,a]*)
conditional[x___] :> CConditional[x],
expression[x___] :> CExpression[x], block[x___] :> CBlock[x],
program[x___] :> CProgram[x], statement[x___] :> CStatement[x],
do[x___] :> CDo[x], for[x___] :> CFor[x], if[x___] :> CIf[x],
switch[x___] :> CSwitch[x], default[x___] :> CDefault[x],
while[x___] :> CWhile[x], cast[x___] :> CCast[x],
HoldPattern[RuleDelayed][x_, c___] :> CDeclare[x, c],
HoldPattern[StringExpression][x___] :> CDeclare[x],
enum[x___] :> CEnum[x], pointertype[x___] :> CPointerType[x],
struct[x___] :> CStruct[x], union[x___] :> CUnion[x],
typedef[x___] :> CTypedef[x], sizeof[x___] :> CSizeOf[x],
return[x___] :> CReturn[x], break[x___] :> CBreak[x],
continue[x___] :> CContinue[x], goto[x___] :> CGoto[x],
label[x___] :> CLabel[x], member[x___] :> CMember[x],
HoldPattern[Rule][x___] :> CPointerMember[x],
Function[x___] :> CAddress[x], $[x___] :> CDereference[x],
array[x___] :> CArray[x],
constant[x___] :> CConstant[x],(*comment[
x___]\[RuleDelayed]CComment[x] parentheses[
x___]\[RuleDelayed]CParentheses[x],*)str[x___] :> CString[x],
include[x___] :> CInclude[x], define[x___] :> CDefine[x],
error[x___] :> CError[x], line[x___] :> CLine[x],
pragma[x___] :> CPragma[x], undef[x___] :> CUndef[x],
fn[t_, n_, args_, x___] :> CFunction[t, n, args, {x}]};
t = fun@program[
include["stdlib.h"],
include["constants.h"],
fn[int, yGreaterX, {{int, x}, {int, y}},
i = int[3],
if[x < y,
block[{
i = int[3]
}], block[{
x = int[4]
}]
],
return[i]
]
];
StringReplace[
ToCCodeString[ReleaseHold@t, "Indent" -> 1], {"\n\n" -> "\n",
RegularExpression["\n[\\s]*{"] -> "{"}]
fun
to generate the first expression from the second? $\endgroup$ – Leonid Shifrin Feb 2 '15 at 20:06