Skip to content

Instantly share code, notes, and snippets.

@ysm-dev
Created October 4, 2018 06:39
Show Gist options
  • Save ysm-dev/8e0b5184663c3becb168971cc77c4415 to your computer and use it in GitHub Desktop.
Save ysm-dev/8e0b5184663c3becb168971cc77c4415 to your computer and use it in GitHub Desktop.
in_str = input()
macros = []
macro = {}
macro_started = False
trim_str = in_str.strip()
while trim_str != 'end':
list_of_commands = list(filter(None, in_str.split(' ')))
if 'macro' in list_of_commands:
macro['lines'] = [in_str]
macro_started = True
args = list_of_commands[-1].split(',')
macro['name'] = list_of_commands[0]
macro['num_of_arg'] = len(args)
macro['args'] = {}
for i in range(0, len(args)):
macro['args'][args[i]] = '#' + str(i)
if macro_started and 'macro' not in list_of_commands:
for arg in macro['args']:
in_str = in_str.replace(arg, macro['args'][arg])
macro['lines'].append(in_str)
if 'endm' in list_of_commands:
macro_started = False
for line in macro['lines']:
print(line)
macros.append(macro)
macro = {}
in_str = input()
trim_str = in_str.strip()
if(trim_str=='end'):
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment