示例#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_indexable(p):
    """
    indexable : identifier
              | STRING
              | array
    """
    if isinstance(p[1], ast.BaseExpression):
        p[0] = p[1]
    else:  # we need to handle the strings
        p[0] = ast.Primitive(p[1])
示例#4
0
def p_primitive(p):
    """
    primitive : NUM_INT
              | NUM_FLOAT
              | STRING
              | boolean
    """
    if isinstance(p[1], ast.BaseExpression):
        p[0] = p[1]
    else:
        p[0] = ast.Primitive(p[1])
示例#5
0
def p_for_loop_infinite(p):
    """
    statement : FOR LBRACK statement_list RBRACK
    """
    p[0] = ast.While(ast.Primitive(True), p[3])
示例#6
0
def p_boolean(p):
    """
    boolean : TRUE
            | FALSE
    """
    p[0] = ast.Primitive(p[1])
示例#7
0
def p_paren(p):
    """
    expression : LPAREN expression RPAREN
    """
    p[0] = p[2] if isinstance(p[2], ast.BaseExpression) else ast.Primitive(
        p[2])
示例#8
0
def p_boolean(p):
    '''
    boolean : TRUE
            | FALSE
    '''
    p[0] = ast.Primitive(p[1])