+CInfixOperatorDeclaration = collections.namedtuple(
+ 'CInfixOperatorDeclaration',
+ [
+ 'name',
+ 'input_type',
+ 'result_type',
+ 'c_operator',
+ ],
+)
+
+INFIX_OPERATOR_TO_DECLARATION = {
+ '+': CInfixOperatorDeclaration(name='add', input_type='INTEGER', result_type='INTEGER', c_operator='+'),
+ '-': CInfixOperatorDeclaration(name='subtract', input_type='INTEGER', result_type='INTEGER', c_operator='-'),
+ '*': CInfixOperatorDeclaration(name='multiply', input_type='INTEGER', result_type='INTEGER', c_operator='*'),
+ '//': CInfixOperatorDeclaration(name='integerDivide', input_type='INTEGER', result_type='INTEGER', c_operator='/'),
+ '%': CInfixOperatorDeclaration(name='modularDivide', input_type='INTEGER', result_type='INTEGER', c_operator='%'),
+ 'and': CInfixOperatorDeclaration(name='and', input_type='BOOLEAN', result_type='BOOLEAN', c_operator='&&'),
+ 'or': CInfixOperatorDeclaration(name='or', input_type='BOOLEAN', result_type='BOOLEAN', c_operator='||'),
+}
+
+def transform_infix_expression(accumulators, expression):
+ if expression.order == 'comparison_level':
+ return transform_comparison_level_expression(accumulators, expression)
+
+ accumulators.operator_set.add(INFIX_OPERATOR_TO_DECLARATION[expression.operator])
+
+ return CFunctionCallForFurInfixOperator(
+ name=INFIX_OPERATOR_TO_DECLARATION[expression.operator].name,
+ left=transform_expression(accumulators, expression.left),
+ right=transform_expression(accumulators, expression.right),
+ )
+
+def transform_integer_literal_expression(accumulators, expression):
+ return CIntegerLiteral(value=expression.value)
+
+def transform_parenthesized_expression(accumulators, expression):
+ # Parentheses can be removed because everything in the C output is explicitly parenthesized
+ return transform_expression(accumulators, expression.internal)
+
+def transform_negation_expression(accumulators, expression):
+ return CNegationExpression(
+ value=transform_expression(accumulators, expression.internal_expression),
+ )
+
+def transform_expression(accumulators, expression):
+ # TODO Clean up handlers for parsing expressions
+ return {
+ parsing.FurFunctionCallExpression: transform_function_call_expression,
+ parsing.FurInfixExpression: transform_infix_expression,
+ parsing.FurIntegerLiteralExpression: transform_integer_literal_expression,
+ parsing.FurNegationExpression: transform_negation_expression,
+ parsing.FurParenthesizedExpression: transform_parenthesized_expression,
+ parsing.FurStringLiteralExpression: transform_string_literal,
+ parsing.FurSymbolExpression: transform_symbol_expression,
+ normalization.NormalFunctionCallExpression: transform_function_call_expression,
+ normalization.NormalInfixExpression: transform_infix_expression,
+ normalization.NormalNegationExpression: transform_negation_expression,
+ normalization.NormalVariableExpression: transform_variable_expression,
+ }[type(expression)](accumulators, expression)
+
+def transform_symbol_assignment_statement(accumulators, assignment_statement):