Esempio n. 1
0
 def callback(ch, method, properties, body):
     print " [x] Received judge request %r" % (body,) # for debug
     s = Sub()
     try:
         s.getSub(body)
         c = Compile()
         c.compile(s)
     except Exception, e:
         print 'compile err| ', Exception, ':', e # for debug
Esempio n. 2
0
 def callback(ch, method, properties, body):
     print " [x] Received judge request %r" % (body, )  # for debug
     s = Sub()
     try:
         s.getSub(body)
         c = Compile()
         c.compile(s)
     except Exception, e:
         print 'compile err| ', Exception, ':', e  # for debug
Esempio n. 3
0
 def act(self, token):
     word = token.word
     if word == ':':
         if self.compile:
             print('Already in compile mode!')
             return False
         self.compile = Compile()
     elif word == ';':
         if not self.compile:
             print('Not in compile mode!')
             return False
         self.compile.finish(self)
         self.compile = None
     elif self.compile:
         try:
             self.compile.take(token)
         except CompileException as e:
             print(e)
             self.compile = None
     elif word == 'variable':
         if self.lex:
             name = next(self.lex)
             if name.isstringliteral:
                 raise ForthException('Expected name, not string')
             name = name.word
             index = self.memory.create_var(name)
             self.on(name, lambda s: s.istack.push(index))
         else:
             raise ForthException("No name variable name given")
     elif word == 'constant':
         if self.lex:
             name = next(self.lex)
             if name.isstringliteral:
                 raise ForthException('Expected name, not string')
             name = name.word
             n1 = self.istack.pop()
             self.on(name, lambda s: s.istack.push(n1))
         else:
             raise ForthException("No name variable name given")
     elif isInt(word):
         self.istack.push(int(word))
     elif isFloat(word):
         self.fstack.push(float(word))
     elif token.isstringliteral:
         print(word, end='')
     elif word in self.dict:
         self.dict[word](self)
     else:
         raise ForthException('Unknown Token: ' + word)
     return True
Esempio n. 4
0
    def __init__(self, comp=False, conf=False):
        '''
        Initiate the diagnosis finder.

        Parameters:
        comp - Recompiles the data files if set to True
        conf - Supply a Conf object
        '''
        if(conf):
            self.conf=conf
        else:
            self.conf=Conf()
        self.compiler=Compile(conf)
        if(comp):
            self.compiler.compile()
        self.index=Index(conf)
Esempio n. 5
0
File: app.py Progetto: H1ccup/Narnia
	def generate(self):
		for dep in self.deps:
			api_object = ApiObject()
			self.generated_api[dep.__name__]= Compile.generate(dep)
			
		response = {}
		for k,v in self.generated_api.iteritems():
			response[k] = []
			for data in self.generated_api[k]:
				response[k].append(data.__dict__)

		with open('data.txt', 'wb') as outfile:
  			json.dump(response, outfile)
		return self.conf
Esempio n. 6
0
    def __init__(self, comp=False, conf=False):
        """
        Initiate the diagnosis finder.

        Parameters:
        comp - Recompiles the data files if set to True
        conf - Supply a Conf object
        """
        if conf:
            self.conf = conf
        else:
            self.conf = Conf()
        self.compiler = Compile(conf)
        if comp:
            self.compiler.compile()
        self.index = Index(conf)
def BuildAndDeploy(contractName):
    Compile(contractName)
    try:
        os.system("punica deploy --avm " +
                  os.path.join(GetBuildFolderPath(), contractName) +
                  ".avm --config " +
                  os.path.join(GetContractsFolderPath(), contractName) +
                  "-config.json")
    except:
        print(sys.exc_info()[0])

    with open(GetDestAbiFilePath(contractName), "r") as f:
        dict_abi = json.loads(f.read())
        contract_address_tmp = dict_abi['hash'].replace('0x', '')
        contract_address = [
            contract_address_tmp[i:i + 2]
            for i in range(0, len(contract_address_tmp), 2)
        ]

    return contract_address
