--- /dev/null
+print("Don't stop me now\n")
+print('"Cogito ergo sum." --Descartes\n')
--- /dev/null
+Don't stop me now
+"Cogito ergo sum." --Descartes
)
return definition
+C_ESCAPES = {
+ '"': r'\"',
+}
+
+def escape_character(ch):
+ return C_ESCAPES.get(ch, ch)
+
+def escape_string_literal(string_literal):
+ return ''.join(escape_character(ch) for ch in string_literal)
+
def generate(program):
template = ENV.get_template('program.c')
return template.render(
infix_declarations=program.operator_declarations,
statements=list(generate_statement(s) for s in program.statements),
standard_libraries=list(sorted(program.standard_libraries)),
- string_literal_list=program.string_literal_list,
+ string_literal_list=list(escape_string_literal(s) for s in program.string_literal_list),
symbol_list=program.symbol_list,
)
result_statement_list.append(s)
result_statement_list.append(normalized)
+ # TODO The way we fix the last statement is really confusing
last_statement = result_statement_list[-1]
if isinstance(last_statement, NormalExpressionStatement) and isinstance(last_statement.expression, NormalVariableExpression):
- result_expression = result_statement_list.pop().expression
-
if assign_result_to is not None:
+ result_expression = result_statement_list.pop().expression
result_statement_list.append(
NormalVariableReassignmentStatement(
variable=assign_result_to,
return True, index, FurIntegerLiteralExpression(integer=value)
def _string_literal_expression_parser(index, tokens):
+ if tokens[index].type == 'double_quoted_string_literal':
+ return (True, index + 1, FurStringLiteralExpression(string=tokens[index].match[1:-1]))
+
if tokens[index].type == 'single_quoted_string_literal':
return (True, index + 1, FurStringLiteralExpression(string=tokens[index].match[1:-1]))
('integer_literal', r'\d+'),
('symbol', r'[a-z_]+'),
('single_quoted_string_literal', r"'.*?'"),
+ ('double_quoted_string_literal', r'".*?"'),
('comparison_level_operator', r'(<=|>=|==|!=|<|>)'),
('assignment_operator', r'='),
('addition_level_operator', r'(\+\+|\+|-)'),
transform_statement(accumulators, statement) for statement in program.statement_list
]
- # This prevents warnings about normalized variables being entire C statements
- last_statement = statement_list[-1]
- if isinstance(last_statement, normalization.NormalExpressionStatement) and isinstance(last_statement.expression, normalization.NormalVariableExpression):
- del statement_list[-1]
-
standard_library_set = set()
for builtin in accumulators.builtin_set:
for standard_library in BUILTINS[builtin]: