+def transform_variable_expression(accumulators, expression):
+ return CVariableExpression(variable=expression.variable)
+
+def transform_string_literal_expression(accumulators, expression):
+ value = expression.string
+
+ try:
+ index = accumulators.string_literal_list.index(value)
+ except ValueError:
+ index = len(accumulators.string_literal_list)
+ accumulators.string_literal_list.append(value)
+
+ return CStringLiteral(index=index, value=value)
+
+def transform_symbol_expression(accumulators, expression):
+ if expression.symbol in BUILTINS:
+ accumulators.builtin_set.add(expression.symbol)
+
+ try:
+ symbol_list_index = accumulators.symbol_list.index(expression.symbol)
+ except ValueError:
+ symbol_list_index = len(accumulators.symbol_list)
+ accumulators.symbol_list.append(expression.symbol)
+
+ return CSymbolExpression(
+ symbol=expression.symbol,
+ symbol_list_index=symbol_list_index,
+ )
+
+CInfixDeclaration = collections.namedtuple(
+ 'CInfixDeclaration',
+ [
+ 'name',
+ 'in_type',
+ 'out_type',
+ 'operator',
+ ],
+)
+
+INFIX_OPERATOR_TO_DECLARATION = {
+ '+': CInfixDeclaration(name='add', in_type='integer', out_type='integer', operator='+'),
+ '-': CInfixDeclaration(name='subtract', in_type='integer', out_type='integer', operator='-'),
+ '*': CInfixDeclaration(name='multiply', in_type='integer', out_type='integer', operator='*'),
+ '//': CInfixDeclaration(name='integerDivide', in_type='integer', out_type='integer', operator='/'),
+ '%': CInfixDeclaration(name='modularDivide', in_type='integer', out_type='integer', operator='%'),
+ 'and': CInfixDeclaration(name='and', in_type='boolean', out_type='boolean', operator='&&'),
+ 'or': CInfixDeclaration(name='or', in_type='boolean', out_type='boolean', operator='||'),
+ '==': CInfixDeclaration(name='equals', in_type='integer', out_type='boolean', operator='=='),
+ '!=': CInfixDeclaration(name='notEquals', in_type='integer', out_type='boolean', operator='!='),
+ '<=': CInfixDeclaration(name='lessThanOrEqual', in_type='integer', out_type='boolean', operator='<='),
+ '>=': CInfixDeclaration(name='greaterThanOrEqual', in_type='integer', out_type='boolean', operator='>='),
+ '<': CInfixDeclaration(name='lessThan', in_type='integer', out_type='boolean', operator='<'),
+ '>': CInfixDeclaration(name='greaterThan', in_type='integer', out_type='boolean', operator='>'),
+}
+
+def transform_comparison_level_expression(accumulators, expression):
+ accumulators.operator_set.add(INFIX_OPERATOR_TO_DECLARATION[expression.operator])
+