Esempio n. 8
0
class DDStorm:
    """ Provides the class for finding differential diagnosis. """

    conf = False

    def __init__(self, comp=False, conf=False):
        """
        Initiate the diagnosis finder.

        Parameters:
        comp - Recompiles the data files if set to True
        conf - Supply a Conf object
        """
        if conf:
            self.conf = conf
        else:
            self.conf = Conf()
        self.compiler = Compile(conf)
        if comp:
            self.compiler.compile()
        self.index = Index(conf)

    def dd(self, symptoms):
        """
        Find the differential diagnosis list.

        Parameter:
        symptom - list of strings containing symptoms

        Return value:
        List of strings containing the differential diagnosis
        """

        # Return empty list if symptom list is empty
        if not symptoms:
            return

        # Find DD of first symptom and discard it
        diff1 = self._getDiff(symptoms.pop(0))

        # Loop through the rest of the list
        for s in symptoms:

            # Find DD of the current item in the list
            diff2 = self._getDiff(s)

            # List for temporary holding the DDs
            temp = []

            # Make both lists the same length by appending empty strings to the end
            if len(diff1) > len(diff2):
                diff2 += [""] * (len(diff1) - len(diff2))
            elif len(diff2) > len(diff1):
                diff1 += [""] * (len(diff2) - len(diff1))

            # Loop over both lists
            for (s1, s2) in zip(diff1, diff2):

                # Add s1 to temp if s1 or any of its upstream ancestor is common to both list
                if (s1 not in temp) and (len(s1) > 0):
                    if s1 in diff2:
                        temp.append(s1)
                    else:
                        us = self.index.upstream(s1)
                        for i in us:
                            if i in diff2:
                                temp.append(i)

                # Add s2 to temp if s2 or any of its upstream ancestor is common to both list
                if (s2 not in temp) and (len(s2) > 0):
                    if s2 in diff1:
                        temp.append(s2)
                    else:
                        us = self.index.upstream(s2)
                        for i in us:
                            if i in diff1:
                                temp.append(i)

            # Copy temp to first list
            diff1 = list(temp)

        return diff1

    def _getDiff(self, symptom):
        """ Return differential diagnosis for a single symptom """
        diff = []
        symptom = symptom.lower().replace("_", " ").replace("-", " ")
        if os.path.isfile(self.conf.get("module_path") + symptom + ".module"):
            with open(self.conf.get("module_path") + symptom + ".module", "r") as mf:
                for line in mf:
                    diff.append(line.strip())
        return diff

    def symptoms(self):
        """
        Return a full list of available symptoms

        Return value:
        List of string containing symptoms
        """
        symp = []
        for n in os.listdir(self.conf.get("module_path")):
            symp.append(os.path.splitext(os.path.basename(n))[0].capitalize())
        return symp
Esempio n. 9
0
def start_compile(path: str, *args, **kwargs) -> None:
    Compile(path)
Esempio n. 10
0
                        dest="compiler",
                        help="Specify the C compiler to use")
    parser.add_argument("-o", dest="output", help="Specify the output dir")

    args = parser.parse_args()
    session = Tokenizer(args.inputFiles, args.debug, args.verbose)

    if args.verbose:
        print("Scanning %s..." % args.inputFiles)
    session.scanFiles()
    if args.verbose:
        print("Found %s files to parse" % str(len(session.jobs)))

    session.tokenizeFiles()
    if args.debug:
        session.writeFiles()

    lex = Lexer(session.jobs)
    session.jobs = lex.processJobs()

    transpile = Transpiler(session.jobs, args.verbose)
    transpile.processJobs()
    files = transpile.writeFiles()

    compiler = "gcc"
    if args.compiler:
        compiler = args.compiler

    if len(files) > 0 and args.output:
        c = Compile(files, args.output, compiler)
        c.compile()
Esempio n. 11
0
#!/usr/bin/env python
import time
from compile import Compile
from sub import Sub
from judge import Judge
c = Compile()
s = Sub()
s.sid = 1
s.lang = 'g++'
c.compile(s)
print 'ce:'+s.ce
print 'status:'+str(s.status)
s.pid = 15
s.case_cnt = 1
s.time_lim = 1000
s.mem_lim = 10240
s.case_lim = [{'time':1000, 'mem':4000},]
j = Judge()
j.judge(s)
print 'status:'+str(s.status)
print s.case_res

Esempio n. 12
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 14 19:56:56 2020

