<commit_before>import random
import math
import re
import operator

def simplifyNumber(val):
    if type(val) == complex and val.imag == 0:
        val = val.real
    if type(val) == float and val.is_integer():
        val = int(val)
    return val

class DiceParser:
    # OP: [Precedence, Associativity]
    OPERATORS = {
        'd': {'pre':101, 'assoc':'NONE', 'func':lambda a,b:NotImplemented},
        '^': {'pre':4, 'assoc':'RIGHT', 'func':operator.pow},
        '*': {'pre':3, 'assoc':'LEFT', 'func':operator.mul},
        '/': {'pre':3, 'assoc':'LEFT', 'func':operator.truediv},
        '+': {'pre':2, 'assoc':'LEFT', 'func':operator.add},
        '-': {'pre':2, 'assoc':'LEFT', 'func':operator.sub},
        '>': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a>b},
        '<': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a<b},
        '==': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a==b},
        '!=': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a!=b},
        '>=': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a>=b},
        '<=': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a<=b}
    }

    UNARY_OPERATORS = {
        'dF': {'pre':100, 'assoc':'LEFT', 'func':lambda a:NotImplemented},
        '!': {'pre':5, 'assoc':'LEFT', 'func':math.factorial},
        '~': {'pre':6, 'assoc':'RIGHT', 'func':lambda a:not a},
    }

    # NAME: ARG_COUNT, FUNC
    FUNCTIONS = {
        'ceil': {'args':1, 'func':math.ceil},
        'floor': {'args':1, 'func':math.floor},
        'if': {'args':3, 'func':lambda a,b,c:b if a else c}
    }

    REGEXES = {
        'number': r'(?:[1-9][0-9]*\.?|0\.)[0-9]*(?:[eE][0-9]*)?j?'
    }
    
    def __init__(self):
        self.index = 0
        self.roll = ''

    def evaluateInfix(self, roll):
        postfixtokens = self.InfixToPostfix(roll)
        stack = []
        rolls = []
        index = 0
        try:
            for t in postfixtokens:
                if t['type'] == 'num':
                    val = complex(t['val'])
                    val = simplifyNumber(val)
                    stack.append(val)
                elif t['type'] == 'func':
                    func = DiceParser.FUNCTIONS[t['val']]
                    val = func['func'](*stack[-func['args']:])
                    for i in range(func['args']):
                        stack.pop(-1)
                    val = simplifyNumber(val)
                    stack.append(val)
                elif t['type'] == 'op':
                    arg2 = stack.pop(-1)
                    arg1 = stack.pop(-1)
                    val = 0
                    if t['val'] == 'd':
                        r = []
                        for i in range(arg1):
                            r.append(random.randint(1, arg2))
                        val = sum(r)
                        rolls.append('{0:d}d{1:d}: {2} = {3}'.format(
                            arg1, arg2, val, ', '.join(str(x) for x in r)))
                    else:
                        val = DiceParser.OPERATORS[t['val']]['func'](arg1, arg2)<commit_msg>Add error on binary operator without two operands<commit_after>import random
import math
import re
import operator

def simplifyNumber(val):
    if type(val) == complex and val.imag == 0:
        val = val.real
    if type(val) == float and val.is_integer():
        val = int(val)
    return val

class DiceParser:
    # OP: [Precedence, Associativity]
    OPERATORS = {
        'd': {'pre':101, 'assoc':'NONE', 'func':lambda a,b:NotImplemented},
        '^': {'pre':4, 'assoc':'RIGHT', 'func':operator.pow},
        '*': {'pre':3, 'assoc':'LEFT', 'func':operator.mul},
        '/': {'pre':3, 'assoc':'LEFT', 'func':operator.truediv},
        '+': {'pre':2, 'assoc':'LEFT', 'func':operator.add},
        '-': {'pre':2, 'assoc':'LEFT', 'func':operator.sub},
        '>': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a>b},
        '<': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a<b},
        '==': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a==b},
        '!=': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a!=b},
        '>=': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a>=b},
        '<=': {'pre':1, 'assoc':'NONE', 'func':lambda a,b:a<=b}
    }

    UNARY_OPERATORS = {
        'dF': {'pre':100, 'assoc':'LEFT', 'func':lambda a:NotImplemented},
        '!': {'pre':5, 'assoc':'LEFT', 'func':math.factorial},
        '~': {'pre':6, 'assoc':'RIGHT', 'func':lambda a:not a},
    }

    # NAME: ARG_COUNT, FUNC
    FUNCTIONS = {
        'ceil': {'args':1, 'func':math.ceil},
        'floor': {'args':1, 'func':math.floor},
        'if': {'args':3, 'func':lambda a,b,c:b if a else c}
    }

    REGEXES = {
        'number': r'(?:[1-9][0-9]*\.?|0\.)[0-9]*(?:[eE][0-9]*)?j?'
    }
    
    def __init__(self):
        self.index = 0
        self.roll = ''

    def evaluateInfix(self, roll):
        postfixtokens = self.InfixToPostfix(roll)
        stack = []
        rolls = []
        index = 0
        try:
            for t in postfixtokens:
                if t['type'] == 'num':
                    val = complex(t['val'])
                    val = simplifyNumber(val)
                    stack.append(val)
                elif t['type'] == 'func':
                    func = DiceParser.FUNCTIONS[t['val']]
                    val = func['func'](*stack[-func['args']:])
                    for i in range(func['args']):
                        stack.pop(-1)
                    val = simplifyNumber(val)
                    stack.append(val)
                elif t['type'] == 'op':
                    if len(stack) < 2:
                        raise ValueError('Not enough arguments for "{0}" at {1}'.format(t['val'], t['index']))
                    arg2 = stack.pop(-1)
                    arg1 = stack.pop(-1)
                    val = 0
                    if t['val'] == 'd':
                        r = []
                        for i in range(arg1):
                            r.append(random.randint(1, arg2))
                        val = sum(r)
                        rolls.append('{0:d}d{1:d}: {2} = {3}'.format(
                            arg1, arg2, val, ', '.join(str(x) for x in r)))
                    else:
                        val = DiceParser.OPERATORS[t['val']]['func'](arg1, arg2)
{'fraction_non_alphanumeric': 0.21300448430493274, 'fraction_numerical': 0.016816143497757848, 'mean_word_length': 1.7486795774647887, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3654590', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2069, 'n_words': 398}