Ejemplo n.º 1
0
	def _compile_WHILE(self, whilestmt):
		self.add_line('while ' + scp.get_expr(whilestmt['condition']) + ':')
		self._inc_indent()
		for st in whilestmt['statements']:
			self.compile_statement(st)
		self._dec_indent()
		self.add_line()
Ejemplo n.º 2
0
	def _compile_SECTION(self, section):
		params=""
		for p in section['params']:
			params += p['name'][1]
			if 'default' in p:
				params += "=" + scp.get_expr(p['default'])
			params += ", "
		if len(params) > 0:
			params = '(' + params[:-2] + ')'
		self.add_line('label ' + section['section'][1] + params + ":")
		self._inc_indent()
Ejemplo n.º 3
0
	def _compile_IF(self, ifstmt):
		elsebr = None
		firstbr = True
		for br in ifstmt['branches']:
			if br['condition'] is None:
				elsestmt = br
			else:
				if firstbr:
					self.add_line('if ' + scp.get_expr(br['condition']) + ':')
					firstbr = False
				else:
					self.add_line('elif ' + scp.get_expr(br['condition']) + ':')
				self._inc_indent()
				for st in br['statements']:
					self.compile_statement(st)
				self._dec_indent()
		if elsebr is not None:
			self.add_line('else:')
			self._inc_indent()
			for st in elsebr['statements']:
				self.compile_statement(st)
			self._dec_indent()
Ejemplo n.º 4
0
	def make_varset(self, varset):
		line = ''
		if scp.typed_check(varset['value'], 'boolean'):
			return self.make_flagset(varset)
		var = scp.to_words(varset['name'][1]).lower()
		value = scp.get_expr(varset['value'])
		if scp.typed_check(varset['value'], 'incdec'):
			readable = scp.to_human_readable(var + value)
			var_in = readable.rfind(var)
			var_str = readable[var_in:].replace(var, scp.quote(var, "'"), 1)
			readable = readable[0:var_in] + var_str
			line = readable.strip().capitalize() + '.'
		else:
			line = 'Set the variable ' + scp.quote(var, "'") + ' to ' + value + '.'
		return (line, False)
Ejemplo n.º 5
0
	def _compile_EXECUTE(self, execute):
		params = ""
		use_pass = False
		for p in execute['params']:
			if 'name' in p:
				use_pass = True
				params += p['name'][1] + "="
			params += scp.get_expr(p['value'])
			params += ', '
		if len(params) > 0:
			params = '(' + params[:-2] + ')'
		if use_pass:
			self.add_line('call expression %s pass %s' % (scp.quote(execute['section'][1]), params))
		else:
			self.add_line('call %s%s' % (execute['section'][1], params))
		self.add_line()
Ejemplo n.º 6
0
	def _compile_IF(self, ifstmt):
		elsebr = None
		firstbr = True
		had_output = False
		for br in ifstmt['branches']:
			if br['condition'] is None:
				elsestmt = br
			else:
				if not self.contains_writeable(br['statements']):
					continue
				had_output = True
				negation = ''
				if firstbr:
					line = '%s do the following'
					firstbr = False
				else:
					line = 'Otherwise,%s do the following'
				cond = scp.get_expr(br['condition'])
				if scp.typed_check(br['condition'], 'boolean'):
					tcond = br['condition'][1]
					if tcond:
						negation = ' always'
						line += ':'
					else:
						negation = ' never'
						line += ':'
				elif scp.typed_check(br['condition'], 'id'):
					cond_words = scp.to_words(br['condition'][1]).lower()
					if cond_words.startswith('have '):
						cond_ph = cond_words[len('have '):]
						line += ' only if we have ' + cond_ph + ':'
					else:
						line += ' only if ' + scp.quote(cond_words, "'") + ' is set:'
				else:
					line += ' only if ' + scp.to_human_readable(cond) + ':'
				self.add_paragraph((line % negation).strip().capitalize(), style='Engine Instruction')
				self.compile_block(br['statements'])
		if elsebr is not None and had_output and self.contains_writeable(elsebr['statements']):
			self.add_paragraph("Otherwise, do the following:", style='Engine Instruction')
			self.compile_block(elsebr['statements'])
		if not had_output:
			self._add_break = False
Ejemplo n.º 7
0
	def _compile_WHILE(self, whilestmt):
		line = "Do the following "
		cond = scp.get_expr(whilestmt['condition'])
		if scp.typed_check(whilestmt['condition'], 'boolean'):
			tcond = whilestmt['condition'][1]
			if tcond:
				line += 'forever:'
			else:
				line = 'Never do the following:'
		elif scp.typed_check(whilestmt['condition'], 'id'):
			cond_words = scp.to_words(whilestmt['condition'][1]).lower()
			if cond_words.startswith('have '):
				cond_ph = cond_words[len('have '):]
				line += 'while we have ' + cond_ph + ':'
			else:
				line += 'while ' + scp.quote(cond_words, "'") + ' is set:'
		else:
			line += 'while ' + scp.to_human_readable(cond) + ':'
		if self.contains_writeable(whilestmt['statements']):
			self.add_paragraph(line, style='Engine Instruction')
			self.compile_block(whilestmt['statements'])
		else:
			self._add_break = False
Ejemplo n.º 8
0
	def make_flagset(self, flagset):
		line = ''
		value = scp.get_expr(flagset['value'])
		tvalue = flagset['value'][1]
		flag = scp.to_words(flagset['name'][1]).lower()
		nat_lang = flag.startswith('have ')
		if nat_lang:
			phrase = flag[len('have '):]
		if scp.typed_check(flagset['value'], 'boolean'):
			if not nat_lang:
				if tvalue:
					line = 'Set the flag ' + scp.quote(flag, "'") + '.'
				else:
					line = 'Unset the flag ' + scp.quote(flag, "'") + '.'
			else:
				if tvalue:
					line = 'We have now ' + phrase + '.'
				else:
					line = 'We have now not ' + phrase + '.'
		elif scp.typed_check(flagset['value'], 'id'):
			if nat_lang:
				line = 'Whether we have ' + phrase + ' is determined by '
			else:
				line = 'Set the flag ' + scp.quote(flag, "'") + ' to the same as '
			value_id = scp.to_words(value).lower()
			if value_id.startswith('have '):
				val_phrase = value_id[len('have '):]
				line += 'whether we have ' + val_phrase + '.'
			else:
				line += 'the value of the variable ' + scp.quote(value_id, "'") + '.'
		elif scp.typed_check(flagset['value'], 'expr'):
			if nat_lang:
				line = 'Whether we have now ' + flag + ' is determined by the value of the variable ' + value + '.'
			else:
				line = 'Set the flag ' + scp.quote(flag, "'") + ' to the same as the value of the variable ' + value + '.'
		return (line, nat_lang)
Ejemplo n.º 9
0
	def _compile_END(self, end):
		if 'retval' in end:
			self.add_line('return ' + scp.get_expr(end['retval']))
		self._dec_indent()
		self.add_line()
Ejemplo n.º 10
0
	def _compile_VARSET(self, varset, noline=False):
		self.add_line('$ ' + varset['name'][1] + ' ' + scp.get_expr(varset['value'], '= '))
		if not noline:
			self.add_line()
Ejemplo n.º 11
0
	def _compile_FLAGSET(self, flagset):
		self.add_line('$ ' + flagset['name'][1] + ' = ' + scp.get_expr(flagset['value']))
		self.add_line()