@author: aishit
"""

from generate_latex import Gen_Latex
from compile import Compile

Gen_Latex()
Compile()
Esempio n. 13
0
class State:
    def __init__(self):
        self.istack = Stack()
        self.rstack = Stack()
        self.fstack = Stack()
        self.memory = Memory()
        self.lex = None
        self.dict = {}
        self.compile = None

    def on(self, word, action):
        self.dict[word] = action

    def act_all(self, tokens):
        for token in tokens:
            if callable(token):
                token(self)
            elif type(token) == type([]):
                self.act_all(token)
            else:
                self.act(token)

    def act(self, token):
        word = token.word
        if word == ':':
            if self.compile:
                print('Already in compile mode!')
                return False
            self.compile = Compile()
        elif word == ';':
            if not self.compile:
                print('Not in compile mode!')
                return False
            self.compile.finish(self)
            self.compile = None
        elif self.compile:
            try:
                self.compile.take(token)
            except CompileException as e:
                print(e)
                self.compile = None
        elif word == 'variable':
            if self.lex:
                name = next(self.lex)
                if name.isstringliteral:
                    raise ForthException('Expected name, not string')
                name = name.word
                index = self.memory.create_var(name)
                self.on(name, lambda s: s.istack.push(index))
            else:
                raise ForthException("No name variable name given")
        elif word == 'constant':
            if self.lex:
                name = next(self.lex)
                if name.isstringliteral:
                    raise ForthException('Expected name, not string')
                name = name.word
                n1 = self.istack.pop()
                self.on(name, lambda s: s.istack.push(n1))
            else:
                raise ForthException("No name variable name given")
        elif isInt(word):
            self.istack.push(int(word))
        elif isFloat(word):
            self.fstack.push(float(word))
        elif token.isstringliteral:
            print(word, end='')
        elif word in self.dict:
            self.dict[word](self)
        else:
            raise ForthException('Unknown Token: ' + word)
        return True

    def parse_text(self, text):
        self.lex = iter(Lexer(text))
        for token in self.lex:
            if not self.act(token):
                self.lex = None
                return False
        self.lex = None
        return True
Esempio n. 14
0
class DDStorm:
    ''' Provides the class for finding differential diagnosis. '''
    conf=False
    
    def __init__(self, comp=False, conf=False):
        '''
        Initiate the diagnosis finder.

        Parameters:
        comp - Recompiles the data files if set to True
        conf - Supply a Conf object
        '''
        if(conf):
            self.conf=conf
        else:
            self.conf=Conf()
        self.compiler=Compile(conf)
        if(comp):
            self.compiler.compile()
        self.index=Index(conf)

    def dd(self, symptoms):
        '''
        Find the differential diagnosis list.

        Parameter:
        symptom - list of strings containing symptoms

        Return value:
        List of strings containing the differential diagnosis
        '''

        # Return empty list if symptom list is empty
        if(not symptoms):
            return
        
        # Find DD of first symptom and discard it
        diff1=self._getDiff(symptoms.pop(0))

        # Loop through the rest of the list
        for s in symptoms:
            
            # Find DD of the current item in the list
            diff2=self._getDiff(s)

            # List for temporary holding the DDs
            temp=[]

            # Make both lists the same length by appending empty strings to the end
            if(len(diff1)>len(diff2)):
                diff2+=[""]*(len(diff1)-len(diff2))
            elif(len(diff2)>len(diff1)):
                diff1+=[""]*(len(diff2)-len(diff1))

            # Loop over both lists
            for (s1, s2) in zip(diff1, diff2):

                # Add s1 to temp if s1 or any of its upstream ancestor is common to both list
                if((s1 not in temp) and (len(s1)>0)):
                    if(s1 in diff2):
                        temp.append(s1)
                    else:
                        us=self.index.upstream(s1)
                        for i in us:
                            if(i in diff2):
                                temp.append(i)

                # Add s2 to temp if s2 or any of its upstream ancestor is common to both list
                if((s2 not in temp) and (len(s2)>0)):
                    if(s2 in diff1):
                        temp.append(s2)
                    else:
                        us=self.index.upstream(s2)
                        for i in us:
                            if(i in diff1):
                                temp.append(i)

            # Copy temp to first list
            diff1=list(temp)

        return diff1

    def _getDiff(self, symptom):
        ''' Return differential diagnosis for a single symptom '''
        diff=[]
        symptom=symptom.lower().replace("_"," ").replace("-", " ")
        if(os.path.isfile(self.conf.get("module_path")+symptom+".module")):
           with open(self.conf.get("module_path")+symptom+".module", "r") as mf:
               for line in mf:
                   diff.append(line.strip())
        return diff
        
    def symptoms(self):
        '''
        Return a full list of available symptoms

        Return value:
        List of string containing symptoms
        '''
        symp=[]
        for n in os.listdir(self.conf.get("module_path")):
            symp.append(os.path.splitext(os.path.basename(n))[0].capitalize())
        return symp
Esempio n. 15
0
File: test.py Progetto: YLAsce/oj
#!/usr/bin/env python
import time
from compile import Compile
from sub import Sub
from judge import Judge
c = Compile()
s = Sub()
s.sid = 1
s.lang = 'g++'
c.compile(s)
print 'ce:' + s.ce
print 'status:' + str(s.status)
s.pid = 15
s.case_cnt = 1
s.time_lim = 1000
s.mem_lim = 10240
s.case_lim = [
    {
        'time': 1000,
        'mem': 4000
    },
]
j = Judge()
j.judge(s)
print 'status:' + str(s.status)
print s.case_res