Example #1
0
 def default(self, line):
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     result = yacc.parse(line)
     print "result is: ", result
     print lis.eval(result)
Example #2
0
def main():
    with open('testfile.c', 'r') as content_file:
        content = content_file.read()
        AST = yacc.parse(content)
        print AST
        if AST != None:
            lis.eval(AST)
Example #3
0
 def default(self, line):
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     result = yacc.parse(line)
     print "result is: ", result
     print lis.eval(result)
Example #4
0
def p_expression(p):
    '''expression : primary 
                  | function
                  | vardeclarations
                  | letdeclarations'''
    p[0] = p[1]
    print p[0]
    print lis.eval(p[0])
Example #5
0
 def default(self, line):       
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     result = yacc.parse(line)  # parsing the line and evaluating the line; this yacc refers to the yacc that's in ply folder
     # result is the ast
     print "result is: ", result
     import lis
     print lis.eval(result)
     '''
def callJSON(func):
	global r20functions
	if func.get('type')=='lisp':
		if lis:
			lis.eval(lis.parse(str(func['content'])))
		else:
			sendMsgToR20('Cannot execute lisp function, lisp functions rely on lispy2 by Peter Norvig, available here:  http://norvig.com/lispy2.html')
	else:
		r20functions=reload(r20functions)
		r20functions.getFunc(func['name'])(func)
Example #7
0
def callJSON(func):
    global r20functions
    if func.get('type') == 'lisp':
        if lis:
            lis.eval(lis.parse(str(func['content'])))
        else:
            sendMsgToR20(
                'Cannot execute lisp function, lisp functions rely on lispy2 by Peter Norvig, available here:  http://norvig.com/lispy2.html'
            )
    else:
        r20functions = reload(r20functions)
        r20functions.getFunc(func['name'])(func)
Example #8
0
    def default(self, line):
        """Called on an input line when the command prefix is not recognized.
           In that case we execute the line as Python code.
        """
        print "\nParsing input with YACC:"
        result = yacc.parse(line)
        # This result is the Abstract Syntax Tree.
        print "The result is: ", result

        # Imports lis.py methods in the same folder, then passes the result for evaluation.
        import lis
        print ("\nEvaluating result with Lis.py:")
        print lis.eval(result)
Example #9
0
 def default(self, line):       
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     # from class
     '''
     result = yacc.parse(line)
     s = lisp_str(result)
     if s != 'nil':
         print s
     '''
     result = yacc.parse(line)
     print "result is: ", result
     import lis
     print lis.eval(result)
Example #10
0
 def default(self, line):       
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code."""
     ast = yacc.parse(line)
     print ('AST:', ast)
     import lis
     print ('RESULT:', lis.eval(ast))
    def default(self, line):
        """Called on an input line when the command prefix is not recognized.
           In that case we execute the line as Python code.
        """
        result = yacc.parse(line)

        import lis
        r = lis.eval(result)
        if r is not None: print r
Example #12
0
 def default(self, line):       
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     result = yacc.parse(line)
     print "AST is".format(result)
     r = lis.eval(result)
     if r is not None:
         print r
Example #13
0
 def default(self, line):
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     AST = yacc.parse(line)
     s = lisp_str(AST)
     if s != 'nil':
         print("Parsed input: " + s)
         print("into AST: " + str(AST))
         print("Trying to evaluate result...")
         result = lis.eval(AST)
         print(result)
Example #14
0
 def default(self, line):       
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     AST = yacc.parse(line)
     s = lisp_str(AST)
     if s != 'nil':
         print ("Parsed input: " + s)
         print ("into AST: " + str(AST))
         print ("Trying to evaluate result...")
         result = lis.eval(AST)
         print (result)
Example #15
0
def test(task_name, func_string, subset='train'):
    with open(f'ARC/data/training/{task_name}.json') as f:
        j = json.load(f)

    prog = parse(func_string)

    correct = True
    for i, t in enumerate(j[subset]):
        input_grid = np.array(t['input'])
        prog_with_input = ['define', 'grid', input_grid, prog]
        pred = eval(prog_with_input)
        #print(pred)
        # vis(pred)
        target = np.array(t['output'])
        correct &= match(pred, target)

    return correct
Example #16
0
    def notes(self, world, *args):
        if not self.__dict__.get('note_store'):
            self.note_store = []
            self.save()
        if len(args) == 0:
            if self.note_store:
                for n, note in enumerate(self.note_store):
                    print("note #" + str(n) + "\n" + note.split('\n')[0])
            else:
                print("No notes.")

        elif len(args) > 0:
            if str(args[0]).lower() in ['new', 'create', 'write', 'add']:
                self.writenote()
                return
            if str(args[0]).lower() in ['delete', 'del', 'rm']:
                try:
                    del self.note_store[int(args[1])]
                    self.save()
                    print('Deleted.')
                except ValueError:
                    print("Bad note ID.")
                except IndexError:
                    print("Can't find that note ID")
                return
            if str(args[0]).lower() in ['run']:
                try:
                    for line in self.note_store[int(args[1])].split('\n'):
                        val = lis.eval(lis.parse(line))
                        if val:
                            print(lis.lispstr(val))
                    print()
                except IndexError:
                    print("Can't find that note ID")
                return
            if str(args[0]).lower() in ['drop']:
                try:
                    dropped_note = self.note_store[int(args[1])]
                    del self.note_store[int(args[1])]
                    self.save()
                    room_data = get_room(self.x, self.y)
                    if not room_data.get('data'):
                        room_data['data'] = []
                    room_data['data'].append(dropped_note)

                    put_room(self.x, self.y, room_data)
                except ValueError:
                    raise  # print("Bad note ID.")
                except IndexError:
                    raise  # print("Can't find that note ID")
                return
            elif type(args[0]) == int:
                try:
                    print(
                        "note #" +
                        str(args[0]) + " " +
                        self.note_store[int(args[0])]
                    )
                    return
                except ValueError:
                    print("Bad note ID.")
                    return
                except IndexError:
                    print("Can't find that note ID")
                    return
Example #17
0
def mainloop(statements):
    for statement in statements:
        if len(statement) != 0:
            tokens = parse(statement)
            print(eval(tokens))
Example #18
0
def p_letdeclarations(p):
    '''letdeclarations : LET IDENTIFIER EQUALS expression'''

    a = lis.eval(p[4])
    p[0] = ['let'] + [p[2]] + [a]