예제 #1
0
def p_increment_decrement_identifiers(p):
    """
    expression : identifier DOUBLE_PLUS
               | identifier DOUBLE_MINUS
    """
    if p[2] == "++":
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), "+")
    else:
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), "-")
예제 #2
0
def p_increment_decrement_identifiers(p):
    '''
    expression : identifier DOUBLE_PLUS
               | identifier DOUBLE_MINUS
    '''
    if p[2] == '++':
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), '+')
    else:
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), '-')
예제 #3
0
def p_boolean_operators(p):
    """
    boolean : expression EQ expression
            | expression NEQ expression
            | expression GT expression
            | expression GTE expression
            | expression LT expression
            | expression LTE expression
            | expression AND expression
            | expression OR expression
    """
    p[0] = ast.BinaryOperation(p[1], p[3], p[2])
예제 #4
0
def p_binary_op(p):
    """
    expression : expression PLUS expression %prec PLUS
               | expression MINUS expression %prec MINUS
               | expression MUL expression %prec MUL
               | expression DIV expression %prec DIV
               | expression EXP expression %prec EXP
               | expression MOD expression %prec MOD

               | expression BIT_AND expression
               | expression BIT_OR expression
               | expression BIT_XOR expression
               | expression LSHIFT expression
               | expression RSHIFT expression
    """
    p[0] = ast.BinaryOperation(p[1], p[3], p[2])