def interpret(options): '''Parse and run source file''' try: maxstack, source = parse(options.filename) run(maxstack, source, options.verbose) except Exception as e: die(options.filename, e)
def llvm(options): '''Parse and compile source file to LLVM''' checkLLVM() from src.genllvm import buildModule try: # Parse file into mapping of labels to instructions name = getName(options.filename) maxstack, source = parse(options.filename) # Generate and write LLVM IR module = buildModule(name, source, maxstack) irFilename = name + '.ll' with open(irFilename, 'w') as stream: stream.write(str(module)) # Generate assembly with llc asmFilename = name + '.s' shell([ 'llc', irFilename, '-o ' + asmFilename, '-O' + options.O, ]) # Assemble executable with clang # GCC doesn't like the assembly llc produces shell([ 'clang', asmFilename, '-o ' + name, ]) except Exception as e: die(options.filename, e)
def _parse_and_compile(self,in_file): import src.parse as parse import src.compileProgramToSDD as Convert import src.compile as compiler from src import simplify compiled_programs = [] if self.args.verbosity > 0: print(">>>Start parsing program") parsed_program = parse.parse(in_file) if self.args.verbosity > 0: print(">>>Done parsing program") if self.args.verbosity > 4: print("Parsed logic program:") print(parsed_program) if self.args.verbosity > 15: print("Warning: verbosity is greater than 15") print(" This means that all IDs in logic programs will be replaced by their string-value in " "symboltables. This might affect the behaviour of lp2sdd. If you wish to avoid this, make " "sure your verbosity is lower than 15.") parsed_program = simplify.simplify(parsed_program) print(">>>Done simplifying program") print("Simplified logic program:") print(parsed_program) if self.args.verbosity > 0: print(">>>Start compiling program") compilation_result = Convert.convert_program_to_sdd(self.args, parsed_program) compiled_programs.append(compilation_result) if self.args.verbosity > 0: print(">>>Bottom up part of compilation done. Compiling entire program as one SDD") sdd = compilation_result.get_entire_program_as_sdd() if self.args.verbosity > 0: print(">>>Size of the compiled SDD: ") print(compiler.smart_size(sdd)) if self.args.verbosity > 0: print(">>>Done compiling program.") if self.args.verbosity > 0: print(">>>Done compiling all programs.") return compiled_programs
def main() -> None: bot_name = None slack_client = SlackClient(environ["SLACK_BOT_TOKEN"]) kwargs = {"with_team_state": False, "auto_reconnect": True} try: if slack_client.rtm_connect(**kwargs): bot_creds = slack_client.api_call("auth.test") bot_name = "@{}".format(bot_creds["user"]) bot_id = bot_creds["user_id"] print("Good to see you again, {}.\n".format(bot_name)) while True: loop( slack_client, bot_name, parse(bot_id, slack_client.rtm_read()), ) sleep(0.15) else: print("Hmm, unable to connect.") except (KeyboardInterrupt, ApiError) as e: print(death(bot_name, str(e)))
def compile(options): '''Parse and compile source file to C''' try: # Parse file into mapping of labels to instructions name = getName(options.filename) maxstack, source = parse(options.filename) # Generate and write C source cfilename = name + '.c' with open(cfilename, 'w') as stream: stream.write(gen(maxstack, source)) # Compile using default or specified compiler shell([ options.compiler, cfilename, options.args if options.args else '-O2 -o{}'.format(name), '-DVERBOSE_EXECUTION' if options.verbose else '' ]) except Exception as e: die(options.filename, e)
def customers(): customers = parse(FILE_NAME) yield customers
def test_parsed_customer_invalid_json(): with pytest.raises(Exception): customers = parse('tests/test_customers_value_error.txt')
def test_parsed_customer_missing_key(): with pytest.raises(KeyError): customers = parse('tests/test_customers_key_error.txt')
def test_parsed_missing_file(): with pytest.raises(Exception): customers = parse('missing.txt')
def invitees(): customers = parse(FILE_NAME) invitees = invite(customers) yield invitees
def test_invitees_length_all(): customers = parse('tests/test_invitees_all.txt') invitees = invite(customers) assert len(invitees) == 2
def test_invitees_length_zero(): customers = parse('tests/test_invitees_zero.txt') invitees = invite(customers) assert len(invitees) == 0
import unittest from src.document import document from src.parse import parse procedure_full = "!comment\nbegin-procedure name(x,y,z)\nbody\nend-procedure" procedure_min = "begin-procedurename()end-procedure" test_name = 'test' p = parse() class Test_test1(unittest.TestCase): def parser_no_match(self, parser, string): iter = parser.parse(string) self.assertIsNotNone(iter) try: match = iter.next() except StopIteration: self.assertTrue(True) else: self.assertTrue(False) def parser_success(self, parser, string, resultArray): """ test first match. Every group should contain the corresponding value from the resultArray. The iterator must contain at least one match or the test fails """ iter = parser.parse(string) self.assertIsNotNone(iter) match = iter.next() groups = match.groups()
def test_parse(): assert list(parse(BOT_ID, EVENTS)) == [("foo bar", EVENT["channel"])]